Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Resource/AbstractResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
65 changes: 65 additions & 0 deletions test/ZammadAPIClient/GetIDTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace ZammadAPIClient;

use PHPUnit\Framework\TestCase;
use ZammadAPIClient\Resource\AbstractResource;

class GetIDTest extends TestCase
{
private static $client;

public static function setUpBeforeClass(): void
{
self::$client = new Client([
'url' => '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.'
);
}
}