diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 86904a0..4b2d014 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,22 +1,9 @@ */ @@ -37,7 +44,7 @@ public function testOneTin(string $tin): void $subject = $adis->statusBusinessSubject($tin); Assert::type(Ares\Adis\StatusBusinessSubjects\Subject::class, $subject); - Assert::equal(loadResult("adis/$subject->tin"), Json::decode(Json::encode($subject))); + $this->assertFile($subject->tin, $subject); } @@ -57,7 +64,7 @@ public function testMulti(): void $results = []; foreach ($adis->statusBusinessSubjects($tins) as $name => $subject) { Assert::type(Ares\Adis\StatusBusinessSubjects\Subject::class, $subject); - Assert::equal(loadResult("adis/$subject->tin"), Json::decode(Json::encode($subject))); + $this->assertFile($subject->tin, $subject); $results[$name] = $subject; } diff --git a/tests/src/E2E/Ares/CoreTest.php b/tests/src/E2E/Ares/CoreTest.php index ec741db..b1a44e7 100644 --- a/tests/src/E2E/Ares/CoreTest.php +++ b/tests/src/E2E/Ares/CoreTest.php @@ -5,7 +5,6 @@ use h4kuna; use h4kuna\Ares; use h4kuna\Ares\Tests\TestCase; -use Nette\Utils\Json; use Tester\Assert; require_once __DIR__ . '/../../../bootstrap.php'; @@ -15,6 +14,14 @@ */ final class CoreTest extends TestCase { + use Ares\Tests\UseStoredFile; + + protected static function getMask(): string + { + return __DIR__ . '/../../../fixtures/ares/%file%.json'; + } + + /** * @return array> */ @@ -46,9 +53,8 @@ protected function provideCore(): array public function testCore(string $in): void { $data = (new Ares\AresFactory())->create()->loadBasic($in); - $json = Json::decode(Json::encode($data)); - sort($json->nace, SORT_NUMERIC); // @phpstan-ignore-line - Assert::equal(loadResult("ares/$data->in"), $json); + sort($data->nace, SORT_NUMERIC); // @phpstan-ignore-line + $this->assertFile($data->in, $data); } diff --git a/tests/src/E2E/DataBox/00007064.ser b/tests/src/E2E/DataBox/00007064.ser deleted file mode 100644 index 6de6598..0000000 --- a/tests/src/E2E/DataBox/00007064.ser +++ /dev/null @@ -1 +0,0 @@ -a:16:{i:0;O:8:"stdClass":6:{s:3:"Ico";s:8:"00007064";s:10:"NazevOsoby";s:19:"Ministerstvo vnitra";s:4:"ISDS";s:7:"6bnaawp";s:3:"PDZ";s:5:"false";s:11:"TypSubjektu";s:3:"OVM";s:11:"AdresaSidla";O:8:"stdClass":8:{s:12:"AdresaTextem";s:46:"Nad štolou 936/3, Holešovice, 17000, Praha 7";s:10:"OkresNazev";O:8:"stdClass":0:{}s:9:"ObecNazev";s:7:"Praha 7";s:13:"CastObceNazev";s:11:"Holešovice";s:10:"UliceNazev";s:11:"Nad štolou";s:8:"PostaKod";s:5:"17000";s:12:"CisloDomovni";s:3:"936";s:15:"CisloOrientacni";s:1:"3";}}i:1;O:8:"stdClass":6:{s:3:"Ico";s:8:"00007064";s:10:"NazevOsoby";s:43:"P.O.Box 35, Praha 616 (Ministerstvo vnitra)";s:4:"ISDS";s:7:"265vfsh";s:3:"PDZ";s:5:"false";s:11:"TypSubjektu";s:7:"OVM_REQ";s:11:"AdresaSidla";O:8:"stdClass":8:{s:12:"AdresaTextem";s:46:"Nad štolou 936/3, Holešovice, 17000, Praha 7";s:10:"OkresNazev";O:8:"stdClass":0:{}s:9:"ObecNazev";s:7:"Praha 7";s:13:"CastObceNazev";s:11:"Holešovice";s:10:"UliceNazev";s:11:"Nad štolou";s:8:"PostaKod";s:5:"17000";s:12:"CisloDomovni";s:3:"936";s:15:"CisloOrientacni";s:1:"3";}}i:2;O:8:"stdClass":6:{s:3:"Ico";s:8:"00007064";s:10:"NazevOsoby";s:53:"Komunikace mezi EKIS MV a ISoSS (Ministerstvo vnitra)";s:4:"ISDS";s:7:"t88358j";s:3:"PDZ";s:5:"false";s:11:"TypSubjektu";s:7:"OVM_REQ";s:11:"AdresaSidla";O:8:"stdClass":8:{s:12:"AdresaTextem";s:34:"Na Pankráci 1623/72, 14000, Praha";s:10:"OkresNazev";O:8:"stdClass":0:{}s:9:"ObecNazev";s:5:"Praha";s:13:"CastObceNazev";O:8:"stdClass":0:{}s:10:"UliceNazev";s:12:"Na Pankráci";s:8:"PostaKod";s:5:"14000";s:12:"CisloDomovni";s:4:"1623";s:15:"CisloOrientacni";s:2:"72";}}i:3;O:8:"stdClass":6:{s:3:"Ico";s:8:"00007064";s:10:"NazevOsoby";s:50:"Odbor provozu a rozvoje EKIS (Ministerstvo vnitra)";s:4:"ISDS";s:7:"v522hjw";s:3:"PDZ";s:5:"false";s:11:"TypSubjektu";s:7:"OVM_REQ";s:11:"AdresaSidla";O:8:"stdClass":8:{s:12:"AdresaTextem";s:43:"Na Pankráci 1623/72, Nusle, 14000, Praha 4";s:10:"OkresNazev";O:8:"stdClass":0:{}s:9:"ObecNazev";s:7:"Praha 4";s:13:"CastObceNazev";s:5:"Nusle";s:10:"UliceNazev";s:12:"Na Pankráci";s:8:"PostaKod";s:5:"14000";s:12:"CisloDomovni";s:4:"1623";s:15:"CisloOrientacni";s:2:"72";}}i:4;O:8:"stdClass":6:{s:3:"Ico";s:8:"00007064";s:10:"NazevOsoby";s:48:"sekce pro státní službu (Ministerstvo vnitra)";s:4:"ISDS";s:7:"9iutsan";s:3:"PDZ";s:5:"false";s:11:"TypSubjektu";s:7:"OVM_REQ";s:11:"AdresaSidla";O:8:"stdClass":8:{s:12:"AdresaTextem";s:50:"Jindřišská 967/34, Nové Město, 11000, Praha 1";s:10:"OkresNazev";O:8:"stdClass":0:{}s:9:"ObecNazev";s:7:"Praha 1";s:13:"CastObceNazev";s:12:"Nové Město";s:10:"UliceNazev";s:13:"Jindřišská";s:8:"PostaKod";s:5:"11000";s:12:"CisloDomovni";s:3:"967";s:15:"CisloOrientacni";s:2:"34";}}i:5;O:8:"stdClass":6:{s:3:"Ico";s:8:"00007064";s:10:"NazevOsoby";s:49:"sekce státního tajemníka (Ministerstvo vnitra)";s:4:"ISDS";s:7:"krk34e3";s:3:"PDZ";s:5:"false";s:11:"TypSubjektu";s:7:"OVM_REQ";s:11:"AdresaSidla";O:8:"stdClass":8:{s:12:"AdresaTextem";s:46:"Nad štolou 936/3, Holešovice, 17000, Praha 7";s:10:"OkresNazev";O:8:"stdClass":0:{}s:9:"ObecNazev";s:7:"Praha 7";s:13:"CastObceNazev";s:11:"Holešovice";s:10:"UliceNazev";s:11:"Nad štolou";s:8:"PostaKod";s:5:"17000";s:12:"CisloDomovni";s:3:"936";s:15:"CisloOrientacni";s:1:"3";}}i:6;O:8:"stdClass":6:{s:3:"Ico";s:8:"00007064";s:10:"NazevOsoby";s:41:"P.O.BOX 69, Praha 4 (Ministerstvo vnitra)";s:4:"ISDS";s:7:"eck76yk";s:3:"PDZ";s:5:"false";s:11:"TypSubjektu";s:7:"OVM_REQ";s:11:"AdresaSidla";O:8:"stdClass":8:{s:12:"AdresaTextem";s:37:"Na strži 1709/42, Krč, 14000, Praha";s:10:"OkresNazev";O:8:"stdClass":0:{}s:9:"ObecNazev";s:5:"Praha";s:13:"CastObceNazev";s:4:"Krč";s:10:"UliceNazev";s:9:"Na strži";s:8:"PostaKod";s:5:"14000";s:12:"CisloDomovni";s:4:"1709";s:15:"CisloOrientacni";s:2:"42";}}i:7;O:8:"stdClass":6:{s:3:"Ico";s:8:"00007064";s:10:"NazevOsoby";s:70:"Centrum zajištěných aktiv Ministerstva vnitra (Ministerstvo vnitra)";s:4:"ISDS";s:7:"v3p745b";s:3:"PDZ";s:5:"false";s:11:"TypSubjektu";s:7:"OVM_REQ";s:11:"AdresaSidla";O:8:"stdClass":8:{s:12:"AdresaTextem";s:43:"Na Pankráci 1623/72, Nusle, 14000, Praha 4";s:10:"OkresNazev";O:8:"stdClass":0:{}s:9:"ObecNazev";s:7:"Praha 4";s:13:"CastObceNazev";s:5:"Nusle";s:10:"UliceNazev";s:12:"Na Pankráci";s:8:"PostaKod";s:5:"14000";s:12:"CisloDomovni";s:4:"1623";s:15:"CisloOrientacni";s:2:"72";}}i:8;O:8:"stdClass":6:{s:3:"Ico";s:8:"00007064";s:10:"NazevOsoby";s:42:"P.O.BOX 92, Praha 74 (Ministerstvo vnitra)";s:4:"ISDS";s:7:"tvz75mf";s:3:"PDZ";s:5:"false";s:11:"TypSubjektu";s:7:"OVM_REQ";s:11:"AdresaSidla";O:8:"stdClass":8:{s:12:"AdresaTextem";s:43:"Dělnická 213/8, Holešovice, 17000, Praha";s:10:"OkresNazev";O:8:"stdClass":0:{}s:9:"ObecNazev";s:5:"Praha";s:13:"CastObceNazev";s:11:"Holešovice";s:10:"UliceNazev";s:10:"Dělnická";s:8:"PostaKod";s:5:"17000";s:12:"CisloDomovni";s:3:"213";s:15:"CisloOrientacni";s:1:"8";}}i:9;O:8:"stdClass":6:{s:3:"Ico";s:8:"00007064";s:10:"NazevOsoby";s:88:"Dotační program na měkké cíle - Odbor bezpečnostní politiky (Ministerstvo vnitra)";s:4:"ISDS";s:7:"f6wh3w8";s:3:"PDZ";s:5:"false";s:11:"TypSubjektu";s:7:"OVM_REQ";s:11:"AdresaSidla";O:8:"stdClass":8:{s:12:"AdresaTextem";s:44:"Nad štolou 936/3, Holešovice, 17000, Praha";s:10:"OkresNazev";O:8:"stdClass":0:{}s:9:"ObecNazev";s:5:"Praha";s:13:"CastObceNazev";s:11:"Holešovice";s:10:"UliceNazev";s:11:"Nad štolou";s:8:"PostaKod";s:5:"17000";s:12:"CisloDomovni";s:3:"936";s:15:"CisloOrientacni";s:1:"3";}}i:10;O:8:"stdClass":6:{s:3:"Ico";s:8:"00007064";s:10:"NazevOsoby";s:46:"Bezpečnostní sbory ČR (Ministerstvo vnitra)";s:4:"ISDS";s:7:"g2jdsfa";s:3:"PDZ";s:5:"false";s:11:"TypSubjektu";s:7:"OVM_REQ";s:11:"AdresaSidla";O:8:"stdClass":8:{s:12:"AdresaTextem";s:46:"Nad štolou 936/3, Holešovice, 17000, Praha 7";s:10:"OkresNazev";O:8:"stdClass":0:{}s:9:"ObecNazev";s:7:"Praha 7";s:13:"CastObceNazev";s:11:"Holešovice";s:10:"UliceNazev";s:11:"Nad štolou";s:8:"PostaKod";s:5:"17000";s:12:"CisloDomovni";s:3:"936";s:15:"CisloOrientacni";s:1:"3";}}i:11;O:8:"stdClass":6:{s:3:"Ico";s:8:"00007064";s:10:"NazevOsoby";s:32:"P.O.Box 36 (Ministerstvo vnitra)";s:4:"ISDS";s:7:"ujndxxk";s:3:"PDZ";s:5:"false";s:11:"TypSubjektu";s:7:"OVM_REQ";s:11:"AdresaSidla";O:8:"stdClass":8:{s:12:"AdresaTextem";s:29:"Nad Štolou 3, 17034, Praha 7";s:10:"OkresNazev";O:8:"stdClass":0:{}s:9:"ObecNazev";s:7:"Praha 7";s:13:"CastObceNazev";O:8:"stdClass":0:{}s:10:"UliceNazev";s:11:"Nad Štolou";s:8:"PostaKod";s:5:"17034";s:12:"CisloDomovni";s:1:"3";s:15:"CisloOrientacni";O:8:"stdClass":0:{}}}i:12;O:8:"stdClass":6:{s:3:"Ico";s:8:"00007064";s:10:"NazevOsoby";s:97:"Automat pro Sbírku právních předpisů územních samosprávných celků (Ministerstvo vnitra)";s:4:"ISDS";s:7:"ci2xihx";s:3:"PDZ";s:5:"false";s:11:"TypSubjektu";s:7:"OVM_REQ";s:11:"AdresaSidla";O:8:"stdClass":8:{s:12:"AdresaTextem";s:48:"náměstí Hrdinů 1634/3, Nusle, 14000, Praha 4";s:10:"OkresNazev";O:8:"stdClass":0:{}s:9:"ObecNazev";s:7:"Praha 4";s:13:"CastObceNazev";s:5:"Nusle";s:10:"UliceNazev";s:18:"náměstí Hrdinů";s:8:"PostaKod";s:5:"14000";s:12:"CisloDomovni";s:4:"1634";s:15:"CisloOrientacni";s:1:"3";}}i:13;O:8:"stdClass":6:{s:3:"Ico";s:8:"00007064";s:10:"NazevOsoby";s:32:"P.O.Box 10 (Ministerstvo vnitra)";s:4:"ISDS";s:7:"wgunyb8";s:3:"PDZ";s:5:"false";s:11:"TypSubjektu";s:7:"OVM_REQ";s:11:"AdresaSidla";O:8:"stdClass":8:{s:12:"AdresaTextem";s:33:"Nad Štolou 936/3, 17034, Praha 7";s:10:"OkresNazev";O:8:"stdClass":0:{}s:9:"ObecNazev";s:7:"Praha 7";s:13:"CastObceNazev";O:8:"stdClass":0:{}s:10:"UliceNazev";s:11:"Nad Štolou";s:8:"PostaKod";s:5:"17034";s:12:"CisloDomovni";s:3:"936";s:15:"CisloOrientacni";s:1:"3";}}i:14;O:8:"stdClass":6:{s:3:"Ico";s:8:"00007064";s:10:"NazevOsoby";s:31:"P.O.Box 2 (Ministerstvo vnitra)";s:4:"ISDS";s:7:"fxpufij";s:3:"PDZ";s:5:"false";s:11:"TypSubjektu";s:7:"OVM_REQ";s:11:"AdresaSidla";O:8:"stdClass":8:{s:12:"AdresaTextem";s:33:"Nad Štolou 936/3, 17031, Praha 7";s:10:"OkresNazev";O:8:"stdClass":0:{}s:9:"ObecNazev";s:7:"Praha 7";s:13:"CastObceNazev";O:8:"stdClass":0:{}s:10:"UliceNazev";s:11:"Nad Štolou";s:8:"PostaKod";s:5:"17031";s:12:"CisloDomovni";s:3:"936";s:15:"CisloOrientacni";s:1:"3";}}i:15;O:8:"stdClass":6:{s:3:"Ico";s:8:"00007064";s:10:"NazevOsoby";s:39:"přihrádka 21/38 (Ministerstvo vnitra)";s:4:"ISDS";s:7:"xdaun57";s:3:"PDZ";s:5:"false";s:11:"TypSubjektu";s:7:"OVM_REQ";s:11:"AdresaSidla";O:8:"stdClass":8:{s:12:"AdresaTextem";s:33:"Nad štolou 936/3, 17034, Praha 7";s:10:"OkresNazev";O:8:"stdClass":0:{}s:9:"ObecNazev";s:7:"Praha 7";s:13:"CastObceNazev";O:8:"stdClass":0:{}s:10:"UliceNazev";s:11:"Nad štolou";s:8:"PostaKod";s:5:"17034";s:12:"CisloDomovni";s:3:"936";s:15:"CisloOrientacni";s:1:"3";}}} \ No newline at end of file diff --git a/tests/src/E2E/DataBox/27082440.ser b/tests/src/E2E/DataBox/27082440.ser deleted file mode 100644 index 214c1c1..0000000 --- a/tests/src/E2E/DataBox/27082440.ser +++ /dev/null @@ -1 +0,0 @@ -a:1:{i:0;O:8:"stdClass":6:{s:3:"Ico";s:8:"27082440";s:10:"NazevOsoby";s:12:"Alza.cz a.s.";s:4:"ISDS";s:7:"xtkcrkz";s:3:"PDZ";s:4:"true";s:11:"TypSubjektu";s:2:"PO";s:11:"AdresaSidla";O:8:"stdClass":8:{s:12:"AdresaTextem";s:47:"Jankovcova 1522/53, Holešovice, 17000, Praha 7";s:10:"OkresNazev";O:8:"stdClass":0:{}s:9:"ObecNazev";s:7:"Praha 7";s:13:"CastObceNazev";s:11:"Holešovice";s:10:"UliceNazev";s:10:"Jankovcova";s:8:"PostaKod";s:5:"17000";s:12:"CisloDomovni";s:4:"1522";s:15:"CisloOrientacni";s:2:"53";}}} \ No newline at end of file diff --git a/tests/src/E2E/DataBoxTest.php b/tests/src/E2E/DataBoxTest.php index 4a6ace0..0a69e0e 100644 --- a/tests/src/E2E/DataBoxTest.php +++ b/tests/src/E2E/DataBoxTest.php @@ -4,7 +4,7 @@ use h4kuna\Ares\AresFactory; use h4kuna\Ares\Tests\TestCase; -use Tester\Assert; +use h4kuna\Ares\Tests\UseStoredFile; require __DIR__ . '/../../bootstrap.php'; @@ -13,6 +13,13 @@ */ final class DataBoxTest extends TestCase { + use UseStoredFile; + + protected static function getMask(): string + { + return __DIR__ . '/../../fixtures/databox/%file%.json'; + } + /** * @dataProvider provideBasic @@ -21,13 +28,7 @@ public function testBasic(string $in): void { $ares = (new AresFactory())->create(); $data = $ares->loadDataBox($in); - $file = __DIR__ . "/../E2E/DataBox/$in.ser"; - $expected = unserialize(trim((string) file_get_contents($file))); - assert(is_array($expected)); - foreach ($expected as $k => $v) { - // file_put_contents($file, serialize($data)); - Assert::equal($v, $data[$k]); - } + $this->assertFile($in, $data); } diff --git a/tests/src/E2E/Vies/ClientTest.php b/tests/src/E2E/Vies/ClientTest.php index 0a5f971..d0e7a62 100644 --- a/tests/src/E2E/Vies/ClientTest.php +++ b/tests/src/E2E/Vies/ClientTest.php @@ -69,7 +69,7 @@ public function assertCheckVat(string|Ares\Vies\ViesEntity $vatNumber, bool|Thro try { $response = $aresFactory->checkVatVies($vatNumber); } catch (Ares\Exceptions\ServerResponseException $e) { - Assert::same('MS_UNAVAILABLE', $e->getMessage()); + Assert::true(in_array($e->getMessage(), ['MS_UNAVAILABLE', 'MS_MAX_CONCURRENT_REQ'], true)); Environment::skip('VIES service is unavailable'); return; } diff --git a/tests/src/UseStoredFile.php b/tests/src/UseStoredFile.php new file mode 100644 index 0000000..0bd3ba2 --- /dev/null +++ b/tests/src/UseStoredFile.php @@ -0,0 +1,43 @@ +getMask(), ['%file%' => $filename]); + $extension = pathinfo($filename, PATHINFO_EXTENSION); + if (is_file($filename) === false) { + file_put_contents($filename, self::saveContent($content, $extension)); + } + + Assert::same(file_get_contents($filename), self::saveContent($content, $extension)); + } + + + protected static function getMask(): string + { + return '%file%'; + } + + + private static function saveContent(mixed $content, string $extension): string + { + if (is_string($content)) { + return $content; + } + + $jsonReflection = new \ReflectionClass(Json::class); + $isOld = $jsonReflection->getMethod('encode')->getParameters()[1]->name === 'options'; + + return match ($extension) { + 'json' => $isOld ? strtr(Json::encode($content, Json::PRETTY), ['\\/' => '/']) : Json::encode($content, true), + default => throw new \Exception('not implemented'), + }; + } +}