|
|
@@ -1,4 +1,17 @@
|
|
|
<?php
|
|
|
+/**
|
|
|
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
|
+ * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
+ *
|
|
|
+ * Licensed under The MIT License
|
|
|
+ * For full copyright and license information, please see the LICENSE.txt
|
|
|
+ * Redistributions of files must retain the above copyright notice.
|
|
|
+ *
|
|
|
+ * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
+ * @link http://cakephp.org CakePHP(tm) Project
|
|
|
+ * @since 3.5.0
|
|
|
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
|
|
|
+ */
|
|
|
namespace Cake\Test\Console;
|
|
|
|
|
|
use Cake\Console\CommandCollection;
|
|
|
@@ -12,19 +25,35 @@ use stdClass;
|
|
|
*/
|
|
|
class CommandCollectionTest extends TestCase
|
|
|
{
|
|
|
+ /**
|
|
|
+ * Test constructor with valid classnames
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
public function testConstructor()
|
|
|
{
|
|
|
- $this->markTestIncomplete();
|
|
|
+ $collection = new CommandCollection([
|
|
|
+ 'i18n' => I18nShell::class,
|
|
|
+ 'routes' => RoutesShell::class
|
|
|
+ ]);
|
|
|
+ $this->assertTrue($collection->has('routes'));
|
|
|
+ $this->assertTrue($collection->has('i18n'));
|
|
|
+ $this->assertCount(2, $collection);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Constructor with invalid class names should blow up
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ * @expectedException InvalidArgumentException
|
|
|
+ * @expectedExceptionMessage 'nope' is not a subclass of Cake\Console\Shell
|
|
|
+ */
|
|
|
public function testConstructorInvalidClass()
|
|
|
{
|
|
|
- $this->markTestIncomplete();
|
|
|
- }
|
|
|
-
|
|
|
- public function testConstructorInvalidFactory()
|
|
|
- {
|
|
|
- $this->markTestIncomplete();
|
|
|
+ new CommandCollection([
|
|
|
+ 'i18n' => I18nShell::class,
|
|
|
+ 'nope' => stdClass::class
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -97,18 +126,47 @@ class CommandCollectionTest extends TestCase
|
|
|
$collection->add('routes', stdClass::class);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Test removing a command
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
public function testRemove()
|
|
|
{
|
|
|
- $this->markTestIncomplete();
|
|
|
+ $collection = new CommandCollection();
|
|
|
+ $collection->add('routes', RoutesShell::class);
|
|
|
+ $this->assertSame($collection, $collection->remove('routes'));
|
|
|
+ $this->assertFalse($collection->has('routes'));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Removing an unknown command does not fail
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
public function testRemoveUnknown()
|
|
|
{
|
|
|
- $this->markTestIncomplete();
|
|
|
+ $collection = new CommandCollection();
|
|
|
+ $this->assertSame($collection, $collection->remove('nope'));
|
|
|
+ $this->assertFalse($collection->has('nope'));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * test getIterator
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
public function testGetIterator()
|
|
|
{
|
|
|
- $this->markTestIncomplete();
|
|
|
+ $in = [
|
|
|
+ 'i18n' => I18nShell::class,
|
|
|
+ 'routes' => RoutesShell::class
|
|
|
+ ];
|
|
|
+ $collection = new CommandCollection($in);
|
|
|
+ $out = [];
|
|
|
+ foreach ($collection as $key => $value) {
|
|
|
+ $out[$key] = $value;
|
|
|
+ }
|
|
|
+ $this->assertEquals($in, $out);
|
|
|
}
|
|
|
}
|