From a0a69522f761a4d1c7466ead2f1c7ae3bc211f8b Mon Sep 17 00:00:00 2001 From: Victor Dodon Date: Tue, 12 Mar 2024 12:06:24 +0200 Subject: [PATCH] Fix wrong returned value in Company::isActive() and add test --- .gitignore | 2 +- src/Models/Company.php | 5 +++-- tests/Unit/Models/CompanyTest.php | 6 +++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 361384a..c4d44e3 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,4 @@ composer.lock phpunit.xml vendor -.phpunit.result.cache \ No newline at end of file +.phpunit.result.cache diff --git a/src/Models/Company.php b/src/Models/Company.php index d1c5c63..1de51c8 100644 --- a/src/Models/Company.php +++ b/src/Models/Company.php @@ -62,11 +62,12 @@ public function getFullAddress(): string */ public function isActive(): bool { - if (empty($this->parser->getData()['stare_inactiv']['statusInactivi'] ?? null) || !is_bool($this->parser->getData()['stare_inactiv']['statusInactivi'] ?? null)) { + $inactive = $this->parser->getData()['stare_inactiv']['statusInactivi'] ?? null; + if (!isset($inactive) || !is_bool($inactive)) { return false; } - return !$this->parser->getData()['stare_inactiv']['statusInactivi'] ?? false; + return !$inactive; } /** diff --git a/tests/Unit/Models/CompanyTest.php b/tests/Unit/Models/CompanyTest.php index b8e85a7..33182a2 100644 --- a/tests/Unit/Models/CompanyTest.php +++ b/tests/Unit/Models/CompanyTest.php @@ -37,7 +37,10 @@ public function testCompanyDetails() 'cui' => 123456, 'denumire' => 'Test', 'telefon' => 07676000000, - ] + ], + 'stare_inactiv' => [ + 'statusInactivi' => false, + ], ])); $parset->expects($this->any()) ->method("getPostalCode") @@ -52,5 +55,6 @@ public function testCompanyDetails() $this->assertEquals("Şos. Bucureşti-Ploieşti", $company->getAddress()->getStreet()); $this->assertEquals("172-176", $company->getAddress()->getStreetNumber()); $this->assertEquals("057003", $company->getAddress()->getPostalCode()); + $this->assertTrue($company->isActive()); } }