[COMPONENT][Attachment][TESTS] Fix Entity/AttachmentThumbnailTest
This commit is contained in:
@@ -28,6 +28,7 @@ use App\Util\Exception\NotFoundException;
|
||||
use App\Util\Formatting;
|
||||
use BadMethodCallException;
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
|
||||
@@ -48,6 +49,8 @@ abstract class Entity
|
||||
throw new BadMethodCallException('Non existent method ' . static::class . "::{$name} called with arguments: " . print_r($arguments, true));
|
||||
}
|
||||
|
||||
abstract public static function schemaDef(): array;
|
||||
|
||||
/**
|
||||
* Create an instance of the called class or fill in the
|
||||
* properties of $obj with the associative array $args. Doesn't
|
||||
@@ -145,6 +148,32 @@ abstract class Entity
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that this object is equal to another one based on a custom object comparison
|
||||
*
|
||||
* @param self $other the value to test
|
||||
*
|
||||
* @return bool true if equals, false otherwise
|
||||
*/
|
||||
public function equals(self $other): bool
|
||||
{
|
||||
foreach (array_keys($this::schemaDef()['fields']) as $attribute) {
|
||||
$getter = 'get' . Formatting::snakeCaseToPascalCase($attribute);
|
||||
$current = $this->{$getter}();
|
||||
$target = $other->{$getter}();
|
||||
if ($current instanceof DateTimeInterface) {
|
||||
if ($current->getTimestamp() !== $target->getTimestamp()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ($current !== $target) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Who should be notified about this object?
|
||||
*
|
||||
|
Reference in New Issue
Block a user