CommandCollectionTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace Cake\Test\Console;
  3. use Cake\Console\CommandCollection;
  4. use Cake\Shell\I18nShell;
  5. use Cake\Shell\RoutesShell;
  6. use Cake\TestSuite\TestCase;
  7. use stdClass;
  8. /**
  9. * Test case for the CommandCollection
  10. */
  11. class CommandCollectionTest extends TestCase
  12. {
  13. public function testConstructor()
  14. {
  15. $this->markTestIncomplete();
  16. }
  17. public function testConstructorInvalidClass()
  18. {
  19. $this->markTestIncomplete();
  20. }
  21. public function testConstructorInvalidFactory()
  22. {
  23. $this->markTestIncomplete();
  24. }
  25. /**
  26. * Test basic add/get
  27. *
  28. * @return void
  29. */
  30. public function testAdd()
  31. {
  32. $collection = new CommandCollection();
  33. $this->assertSame($collection, $collection->add('routes', RoutesShell::class));
  34. $this->assertTrue($collection->has('routes'));
  35. $this->assertSame(RoutesShell::class, $collection->get('routes'));
  36. }
  37. /**
  38. * Test that add() replaces.
  39. *
  40. * @return void
  41. */
  42. public function testAddReplace()
  43. {
  44. $collection = new CommandCollection();
  45. $this->assertSame($collection, $collection->add('routes', RoutesShell::class));
  46. $this->assertSame($collection, $collection->add('routes', I18nShell::class));
  47. $this->assertTrue($collection->has('routes'));
  48. $this->assertSame(I18nShell::class, $collection->get('routes'));
  49. }
  50. /**
  51. * Test adding with instances
  52. *
  53. * @return void
  54. */
  55. public function testAddInstance()
  56. {
  57. $collection = new CommandCollection();
  58. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')
  59. ->disableOriginalConstructor()
  60. ->getMock();
  61. $shell = new RoutesShell($io);
  62. $collection->add('routes', $shell);
  63. $this->assertTrue($collection->has('routes'));
  64. $this->assertSame($shell, $collection->get('routes'));
  65. }
  66. /**
  67. * Instances that are not shells should fail.
  68. *
  69. * @expectedException InvalidArgumentException
  70. * @expectedExceptionMessage 'routes' is not a subclass of Cake\Console\Shell
  71. */
  72. public function testAddInvalidInstance()
  73. {
  74. $collection = new CommandCollection();
  75. $shell = new stdClass();
  76. $collection->add('routes', $shell);
  77. }
  78. /**
  79. * Class names that are not shells should fail
  80. *
  81. * @expectedException InvalidArgumentException
  82. * @expectedExceptionMessage 'routes' is not a subclass of Cake\Console\Shell
  83. */
  84. public function testInvalidShellClassName()
  85. {
  86. $collection = new CommandCollection();
  87. $collection->add('routes', stdClass::class);
  88. }
  89. public function testRemove()
  90. {
  91. $this->markTestIncomplete();
  92. }
  93. public function testRemoveUnknown()
  94. {
  95. $this->markTestIncomplete();
  96. }
  97. public function testGetIterator()
  98. {
  99. $this->markTestIncomplete();
  100. }
  101. }