|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace SilverLeague\Console\Tests\Framework; |
| 4 | + |
| 5 | +use SilverLeague\Console\Command\SilverStripeCommand; |
| 6 | +use SilverLeague\Console\Framework\Loader\ConfigurationLoader; |
| 7 | +use SilverLeague\Console\Framework\Loader\SilverStripeLoader; |
| 8 | +use SilverLeague\Console\Framework\Bootstrap; |
| 9 | +use SilverLeague\Console\Framework\Scaffold; |
| 10 | +use Symfony\Component\Console\Application; |
| 11 | +use Symfony\Component\Console\Input\InputOption; |
| 12 | + |
| 13 | +/** |
| 14 | + * @coversDefaultClass \SilverLeague\Console\Framework\Scaffold |
| 15 | + * @package silverstripe-console |
| 16 | + * @author Robbie Averill <robbie@averill.co.nz> |
| 17 | + */ |
| 18 | +class ScaffoldTest extends \PHPUnit_Framework_TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * The test subject |
| 22 | + * @var Scaffold |
| 23 | + */ |
| 24 | + protected $scaffold; |
| 25 | + |
| 26 | + /** |
| 27 | + * Initiate the test subject |
| 28 | + */ |
| 29 | + public function setUp() |
| 30 | + { |
| 31 | + $this->scaffold = new Scaffold; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Test that a Symfony Console Application is created, as well as the SilverStripe and Configuration Loaders |
| 36 | + * |
| 37 | + * @covers \SilverLeague\Console\Framework\ConsoleBase |
| 38 | + * @covers ::setSilverStripeLoader |
| 39 | + * @covers ::getSilverStripeLoader |
| 40 | + * @covers ::setConfigurationLoader |
| 41 | + * @covers ::getConfigurationLoader |
| 42 | + */ |
| 43 | + public function testConstructor() |
| 44 | + { |
| 45 | + $this->assertInstanceOf(Application::class, $this->scaffold->getApplication()); |
| 46 | + $this->assertInstanceOf(SilverStripeLoader::class, $this->scaffold->getSilverStripeLoader()); |
| 47 | + $this->assertInstanceOf(ConfigurationLoader::class, $this->scaffold->getConfigurationLoader()); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Test that YAML configuration is loaded from the ConfigurationLoader in array format (YAML ~2.7 is |
| 52 | + * locked into the SilverStripe framework) |
| 53 | + * |
| 54 | + * @covers ::setConfiguration |
| 55 | + * @covers ::getConfiguration |
| 56 | + * @covers ::getConfigurationLoader |
| 57 | + * @covers \SilverLeague\Console\Framework\Loader\ConfigurationLoader |
| 58 | + */ |
| 59 | + public function testLoadConfiguration() |
| 60 | + { |
| 61 | + $config = $this->scaffold->getConfiguration(); |
| 62 | + |
| 63 | + $this->assertInternalType('array', $config); |
| 64 | + $this->assertArrayHasKey('Commands', $config); |
| 65 | + $this->assertContains("SilverLeague\Console\Command\Dev\BuildCommand", $config['Commands']); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Test that the bootstrap method was called, initiating Bootstrap which defines this constant |
| 70 | + * |
| 71 | + * @covers ::bootstrap |
| 72 | + */ |
| 73 | + public function testBootstrapWasCalled() |
| 74 | + { |
| 75 | + $this->assertTrue(defined('SILVERSTRIPE_ROOT_DIR')); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Test that the run method will run the Symfony Application |
| 80 | + * |
| 81 | + * @covers ::run |
| 82 | + */ |
| 83 | + public function testRun() |
| 84 | + { |
| 85 | + $mockApplication = $this->getMockBuilder(Application::class) |
| 86 | + ->disableOriginalConstructor() |
| 87 | + ->setMethods(['run']) |
| 88 | + ->getMock(); |
| 89 | + |
| 90 | + $mockApplication |
| 91 | + ->expects($this->once()) |
| 92 | + ->method('run'); |
| 93 | + |
| 94 | + $this->scaffold->setApplication($mockApplication); |
| 95 | + $this->scaffold->run(); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Test that scaffoldApplication sets the name and version of the SilverStripe Console application, adds |
| 100 | + * Commands and the "flush" InputOption |
| 101 | + * |
| 102 | + * @covers ::scaffoldApplication |
| 103 | + * @covers ::addCommands |
| 104 | + */ |
| 105 | + public function testApplicationIsScaffolded() |
| 106 | + { |
| 107 | + $this->assertSame(Scaffold::APPLICATION_NAME, $this->scaffold->getApplication()->getName()); |
| 108 | + $this->assertContains(Scaffold::APPLICATION_VERSION, $this->scaffold->getApplication()->getVersion()); |
| 109 | + $this->assertInstanceOf( |
| 110 | + InputOption::class, |
| 111 | + $this->scaffold->getApplication()->getDefinition()->getOption('flush') |
| 112 | + ); |
| 113 | + $this->assertInstanceOf(SilverStripeCommand::class, $this->scaffold->getApplication()->find('dev:build')); |
| 114 | + } |
| 115 | +} |
0 commit comments