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() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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
|
|
|
|
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.