From df1867eb6d23ed4916fc17408240b3b9be37f2ee Mon Sep 17 00:00:00 2001 From: Filip Melik Date: Mon, 25 Mar 2019 16:19:46 +0100 Subject: [PATCH] fix + test cases for findByName method when no results found [closes #22] (#23) --- src/Ares.php | 8 ++++---- tests/AresTest.php | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Ares.php b/src/Ares.php index 87346c1..dcf9244 100644 --- a/src/Ares.php +++ b/src/Ares.php @@ -309,11 +309,11 @@ public function findVatById($id) } /** - * @param $name - * @param null $city + * @param string $name + * @param null $city * * @throws InvalidArgumentException - * @throws \Exception + * @throws AresException * * @return array|AresRecord[]|AresRecords */ @@ -350,7 +350,7 @@ public function findByName($name, $city = null) $data = $aresResponse->children($ns['are']); $elements = $data->children($ns['dtt'])->V->S; - if (!count($elements)) { + if (empty($elements)) { throw new AresException('Nic nebylo nalezeno.'); } diff --git a/tests/AresTest.php b/tests/AresTest.php index eba224b..5c06d5c 100644 --- a/tests/AresTest.php +++ b/tests/AresTest.php @@ -52,6 +52,22 @@ public function testFindByEmptyStringException() $this->ares->findByIdentificationNumber(''); } + public function testFindByName() + { + $results = $this->ares->findByName('sever'); + + $this->assertGreaterThan(0, count($results)); + } + + /** + * @expectedException \Defr\Ares\AresException + * @expectedExceptionMessage Nic nebylo nalezeno. + */ + public function testFindByNameNonExistentName() + { + $this->ares->findByName('some non-existent company name'); + } + public function testGetCompanyPeople() { if ($this->isTravis()) { @@ -59,8 +75,7 @@ public function testGetCompanyPeople() } $record = $this->ares->findByIdentificationNumber(27791394); - $companyPeople - = $record->getCompanyPeople(); + $companyPeople = $record->getCompanyPeople(); $this->assertCount(2, $companyPeople); }