Completed
Branch output_parsers_refactor (d2cb12)
by Alessandro
02:20
created

BaseFunctionalTestCase   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 154
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 15
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 154
rs 10
1
<?php
2
3
namespace Paraunit\Tests;
4
5
use Paraunit\Configuration\Paraunit;
6
use Paraunit\Tests\Stub\StubbedParaProcess;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
9
/**
10
 * Class BaseFunctionalTestCase
11
 * @package Paraunit\Tests
12
 */
13
abstract class BaseFunctionalTestCase extends \PHPUnit_Framework_TestCase
14
{
15
    /** @var ContainerBuilder */
16
    protected $container = null;
17
18
    public function setUp()
19
    {
20
        parent::setUp();
21
22
        $this->container = Paraunit::buildContainer();
23
        $this->cleanUpTempDir(Paraunit::getTempBaseDir());
24
    }
25
26
    /**
27
     * @return StubbedParaProcess
28
     */
29
    public function getTestWithSingleError()
30
    {
31
        $process = new StubbedParaProcess();
32
        $process->setExitCode(-1);
33
        $process->setOutput($this->getOutputFileContent('SingleError.txt'));
34
35
        return $process;
36
    }
37
38
    /**
39
     * @return StubbedParaProcess
40
     */
41
    public function getTestWithSingleWarning()
42
    {
43
        $process = new StubbedParaProcess();
44
        $process->setExitCode(-1);
45
        $process->setOutput($this->getOutputFileContent('SingleWarning.txt'));
46
47
        return $process;
48
    }
49
50
    /**
51
     * @return StubbedParaProcess
52
     */
53
    public function getTestWith2Errors2Failures()
54
    {
55
        $process = new StubbedParaProcess();
56
        $process->setExitCode(-1);
57
        $process->setOutput($this->getOutputFileContent('2Errors2Failures.txt'));
58
59
        return $process;
60
    }
61
62
    /**
63
     * @return StubbedParaProcess
64
     */
65
    public function getTestWithParserRegression()
66
    {
67
        $process = new StubbedParaProcess();
68
        $process->setExitCode(-1);
69
        $process->setOutput($this->getOutputFileContent('2Errors2Failures_parser_regression.txt'));
70
71
        return $process;
72
    }
73
74
    /**
75
     * @return StubbedParaProcess
76
     */
77
    public function getTestWithAllGreen()
78
    {
79
        $process = new StubbedParaProcess();
80
        $process->setExitCode(0);
81
        $process->setOutput($this->getOutputFileContent('AllGreen.txt'));
82
83
        return $process;
84
    }
85
86
    /**
87
     * @return StubbedParaProcess
88
     */
89
    public function getTestWithAllGreen5()
90
    {
91
        $process = new StubbedParaProcess();
92
        $process->setExitCode(0);
93
        $process->setOutput($this->getOutputFileContent('AllGreen5.txt'));
94
95
        return $process;
96
    }
97
98
    /**
99
     * @return StubbedParaProcess
100
     */
101
    public function getTestWithFatalError()
102
    {
103
        $process = new StubbedParaProcess();
104
        $process->setExitCode(-1);
105
        $process->setOutput($this->getOutputFileContent('FatalError.txt'));
106
107
        return $process;
108
    }
109
110
    /**
111
     * @return StubbedParaProcess
112
     */
113
    public function getTestWithSegFault()
114
    {
115
        if ( ! extension_loaded('sigsegv')) {
116
            $this->markTestIncomplete('The segfault cannot be reproduced in this environment');
117
        }
118
119
        $process = new StubbedParaProcess();
120
        $process->setExitCode(-1);
121
        $process->setOutput($this->getOutputFileContent('SegFault.txt'));
122
123
        return $process;
124
    }
125
126
    /**
127
     * @return StubbedParaProcess
128
     */
129
    public function getTestWithVeryLongOutput()
130
    {
131
        $process = new StubbedParaProcess();
132
        $process->setExitCode(0);
133
        $process->setOutput($this->getOutputFileContent('VeryLongOutput.txt'));
134
135
        return $process;
136
    }
137
138
    /**
139
     * @param $filename
140
     *
141
     * @return string
142
     */
143
    protected function getOutputFileContent($filename)
144
    {
145
        return file_get_contents(__DIR__ . '/Stub/PHPUnitOutput/' . $filename);
146
    }
147
148
    /**
149
     * @param string $dir
150
     */
151
    private function cleanUpTempDir($dir)
152
    {
153
        $it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
154
        $files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
155
156
        foreach($files as $file) {
157
            if ($file->isDir()){
158
                rmdir($file->getRealPath());
159
            } else {
160
                unlink($file->getRealPath());
161
            }
162
        }
163
164
        rmdir($dir);
165
    }
166
}
167