Skip to content

Commit efdcc20

Browse files
Add data provider for testGenDiff()
1 parent e28d109 commit efdcc20

File tree

1 file changed

+15
-53
lines changed

1 file changed

+15
-53
lines changed

tests/DifferTest.php

+15-53
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Differ\Tests;
44

55
use PHPUnit\Framework\TestCase;
6+
use PHPUnit\Framework\Attributes\DataProvider;
67

78
use function Differ\Differ\genDiff;
89
use function PHPUnit\Framework\assertEquals;
@@ -13,9 +14,6 @@ class DifferTest extends TestCase
1314
private string $beforeJsonPath;
1415
private string $afterYamlPath;
1516
private string $beforeYamlPath;
16-
private string $resultStylishPath;
17-
private string $resultPlainPath;
18-
private string $resultJsonPath;
1917

2018
public function setUp(): void
2119
{
@@ -24,10 +22,6 @@ public function setUp(): void
2422

2523
$this->beforeYamlPath = $this->getFixturePath('before.yaml');
2624
$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');
3125
}
3226

3327
public function getFixturePath(string $fixtureName): string
@@ -36,58 +30,26 @@ public function getFixturePath(string $fixtureName): string
3630
return realpath(implode('/', $parts));
3731
}
3832

39-
public function testGenDiff(): void
33+
#[DataProvider('genDiffProvider')]
34+
public function testGenDiff($resultName, $format): void
4035
{
4136
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)
6439
);
6540

6641
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)
8244
);
45+
}
8346

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+
];
9254
}
9355
}

0 commit comments

Comments
 (0)