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

DebugPrinterTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 37.31 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testIsSubscribedToAllProcessEvents() 0 14 2
A testOnProcessStarted() 12 12 1
A testOnProcessTerminated() 13 13 1
A testOnProcessParsingCompleted() 0 10 1
A testOnProcessToBeRetried() 0 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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