CommandFactoryTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\TestSuite\TestCase;
  16. use InvalidArgumentException;
  17. use TestApp\Command\DemoCommand;
  18. use TestApp\Shell\SampleShell;
  19. class CommandFactoryTest extends TestCase
  20. {
  21. public function testCreateCommand()
  22. {
  23. $factory = new CommandFactory();
  24. $command = $factory->create(DemoCommand::class);
  25. $this->assertInstanceOf(DemoCommand::class, $command);
  26. }
  27. public function testCreateShell()
  28. {
  29. $factory = new CommandFactory();
  30. $shell = $factory->create(SampleShell::class);
  31. $this->assertInstanceOf(SampleShell::class, $shell);
  32. }
  33. public function testInvalid()
  34. {
  35. $factory = new CommandFactory();
  36. $this->expectException(InvalidArgumentException::class);
  37. $this->expectExceptionMessage('Class `Cake\Test\TestCase\Console\CommandFactoryTest` must be an instance of `Cake\Console\Shell` or `Cake\Console\Command`.');
  38. $factory->create(static::class);
  39. }
  40. }