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 | private string $timezone; |
||
15 | |||
16 | protected function setUp(): void |
||
17 | { |
||
18 | $this->timezone = date_default_timezone_get(); |
||
19 | date_default_timezone_set('UTC'); |
||
20 | } |
||
21 | |||
22 | protected function tearDown(): void |
||
23 | { |
||
24 | date_default_timezone_set($this->timezone); |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * @dataProvider providerRegression |
||
29 | */ |
||
30 | public function testRegression(string $file): void |
||
31 | { |
||
32 | $reader = new Reader(Config::getDefault()); |
||
33 | $message = $reader->readFile($file); |
||
34 | |||
35 | $dumper = new Dumper(); |
||
36 | $actual = $dumper->dump($message); |
||
37 | $expectedFile = str_replace('.xml', '.json', $file); |
||
38 | |||
39 | $this->assertFile($expectedFile, $actual); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Custom assert that will not produce gigantic diff. |
||
44 | */ |
||
45 | private function assertFile(string $file, string $actualContent): void |
||
46 | { |
||
47 | // Log actual result for easier comparison with external diff tools |
||
48 | $logFile = 'logs/' . $file; |
||
49 | $dir = dirname($logFile); |
||
50 | @mkdir($dir, 0777, true); |
||
0 ignored issues
–
show
|
|||
51 | file_put_contents($logFile, $actualContent); |
||
52 | |||
53 | Assert::assertFileExists($file, 'Expected file must exist on disk, fix it with: cp ' . $logFile . ' ' . $file); |
||
54 | $expected = file_get_contents($file); |
||
55 | |||
56 | Assert::assertTrue($expected === $actualContent, 'File content does not match, compare with: meld ' . $file . ' ' . $logFile); |
||
57 | } |
||
58 | |||
59 | public static function providerRegression(): iterable |
||
60 | { |
||
61 | yield ['test/data/camt052.v1.xml']; |
||
62 | yield ['test/data/camt052.v2.other-account.xml']; |
||
63 | yield ['test/data/camt052.v2.xml']; |
||
64 | yield ['test/data/camt052.v4.xml']; |
||
65 | yield ['test/data/camt052.v6.xml']; |
||
66 | yield ['test/data/camt053.v2.five.decimals.xml']; |
||
67 | yield ['test/data/camt053.v2.minimal.ultimate.xml']; |
||
68 | yield ['test/data/camt053.v2.minimal.xml']; |
||
69 | yield ['test/data/camt053.v2.multi.statement.xml']; |
||
70 | yield ['test/data/camt053.v3.xml']; |
||
71 | yield ['test/data/camt053.v4.xml']; |
||
72 | yield ['test/data/camt054.v2.xml']; |
||
73 | yield ['test/data/camt054.v4.xml']; |
||
74 | yield ['test/data/camt054.v8-with-UETR.xml']; |
||
75 | yield ['test/data/camt054.v8-with-financial-institution.xml']; |
||
76 | yield ['test/data/camt054.v8.xml']; |
||
77 | } |
||
78 | } |
||
79 |
If you suppress an error, we recommend checking for the error condition explicitly: