Completed
Pull Request — master (#34)
by Alessandro
03:03 queued 40s
created

PHPUnitConfigFileTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 64
rs 10
1
<?php
2
3
namespace Paraunit\Tests\Unit\Configuration;
4
5
use Paraunit\Configuration\PHPUnitConfigFile;
6
7
class PHPUnitConfigFileTest extends \PHPUnit_Framework_TestCase
8
{
9
    private $previousCWD;
10
11
    protected function setUp()
12
    {
13
        parent::setUp();
14
15
        $this->previousCWD = getcwd();
16
17
        $stubPath = realpath(__DIR__ . '/../../Stub');
18
        chdir($stubPath);
19
    }
20
21
    protected function tearDown()
22
    {
23
        chdir($this->previousCWD);
24
        $this->previousCWD = null;
25
26
        parent::tearDown();
27
    }
28
29
    public function testRelativeDirectoryDoesUseDefaultFileName()
30
    {
31
        $dir = 'StubbedXMLConfigs';
32
33
        $config = new PHPUnitConfigFile($dir);
34
35
        $filePath = $config->getFileFullPath();
36
        $this->assertStringEndsWith(PHPUnitConfigFile::DEFAULT_FILE_NAME, $filePath);
37
38
        $directoryPath = $config->getDirectory();
39
        $this->assertStringEndsWith($dir, $directoryPath);
40
    }
41
42
    public function testRelativeFilenameDoesNotUseDefaultFileName()
43
    {
44
        $file = 'StubbedXMLConfigs/stubbed_for_filter_test.xml';
45
46
        $config = new PHPUnitConfigFile($file);
47
48
        $filePath = $config->getFileFullPath();
49
50
        $this->assertStringEndsNotWith(PHPUnitConfigFile::DEFAULT_FILE_NAME, $filePath);
51
    }
52
53
    public function testRelativeDirectoryAndDefaultFileDoesNotExistThrowException()
54
    {
55
        $dir = 'PHPUnitOutput';
56
57
        $this->setExpectedException('InvalidArgumentException', PHPUnitConfigFile::DEFAULT_FILE_NAME . ' does not exist');
58
59
        new PHPUnitConfigFile($dir);
60
    }
61
62
    public function testInvalidDirectoryProvidedThrowException()
63
    {
64
        $dir = 'foobar';
65
66
        $this->setExpectedException('InvalidArgumentException', 'Config path/file provided is not valid');
67
68
        new PHPUnitConfigFile($dir);
69
    }
70
}
71