diff --git a/src/Resource/AbstractResource.php b/src/Resource/AbstractResource.php index 8a36b40..c3fd35c 100644 --- a/src/Resource/AbstractResource.php +++ b/src/Resource/AbstractResource.php @@ -173,7 +173,7 @@ public function clearUnsavedValues() * Gets the ID of the object. * This is a convenience method for getValue('id') * - * @return string ID of this object, if available. + * @return string|null ID of this object as string, or null if not available. */ public function getID() { diff --git a/test/ZammadAPIClient/GetIDTest.php b/test/ZammadAPIClient/GetIDTest.php new file mode 100644 index 0000000..75db368 --- /dev/null +++ b/test/ZammadAPIClient/GetIDTest.php @@ -0,0 +1,65 @@ + 'http://localhost:3000/', + 'username' => 'test@example.com', + 'password' => 'test', + ]); + } + + public static function getClient() + { + return self::$client; + } + + public function testGetIDBeforeSave() + { + $object = self::getClient()->resource( ResourceType::TICKET ); + + $this->assertNull( + $object->getID(), + 'getID() must return null for unsaved object.' + ); + } + + public function testGetIDReturnsString() + { + $object = self::getClient()->resource( ResourceType::TICKET ); + $object->setValue('id', 123); + + $id = $object->getID(); + + $this->assertIsString( + $id, + 'getID() must return a string.' + ); + + $this->assertSame( + '123', + $id, + 'getID() must cast integer to string.' + ); + } + + public function testGetIDReturnsNullWhenIdNotSet() + { + $object = self::getClient()->resource( ResourceType::TICKET ); + $object->setValue('title', 'test'); + + $this->assertNull( + $object->getID(), + 'getID() must return null when id is not set.' + ); + } +}