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

DebugPrinterTest::testOnProcessParsingCompleted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tests\Unit\Printer;
6
7
use Paraunit\Lifecycle\ProcessEvent;
8
use Paraunit\Printer\DebugPrinter;
9
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10
use Tests\BaseUnitTestCase;
11
use Tests\Stub\StubbedParaunitProcess;
12
use Tests\Stub\UnformattedOutputStub;
13
14
class DebugPrinterTest extends BaseUnitTestCase
15
{
16
    public function testIsSubscribedToAllProcessEvents()
17
    {
18
        $this->assertTrue(
19
            is_subclass_of(DebugPrinter::class, EventSubscriberInterface::class),
20
            DebugPrinter::class . ' is not an EventSubscriber!'
21
        );
22
23
        $reflectionClass = new \ReflectionClass(ProcessEvent::class);
24
        $subscribedEvents = array_keys(DebugPrinter::getSubscribedEvents());
25
26
        foreach ($reflectionClass->getConstants() as $eventName) {
27
            $this->assertContains($eventName, $subscribedEvents, 'Not subscribed to event ' . $eventName);
28
        }
29
    }
30
31 View Code Duplication
    public function testOnProcessStarted()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33
        $output = new UnformattedOutputStub();
34
        $printer = new DebugPrinter($output);
35
        $process = new StubbedParaunitProcess();
36
37
        $printer->onProcessStarted(new ProcessEvent($process));
38
39
        $this->assertContains('PROCESS STARTED', $output->getOutput());
40
        $this->assertContains($process->getFilename(), $output->getOutput());
41
        $this->assertContains($process->getCommandLine(), $output->getOutput());
42
    }
43
44 View Code Duplication
    public function testOnProcessTerminated()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        $output = new UnformattedOutputStub();
47
        $printer = new DebugPrinter($output);
48
        $process = new StubbedParaunitProcess();
49
        $process->setTestClassName('Some\Class\Name');
50
51
        $printer->onProcessTerminated(new ProcessEvent($process));
52
53
        $this->assertContains('PROCESS TERMINATED', $output->getOutput());
54
        $this->assertContains($process->getFilename(), $output->getOutput());
55
        $this->assertContains($process->getTestClassName(), $output->getOutput());
56
    }
57
58
    public function testOnProcessParsingCompleted()
59
    {
60
        $output = new UnformattedOutputStub();
61
        $printer = new DebugPrinter($output);
62
63
        $printer->onProcessParsingCompleted();
64
65
        $this->assertContains('PROCESS PARSING COMPLETED', $output->getOutput());
66
        $this->assertContains('RESULTS', $output->getOutput());
67
    }
68
69
    public function testOnProcessToBeRetried()
70
    {
71
        $output = new UnformattedOutputStub();
72
        $printer = new DebugPrinter($output);
73
        $process = new StubbedParaunitProcess();
74
75
        $printer->onProcessToBeRetried(new ProcessEvent($process));
76
77
        $this->assertContains('PROCESS TO BE RETRIED', $output->getOutput());
78
        $this->assertContains($process->getFilename(), $output->getOutput());
79
    }
80
}
81