Test Failed
Pull Request — master (#132)
by Alessandro
03:15
created

SingleResultFormatterTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testFormatProvider() 0 11 2
A assertMappingIsCorrect() 0 20 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tests\Functional\Printer;
6
7
use Paraunit\Printer\SingleResultFormatter;
8
use Paraunit\TestResult\Interfaces\PrintableTestResultInterface;
9
use Paraunit\TestResult\TestResultFormat;
10
use Paraunit\TestResult\TestResultList;
11
use Paraunit\TestResult\TestResultWithSymbolFormat;
12
use Tests\BaseFunctionalTestCase;
13
14
/**
15
 * Class SingleResultFormatterTest
16
 * @package Tests\Functional\Printer
17
 */
18
class SingleResultFormatterTest extends BaseFunctionalTestCase
19
{
20
    public function testFormatProvider()
21
    {
22
        /** @var SingleResultFormatter $formatter */
23
        $formatter = $this->getService(SingleResultFormatter::class);
24
        /** @var TestResultList $testResultList */
25
        $testResultList = $this->getService(TestResultList::class);
26
27
        foreach ($testResultList->getTestResultContainers() as $resultContainer) {
28
            $this->assertMappingIsCorrect($formatter, $resultContainer->getTestResultFormat());
29
        }
30
    }
31
32
    private function assertMappingIsCorrect(SingleResultFormatter $formatter, TestResultFormat $testResultFormat)
33
    {
34
        if (! $testResultFormat instanceof TestResultWithSymbolFormat) {
35
            return;
36
        }
37
38
        $tag = $testResultFormat->getTag();
39
        $symbol = $testResultFormat->getTestResultSymbol();
40
41
        $testResult = $this->prophesize(PrintableTestResultInterface::class);
42
        $testResult->getTestResultFormat()
43
            ->willReturn($testResultFormat);
44
45
        $this->assertEquals(
46
            sprintf('<%s>%s</%s>', $tag, $symbol, $tag),
47
            $formatter->formatSingleResult($testResult->reveal()),
48
            'Mapping incorrect for test result symbol: ' . ($symbol ?: 'N/A')
49
            . '[' . $testResultFormat->getTitle() . ']'
50
        );
51
    }
52
}
53