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

TempFilenameFactoryTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 70
Duplicated Lines 91.43 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 64
loc 70
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetPathForLog() 14 14 1
A testGetFilenameForLog() 18 18 1
A testGetFilenameForCoverage() 17 17 1
A testGetFilenameForConfiguration() 15 15 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\Configuration;
6
7
use Paraunit\Configuration\PHPUnitConfig;
8
use Paraunit\Configuration\TempFilenameFactory;
9
use Paraunit\File\TempDirectory;
10
use Tests\BaseUnitTestCase;
11
12
/**
13
 * Class TempFilenameFactoryTest
14
 * @package Tests\Unit\Configuration
15
 */
16
class TempFilenameFactoryTest extends BaseUnitTestCase
17
{
18 View Code Duplication
    public function testGetPathForLog()
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...
19
    {
20
        $tempDir = new TempDirectory();
21
        $tempFileNameFactory = new TempFilenameFactory($tempDir);
22
23
        $pathForLog = $tempFileNameFactory->getPathForLog();
24
25
        $expected = $tempDir->getTempDirForThisExecution()
26
            . DIRECTORY_SEPARATOR
27
            . 'logs'
28
            . DIRECTORY_SEPARATOR;
29
30
        $this->assertEquals($expected, $pathForLog);
31
    }
32
33 View Code Duplication
    public function testGetFilenameForLog()
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...
34
    {
35
        $processUniqueId = 'asdasdasdasd';
36
        $tempDir = new TempDirectory();
37
        $tempFileNameFactory = new TempFilenameFactory($tempDir);
38
39
        $filenameForLog = $tempFileNameFactory->getFilenameForLog($processUniqueId);
40
41
        $expected = $tempDir->getTempDirForThisExecution()
42
            . DIRECTORY_SEPARATOR
43
            . 'logs'
44
            . DIRECTORY_SEPARATOR
45
            . $processUniqueId
46
            . '.json.log';
47
48
        $this->assertEquals($expected, $filenameForLog);
49
        $this->assertStringStartsWith($tempFileNameFactory->getPathForLog(), $filenameForLog);
50
    }
51
52 View Code Duplication
    public function testGetFilenameForCoverage()
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...
53
    {
54
        $processUniqueId = 'asdasdasdasd';
55
        $tempDir = new TempDirectory();
56
        $tempFileNameFactory = new TempFilenameFactory($tempDir);
57
58
        $filenameForCoverage = $tempFileNameFactory->getFilenameForCoverage($processUniqueId);
59
60
        $expected = $tempDir->getTempDirForThisExecution()
61
            . DIRECTORY_SEPARATOR
62
            . 'coverage'
63
            . DIRECTORY_SEPARATOR
64
            . $processUniqueId
65
            . '.php';
66
67
        $this->assertEquals($expected, $filenameForCoverage);
68
    }
69
70 View Code Duplication
    public function testGetFilenameForConfiguration()
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...
71
    {
72
        $tempDir = new TempDirectory();
73
        $tempFileNameFactory = new TempFilenameFactory($tempDir);
74
75
        $filenameForConfiguration = $tempFileNameFactory->getFilenameForConfiguration();
76
77
        $expected = $tempDir->getTempDirForThisExecution()
78
            . DIRECTORY_SEPARATOR
79
            . 'config'
80
            . DIRECTORY_SEPARATOR
81
            . PHPUnitConfig::DEFAULT_FILE_NAME;
82
83
        $this->assertEquals($expected, $filenameForConfiguration);
84
    }
85
}
86