|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Rougin\Combustor; |
| 4 | + |
| 5 | +use Symfony\Component\Console\Application; |
| 6 | +use Symfony\Component\Console\Tester\CommandTester; |
| 7 | + |
| 8 | +use Rougin\Combustor\Fixture\CommandBuilder; |
| 9 | +use Rougin\Combustor\Fixture\CodeIgniterHelper; |
| 10 | + |
| 11 | +use PHPUnit_Framework_TestCase; |
| 12 | + |
| 13 | +class CreateScaffoldCommandTest extends PHPUnit_Framework_TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @var string |
| 17 | + */ |
| 18 | + protected $appPath; |
| 19 | + |
| 20 | + /** |
| 21 | + * @var array |
| 22 | + */ |
| 23 | + protected $commands = [ |
| 24 | + 'Rougin\Combustor\Commands\CreateControllerCommand', |
| 25 | + 'Rougin\Combustor\Commands\CreateLayoutCommand', |
| 26 | + 'Rougin\Combustor\Commands\CreateModelCommand', |
| 27 | + 'Rougin\Combustor\Commands\CreateScaffoldCommand', |
| 28 | + 'Rougin\Combustor\Commands\CreateViewCommand', |
| 29 | + 'Rougin\Combustor\Commands\InstallDoctrineCommand', |
| 30 | + 'Rougin\Combustor\Commands\InstallWildfireCommand', |
| 31 | + 'Rougin\Combustor\Commands\RemoveDoctrineCommand', |
| 32 | + 'Rougin\Combustor\Commands\RemoveWildfireCommand', |
| 33 | + ]; |
| 34 | + |
| 35 | + /** |
| 36 | + * Sets up the command and the application path. |
| 37 | + * |
| 38 | + * @return void |
| 39 | + */ |
| 40 | + public function setUp() |
| 41 | + { |
| 42 | + $this->appPath = __DIR__ . '/../TestApp/application'; |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Tests if the initial commands exists. |
| 47 | + * |
| 48 | + * @return void |
| 49 | + */ |
| 50 | + public function testCommandsExist() |
| 51 | + { |
| 52 | + CodeIgniterHelper::setDefaults($this->appPath); |
| 53 | + |
| 54 | + copy( |
| 55 | + __DIR__ . '/../../src/Templates/Libraries/Wildfire.template', |
| 56 | + $this->appPath . '/libraries/Wildfire.php' |
| 57 | + ); |
| 58 | + |
| 59 | + mkdir($this->appPath . '/views/layout'); |
| 60 | + |
| 61 | + copy( |
| 62 | + __DIR__ . '/../../src/Templates/Views/Layout/header.template', |
| 63 | + $this->appPath . '/views/layout/header.php' |
| 64 | + ); |
| 65 | + |
| 66 | + copy( |
| 67 | + __DIR__ . '/../../src/Templates/Views/Layout/footer.template', |
| 68 | + $this->appPath . '/views/layout/footer.php' |
| 69 | + ); |
| 70 | + |
| 71 | + $application = $this->getApplication(); |
| 72 | + |
| 73 | + $command = $application->find('create:scaffold'); |
| 74 | + $commandTester = new CommandTester($command); |
| 75 | + $commandTester->execute([ |
| 76 | + 'name' => 'users', |
| 77 | + '--bootstrap' => true |
| 78 | + ]); |
| 79 | + |
| 80 | + $this->assertFileExists($this->appPath . '/controllers/Users.php'); |
| 81 | + $this->assertFileExists($this->appPath . '/models/Users.php'); |
| 82 | + |
| 83 | + $create = $file = $this->appPath . '/views/users/create.php'; |
| 84 | + $edit = $file = $this->appPath . '/views/users/edit.php'; |
| 85 | + $index = $file = $this->appPath . '/views/users/index.php'; |
| 86 | + $show = $file = $this->appPath . '/views/users/show.php'; |
| 87 | + |
| 88 | + $this->assertFileExists($create); |
| 89 | + $this->assertFileExists($edit); |
| 90 | + $this->assertFileExists($index); |
| 91 | + $this->assertFileExists($show); |
| 92 | + |
| 93 | + CodeIgniterHelper::setDefaults($this->appPath); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Gets the application with the loaded classes. |
| 98 | + * |
| 99 | + * @return \Symfony\Component\Console\Application |
| 100 | + */ |
| 101 | + protected function getApplication() |
| 102 | + { |
| 103 | + $application = new Application; |
| 104 | + |
| 105 | + foreach ($this->commands as $commandName) { |
| 106 | + $command = CommandBuilder::create($commandName); |
| 107 | + |
| 108 | + $application->add($command); |
| 109 | + } |
| 110 | + |
| 111 | + return $application; |
| 112 | + } |
| 113 | +} |
0 commit comments