Completed
Push — master ( 01b890...8110dc )
by Robbie
01:11
created

testExceptionThrownIfFileDoesNotExist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
namespace SilverLeague\Console\Tests\Framework\Loader;
4
5
use SilverLeague\Console\Framework\Loader\ConfigurationLoader;
6
use SilverLeague\Console\Framework\Scaffold;
7
8
/**
9
 * @coversDefaultClass \SilverLeague\Console\Framework\Loader\ConfigurationLoader
10
 * @package silverstripe-console
11
 * @author  Robbie Averill <[email protected]>
12
 */
13
class ConfigurationLoaderTest extends \PHPUnit_Framework_TestCase
14
{
15
    /**
16
     * The test subject
17
     *
18
     * @var ConfigurationLoader
19
     */
20
    protected $configuration;
21
22
    /**
23
     * {@inheritDoc}
24
     */
25
    public function setUp()
26
    {
27
        $this->configuration = (new Scaffold)->getConfigurationLoader();
28
    }
29
30
    /**
31
     * Test that the full file path is returned
32
     *
33
     * @covers ::getFilePath
34
     */
35
    public function testEnsureConfigurationFileExists()
36
    {
37
        $this->assertTrue(file_exists($this->configuration->getFilePath()));
38
    }
39
40
    /**
41
     * Test that the YAML configuration file is parsed into an array
42
     *
43
     * @covers ::load
44
     */
45
    public function testParseYamlConfiguration()
46
    {
47
        $configuration = $this->configuration->load();
48
49
        $this->assertInternalType('array', $configuration);
50
        $this->assertArrayHasKey('Commands', $configuration);
51
        $this->assertContains("SilverLeague\Console\Command\Dev\BuildCommand", $configuration['Commands']);
52
    }
53
54
    /**
55
     * Test that an exception is thrown if the configuration file does not exist
56
     *
57
     * @covers ::getFilePath
58
     * @expectedException RuntimeException
59
     * @expectedExceptionMessage The configuration YAML file does not exist!
60
     */
61
    public function testExceptionThrownIfFileDoesNotExist()
62
    {
63
        $mockLoader = $this
64
            ->getMockBuilder(ConfigurationLoader::class)
65
            ->disableOriginalConstructor()
66
            ->setMethods(['getFilePath'])
67
            ->getMock();
68
69
        $mockLoader
70
            ->expects($this->once())
71
            ->method('getFilePath')
72
            ->willReturn('/path/to/file/that/should/never/exist');
73
74
        $mockLoader->load();
75
    }
76
}
77