From a29675154384ce2576a26f6e6464fee552cb2514 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 25 Aug 2023 22:04:37 +0200 Subject: [PATCH] Fix phpunit --- test/phpunit/RestAPIContactTest.php | 6 +++--- test/phpunit/RestAPIDocumentTest.php | 4 ++-- test/phpunit/RestAPIUserTest.php | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/phpunit/RestAPIContactTest.php b/test/phpunit/RestAPIContactTest.php index 74446e4251a..93148e804ab 100644 --- a/test/phpunit/RestAPIContactTest.php +++ b/test/phpunit/RestAPIContactTest.php @@ -137,7 +137,7 @@ class RestAPIContactTest extends PHPUnit\Framework\TestCase $object = json_decode($result['content'], true); // If success content is just an id, if not an array $this->assertNotNull($object, "Parsing of json result must not be null"); - $this->assertNotEquals(500, (empty($object['error']['code']) ? 0 : $object['error']['code']), (string) $object['error']['message']); + $this->assertNotEquals(500, ((is_scalar($object) || empty($object['error']['code'])) ? 0 : $object['error']['code']), (string) $object['error']['message']); $this->assertEquals('200', $object['success']['code']); $this->api_key = $object['success']['token']; @@ -218,7 +218,7 @@ class RestAPIContactTest extends PHPUnit\Framework\TestCase $this->assertEquals($result['curl_error_no'], ''); $object = json_decode($result['content'], true); // If success content is just an id, if not an array $this->assertNotNull($object, "Parsing of json result must no be null"); - $this->assertEquals(400, (empty($object['error']['code']) ? 0 : $object['error']['code']), (string) $object['error']['message']); + $this->assertEquals(400, ((is_scalar($object) || empty($object['error']['code'])) ? 0 : $object['error']['code']), (string) $object['error']['message']); $idofcontactcreated = (int) $object; @@ -238,7 +238,7 @@ class RestAPIContactTest extends PHPUnit\Framework\TestCase $object = json_decode($result['content'], true); // If success content is just an id, if not an array $this->assertNotNull($object, "Parsing of json result must not be null"); - $this->assertNotEquals(500, (empty($object['error']['code']) ? 0 : $object['error']['code']), (string) $object['error']['message']); + $this->assertNotEquals(500, ((is_scalar($object) || empty($object['error']['code'])) ? 0 : $object['error']['code']), (string) $object['error']['message']); $this->assertGreaterThan(0, $object, 'ID return is no > 0'); return $idofcontactcreated; diff --git a/test/phpunit/RestAPIDocumentTest.php b/test/phpunit/RestAPIDocumentTest.php index f42f59d40c9..efeb93964b6 100644 --- a/test/phpunit/RestAPIDocumentTest.php +++ b/test/phpunit/RestAPIDocumentTest.php @@ -131,7 +131,7 @@ class RestAPIDocumentTest extends PHPUnit\Framework\TestCase $object = json_decode($result['content'], true); // If success content is just an id, if not an array $this->assertNotNull($object, "Parsing of json result must not be null"); - $this->assertNotEquals(500, (empty($object['error']['code']) ? 0 : $object['error']['code']), (string) $object['error']['message']); + $this->assertNotEquals(500, ((is_scalar($object) || empty($object['error']['code'])) ? 0 : $object['error']['code']), (string) $object['error']['message']); $this->assertEquals('200', $object['success']['code']); $this->api_key = $object['success']['token']; @@ -189,7 +189,7 @@ class RestAPIDocumentTest extends PHPUnit\Framework\TestCase $object = json_decode($result['content'], true); $this->assertNotNull($object, 'Parsing of json result must not be null'); $this->assertEquals('401', $result['http_code'], 'Return code is not 401'); - $this->assertEquals('401', empty($object['error']['code']) ? '' : $object['error']['code'], 'Error code is not 401'); + $this->assertEquals('401', ((is_scalar($object) || empty($object['error']['code'])) ? '' : $object['error']['code']), 'Error code is not 401'); // Send to existent directory diff --git a/test/phpunit/RestAPIUserTest.php b/test/phpunit/RestAPIUserTest.php index 67a41b48f15..dadbc0a8030 100644 --- a/test/phpunit/RestAPIUserTest.php +++ b/test/phpunit/RestAPIUserTest.php @@ -137,7 +137,7 @@ class RestAPIUserTest extends PHPUnit\Framework\TestCase $object = json_decode($result['content'], true); // If success content is just an id, if not an array $this->assertNotNull($object, "Parsing of json result must not be null"); - $this->assertNotEquals(500, (empty($object['error']['code']) ? 0 : $object['error']['code']), (string) $object['error']['message']); + $this->assertNotEquals(500, ((is_scalar($object) || empty($object['error']['code'])) ? 0 : $object['error']['code']), (string) $object['error']['message']); $this->assertEquals('200', $object['success']['code']); $this->api_key = $object['success']['token']; @@ -238,7 +238,7 @@ class RestAPIUserTest extends PHPUnit\Framework\TestCase $object = json_decode($result['content'], true); // If success content is just an id, if not an array $this->assertNotNull($object, "Parsing of json result must no be null"); - $this->assertNotEquals(500, ((empty($object['error']) || empty($object['error']['code'])) ? 0 : $object['error']['code']), (string) $object['error']['message']); + $this->assertNotEquals(500, ((is_scalar($object) || empty($object['error']) || empty($object['error']['code'])) ? 0 : $object['error']['code']), (string) $object['error']['message']); $this->assertGreaterThan(0, $object, 'ID returned is no > 0'); // attempt to create duplicated user @@ -249,6 +249,6 @@ class RestAPIUserTest extends PHPUnit\Framework\TestCase $this->assertEquals($result['curl_error_no'], ''); $object=json_decode($result['content'], true); $this->assertNotNull($object, "Parsing of json result must no be null"); - $this->assertEquals(500, ((empty($object['error']) || empty($object['error']['code'])) ? 0 : $object['error']['code']), (string) $object['error']['message']); + $this->assertEquals(500, ((is_scalar($object) || empty($object['error']) || empty($object['error']['code'])) ? 0 : $object['error']['code']), (string) $object['error']['message']); } }