CommandFactoryTest.php 1.7 KB

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