ScaffoldTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 99
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testConstructor() 0 6 1
A testLoadConfiguration() 0 8 1
A testBootstrapWasCalled() 0 4 1
A testRun() 0 14 1
A testApplicationIsScaffolded() 0 10 1
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\Scaffold;
9
use Symfony\Component\Console\Application;
10
use Symfony\Component\Console\Input\InputOption;
11
12
/**
13
 * @coversDefaultClass \SilverLeague\Console\Framework\Scaffold
14
 * @package silverstripe-console
15
 * @author  Robbie Averill <[email protected]>
16
 */
17
class ScaffoldTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * The test subject
21
     * @var Scaffold
22
     */
23
    protected $scaffold;
24
25
    /**
26
     * Initiate the test subject
27
     */
28
    public function setUp()
29
    {
30
        $this->scaffold = new Scaffold;
31
    }
32
33
    /**
34
     * Test that a Symfony Console Application is created, as well as the SilverStripe and Configuration Loaders
35
     *
36
     * @covers \SilverLeague\Console\Framework\ConsoleBase
37
     * @covers ::setSilverStripeLoader
38
     * @covers ::getSilverStripeLoader
39
     * @covers ::setConfigurationLoader
40
     * @covers ::getConfigurationLoader
41
     */
42
    public function testConstructor()
43
    {
44
        $this->assertInstanceOf(Application::class, $this->scaffold->getApplication());
45
        $this->assertInstanceOf(SilverStripeLoader::class, $this->scaffold->getSilverStripeLoader());
46
        $this->assertInstanceOf(ConfigurationLoader::class, $this->scaffold->getConfigurationLoader());
47
    }
48
49
    /**
50
     * Test that YAML configuration is loaded from the ConfigurationLoader in array format (YAML ~2.7 is
51
     * locked into the SilverStripe framework)
52
     *
53
     * @covers ::setConfiguration
54
     * @covers ::getConfiguration
55
     * @covers ::getConfigurationLoader
56
     * @covers \SilverLeague\Console\Framework\Loader\ConfigurationLoader
57
     */
58
    public function testLoadConfiguration()
59
    {
60
        $config = $this->scaffold->getConfiguration();
61
62
        $this->assertInternalType('array', $config);
63
        $this->assertArrayHasKey('Commands', $config);
64
        $this->assertContains("SilverLeague\Console\Command\Dev\BuildCommand", $config['Commands']);
65
    }
66
67
    /**
68
     * Test that the bootstrap method was called, initiating Bootstrap which defines this constant
69
     *
70
     * @covers ::bootstrap
71
     * @covers \SilverLeague\Console\Framework\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
}
116