Completed
Push — output_parsers_refactor ( 9ffc6c...755930 )
by Alessandro
09:57
created

TestResultsParser::parseAndContinue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Paraunit\Parser;
4
5
use Paraunit\Process\ProcessResultInterface;
6
7
class TestResultsParser implements JSONParserChainElementInterface
8
{
9
    const PHPUNIT_TEST_RESULTS_REGEX = '/(?<=by Sebastian Bergmann and contributors.\n\n)(.*?)+(?=\n\nTime:)/s';
10
    const PHPUNIT_CONFIG_LOAD = 'Configuration read from ';
11
12
    /**
13
     * @param ProcessResultInterface $process
14
     *
15
     * @return bool True if chain should continue
16
     */
17 13
    public function parsingFoundResult(ProcessResultInterface $process)
18
    {
19 13
        $results = $this->getResultsFromOutput($process->getOutput());
20
21 13
        if ($results != '') {
22 11
            $cleanResults = preg_replace('/[^WFIESR.]+/', '', $results);
23 11
            $process->setTestResults(str_split($cleanResults));
0 ignored issues
show
Deprecated Code introduced by
The method Paraunit\Process\Process...rface::setTestResults() has been deprecated with message: We should use just addTestResult

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
24 11
        }
25
26 13
        return true;
27
    }
28
29
    /**
30
     * @param string $output
31
     *
32
     * @return string
33
     */
34 13
    private function getResultsFromOutput($output)
35
    {
36 13
        $matches = array();
37 13
        preg_match(self::PHPUNIT_TEST_RESULTS_REGEX, $output, $matches);
38
39 13
        $results = '';
40
41 13
        if (!empty($matches)) {
42
            // fix per PHPUNIT < 4.7, strip della riga della config
43 11
            if (substr($matches[0], 0, 24) == $this::PHPUNIT_CONFIG_LOAD) {
44 4
                $results = preg_replace('/^'.preg_quote($this::PHPUNIT_CONFIG_LOAD).'.*\n\n/', '', $matches[0]);
45 4
            } else {
46 7
                $results = $matches[0];
47
            }
48 11
        }
49
50 13
        return $results;
51
    }
52
}
53