CommandFactoryTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. * Licensed under The MIT License
  6. * For full copyright and license information, please see the LICENSE.txt
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  10. * @link http://cakephp.org CakePHP(tm) Project
  11. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  12. */
  13. namespace Cake\Test\TestCase\Console;
  14. use Cake\Console\CommandFactory;
  15. use Cake\Console\ConsoleIo;
  16. use Cake\TestSuite\TestCase;
  17. use InvalidArgumentException;
  18. use TestApp\Command\DemoCommand;
  19. use TestApp\Shell\SampleShell;
  20. class CommandFactoryTest extends TestCase
  21. {
  22. public function testCreateCommand()
  23. {
  24. $factory = new CommandFactory();
  25. $command = $factory->create(DemoCommand::class);
  26. $this->assertInstanceOf(DemoCommand::class, $command);
  27. }
  28. public function testCreateShell()
  29. {
  30. $factory = new CommandFactory();
  31. $shell = $factory->create(SampleShell::class);
  32. $this->assertInstanceOf(SampleShell::class, $shell);
  33. }
  34. public function testInvalid()
  35. {
  36. $factory = new CommandFactory();
  37. $this->expectException(InvalidArgumentException::class);
  38. $this->expectExceptionMessage('Class `Cake\Test\TestCase\Console\CommandFactoryTest` must be an instance of `Cake\Console\Shell` or `Cake\Console\Command`.');
  39. $factory->create(static::class);
  40. }
  41. }