3
3
namespace Differ \Tests ;
4
4
5
5
use PHPUnit \Framework \TestCase ;
6
+ use PHPUnit \Framework \Attributes \DataProvider ;
6
7
7
8
use function Differ \Differ \genDiff ;
8
9
use function PHPUnit \Framework \assertEquals ;
@@ -13,9 +14,6 @@ class DifferTest extends TestCase
13
14
private string $ beforeJsonPath ;
14
15
private string $ afterYamlPath ;
15
16
private string $ beforeYamlPath ;
16
- private string $ resultStylishPath ;
17
- private string $ resultPlainPath ;
18
- private string $ resultJsonPath ;
19
17
20
18
public function setUp (): void
21
19
{
@@ -24,10 +22,6 @@ public function setUp(): void
24
22
25
23
$ this ->beforeYamlPath = $ this ->getFixturePath ('before.yaml ' );
26
24
$ this ->afterYamlPath = $ this ->getFixturePath ('after.yaml ' );
27
-
28
- $ this ->resultStylishPath = $ this ->getFixturePath ('resultStylish.txt ' );
29
- $ this ->resultPlainPath = $ this ->getFixturePath ('resultPlain.txt ' );
30
- $ this ->resultJsonPath = $ this ->getFixturePath ('resultJson.txt ' );
31
25
}
32
26
33
27
public function getFixturePath (string $ fixtureName ): string
@@ -36,58 +30,26 @@ public function getFixturePath(string $fixtureName): string
36
30
return realpath (implode ('/ ' , $ parts ));
37
31
}
38
32
39
- public function testGenDiff (): void
33
+ #[DataProvider('genDiffProvider ' )]
34
+ public function testGenDiff ($ resultName , $ format ): void
40
35
{
41
36
assertEquals (
42
- file_get_contents ($ this ->resultStylishPath ),
43
- genDiff (
44
- $ this ->beforeJsonPath ,
45
- $ this ->afterJsonPath
46
- )
47
- );
48
-
49
- assertEquals (
50
- file_get_contents ($ this ->resultStylishPath ),
51
- genDiff (
52
- $ this ->beforeYamlPath ,
53
- $ this ->afterYamlPath
54
- )
55
- );
56
-
57
- assertEquals (
58
- file_get_contents ($ this ->resultPlainPath ),
59
- genDiff (
60
- $ this ->beforeJsonPath ,
61
- $ this ->afterJsonPath ,
62
- 'plain '
63
- )
37
+ file_get_contents ($ this ->getFixturePath ($ resultName )),
38
+ genDiff ($ this ->beforeJsonPath , $ this ->afterJsonPath , $ format )
64
39
);
65
40
66
41
assertEquals (
67
- file_get_contents ($ this ->resultPlainPath ),
68
- genDiff (
69
- $ this ->beforeYamlPath ,
70
- $ this ->afterYamlPath ,
71
- 'plain '
72
- )
73
- );
74
-
75
- assertEquals (
76
- file_get_contents ($ this ->resultJsonPath ),
77
- genDiff (
78
- $ this ->beforeYamlPath ,
79
- $ this ->afterYamlPath ,
80
- 'json '
81
- )
42
+ file_get_contents ($ this ->getFixturePath ($ resultName )),
43
+ genDiff ($ this ->beforeYamlPath , $ this ->afterYamlPath , $ format )
82
44
);
45
+ }
83
46
84
- assertEquals (
85
- file_get_contents ($ this ->resultJsonPath ),
86
- genDiff (
87
- $ this ->beforeJsonPath ,
88
- $ this ->afterJsonPath ,
89
- 'json '
90
- )
91
- );
47
+ public static function genDiffProvider (): array
48
+ {
49
+ return [
50
+ ['resultStylish.txt ' , 'stylish ' ],
51
+ ['resultPlain.txt ' , 'plain ' ],
52
+ ['resultJson.txt ' , 'json ' ]
53
+ ];
92
54
}
93
55
}
0 commit comments