1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Genkgo\TestCamt\Unit; |
||
6 | |||
7 | use Genkgo\Camt\Config; |
||
8 | use Genkgo\Camt\Reader; |
||
9 | use PHPUnit\Framework\Assert; |
||
10 | use PHPUnit\Framework\TestCase; |
||
11 | |||
12 | class RegressionTest extends TestCase |
||
13 | { |
||
14 | /** |
||
15 | * @dataProvider providerRegression |
||
16 | */ |
||
17 | public function testRegression(string $file): void |
||
18 | { |
||
19 | $reader = new Reader(Config::getDefault()); |
||
20 | $message = $reader->readFile($file); |
||
21 | |||
22 | $dumper = new Dumper(); |
||
23 | $actual = $dumper->dump($message); |
||
24 | $expectedFile = str_replace('.xml', '.json', $file); |
||
25 | |||
26 | $this->assertFile($expectedFile, $actual); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Custom assert that will not produce gigantic diff. |
||
31 | */ |
||
32 | private function assertFile(string $file, string $actualContent): void |
||
33 | { |
||
34 | // Log actual result for easier comparison with external diff tools |
||
35 | $logFile = 'logs/' . $file; |
||
36 | $dir = dirname($logFile); |
||
37 | @mkdir($dir, 0777, true); |
||
0 ignored issues
–
show
|
|||
38 | file_put_contents($logFile, $actualContent); |
||
39 | |||
40 | Assert::assertFileExists($file, 'Expected file must exist on disk, fix it with: cp ' . $logFile . ' ' . $file); |
||
41 | $expected = file_get_contents($file); |
||
42 | |||
43 | Assert::assertTrue($expected === $actualContent, 'File content does not match, compare with: meld ' . $file . ' ' . $logFile); |
||
44 | } |
||
45 | |||
46 | public static function providerRegression(): iterable |
||
47 | { |
||
48 | yield ['test/data/camt052.v1.xml']; |
||
49 | yield ['test/data/camt052.v2.other-account.xml']; |
||
50 | yield ['test/data/camt052.v2.xml']; |
||
51 | yield ['test/data/camt052.v4.xml']; |
||
52 | yield ['test/data/camt052.v6.xml']; |
||
53 | yield ['test/data/camt053.v2.five.decimals.xml']; |
||
54 | yield ['test/data/camt053.v2.minimal.ultimate.xml']; |
||
55 | yield ['test/data/camt053.v2.minimal.xml']; |
||
56 | yield ['test/data/camt053.v2.multi.statement.xml']; |
||
57 | yield ['test/data/camt053.v3.xml']; |
||
58 | yield ['test/data/camt053.v4.xml']; |
||
59 | yield ['test/data/camt054.v2.xml']; |
||
60 | yield ['test/data/camt054.v4.xml']; |
||
61 | yield ['test/data/camt054.v8.xml']; |
||
62 | yield ['test/data/camt054.v8-with-financial-institution.xml']; |
||
63 | } |
||
64 | } |
||
65 |
If you suppress an error, we recommend checking for the error condition explicitly: