diff --git a/phpunit.xml b/phpunit.xml index 7a016f4..20bd15d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,7 +8,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="true"> + stopOnFailure="false"> ./tests diff --git a/src/Http/ResponseFactory.php b/src/Http/ResponseFactory.php index d791cd3..12c76fc 100644 --- a/src/Http/ResponseFactory.php +++ b/src/Http/ResponseFactory.php @@ -22,7 +22,7 @@ public static function createFromOutput(string $response, int $statusCode): Flex $version = null; /** @var string|null $message */ - $message = null; + $message = $response; $success = false; $statistics = []; $rowCount = 0; diff --git a/src/Http/ResponseHydrator.php b/src/Http/ResponseHydrator.php index aeef6c7..b44f677 100644 --- a/src/Http/ResponseHydrator.php +++ b/src/Http/ResponseHydrator.php @@ -5,6 +5,7 @@ use Consistence\ObjectPrototype; use EcomailFlexibee\Config; use EcomailFlexibee\Exception\EcomailFlexibeeNoEvidenceResult; +use EcomailFlexibee\Exception\EcomailFlexibeeRequestError; use EcomailFlexibee\Http\Response\Response; use EcomailFlexibee\Result\EvidenceResult; @@ -24,11 +25,16 @@ public function __construct(Config $config) /** * @param \EcomailFlexibee\Http\Response\Response $response * @return array<\EcomailFlexibee\Result\EvidenceResult> + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestError */ public function convertResponseToEvidenceResults(Response $response): array { $data = $response->getData(); + if (isset($data['success']) && $data['success'] === 'false') { + throw new EcomailFlexibeeRequestError($data['message']); + } + if (!isset($data[$this->config->getEvidence()])) { if (\count($data) === 0) { $data = $response->getStatistics(); @@ -41,7 +47,7 @@ public function convertResponseToEvidenceResults(Response $response): array return [new EvidenceResult($data)]; } - return \array_map(static function (array $data){ + return \array_map(static function (array $data) { return new EvidenceResult($data); }, $data[$this->config->getEvidence()]); } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 796ef13..368763a 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -206,11 +206,17 @@ public function testAllAndChunkInEvidence(): void public function testSearchInEvidence(): void { $client = new Client(Config::HOST, Config::COMPANY, Config::USERNAME, Config::PASSWORD, 'faktura-vydana', false, null); - $result = $client->searchInEvidence('kod<>\'JAN\'', []); + $result = $client->searchInEvidence('(kod neq \'JAN\')', []); Assert::assertTrue(count($result) > 0); + $this->expectException(EcomailFlexibeeRequestError::class); + $client->searchInEvidence('kod neq \'JAN\'', []); + } - $result = $client->searchInEvidence('(datSplat<\'2018-12-04\'%20and%20zuctovano=false)', []); - Assert::assertTrue(count($result) > 0); + public function testSearchInEvidenceWithInvalidUrl(): void + { + $client = new Client(Config::HOST, Config::COMPANY, Config::USERNAME, Config::PASSWORD, 'faktura-vydana', false, null); + $this->expectException(EcomailFlexibeeRequestError::class); + $client->searchInEvidence(' bla.json', []); } public function testDryRunRequest(): void @@ -238,54 +244,6 @@ public function testMakeCustomRequest(): void Assert::assertArrayHasKey('properties', $data->getData()); } - public function testWithExampleFlexibeeData(): void - { - /** @var string $content */ - $content = file_get_contents(sprintf('%s/_Resources/smlouva.xml', __DIR__)); - /** @var \SimpleXMLElement $content */ - $content = simplexml_load_string($content); - /** @var string $content */ - $content = json_encode((array) $content); - $xmlData = json_decode($content, true); - - foreach ($xmlData as $evidenceName => $evidenceData) { - if (in_array($evidenceName, ['@attributes'], true)) { - continue; - } - - $client = new Client(Config::HOST, Config::COMPANY, Config::USERNAME, Config::PASSWORD, $evidenceName, false, null); - - if (array_key_exists('@attributes', $evidenceData)) { - unset($evidenceData['@attributes']); - } - - if (array_key_exists('id', $evidenceData)) { - unset($evidenceData['id']); - } - - try { - if ($evidenceName === 'smlouva' && isset($evidenceData['polozkySmlouvy'])) { - unset($evidenceData['polozkySmlouvy']['@attributes']); - $evidenceData['polozkySmlouvy']['kod'] = uniqid(); - - foreach ($evidenceData['polozkySmlouvy']["smlouva-polozka"] as &$item) { - $item['kod'] = uniqid(); - - } - } - - $idEvidence = (int) $client->save($evidenceData, null)->getData()[0]['id']; - $client->deleteById($idEvidence); - } catch (EcomailFlexibeeRequestError $exception) { - if (mb_stripos($exception->getMessage(), 'již používá jiný záznam') !== false) { - continue; - } - - throw $exception; - } - } - } - public function testRunBackendProcesses(): void { $client = new Client(Config::HOST, Config::COMPANY, Config::USERNAME, Config::PASSWORD, 'pokladni-pohyb', false); @@ -318,36 +276,11 @@ private function checkResponseStructure(EvidenceResult $result): void public function testUnknownCompany(): void { $client = new Client(Config::HOST, 'xxx', Config::USERNAME, Config::PASSWORD, 'faktura-vydana', false); - $this->expectException(EcomailFlexibeeSaveFailed::class); + $this->expectException(EcomailFlexibeeRequestError::class); $client->save([], null); } - public function testCreateUserRelations(): void - { - $client = new Client(Config::HOST, Config::COMPANY, Config::USERNAME, Config::PASSWORD, 'faktura-vydana', false); - $evidenceData = [ - 'nazev' => $this->faker->firstName, - 'kod' => uniqid(), - 'typDokl' => 'code:FAKTURA', - ]; - $invoiceIdA = (int) $client->save($evidenceData, null)->getData()[0]['id']; - Assert::assertNotEmpty($invoiceIdA); - $evidenceData = [ - 'nazev' => $this->faker->firstName, - 'kod' => uniqid(), - 'typDokl' => 'code:FAKTURA', - ]; - $invoiceIdB = (int) $client->save($evidenceData, null)->getData()[0]['id']; - Assert::assertNotEmpty($invoiceIdB); - - $client->addUserRelation($invoiceIdA, $invoiceIdB, 10.0, 1); - $relationsEvidenceResult = $client->getUserRelations($invoiceIdA); - Assert::assertNotEmpty($relationsEvidenceResult->getData()); - $relationId = $relationsEvidenceResult->getData()[0]['id']; - Assert::assertNotEmpty($relationId); - } - public function testCreateSameEvidenceRecord(): void { $code = uniqid(); diff --git a/tests/_Resources/smlouva.xml b/tests/_Resources/smlouva.xml deleted file mode 100644 index f49762c..0000000 --- a/tests/_Resources/smlouva.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - code:TEST - TEST - Smlouva za služby - - - code:TEST - code:FLEXIBEE - - - XR ROSTFLOOR-750 - test - - - XR 3267AA CR - test2 - - - -