ldc-arcadia-genesis-php-client/tests/Unit/Auth/NonceTest.php

212 lines
5.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Auth;
use Ramsey\Uuid\Converter\NumberConverterInterface;
use Ramsey\Uuid\Fields\FieldsInterface;
use Ramsey\Uuid\Type\Hexadecimal;
use Ramsey\Uuid\Type\Integer;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Uwil\ArcadiaApiPhpClient\Auth\Nonce;
describe('Nonce Test', function () {
it('can instanciate a valid nonce', function () {
// GIVEN
$value = Uuid::uuid7();
// WHEN
$nonce = new Nonce($value);
// THEN
expect($nonce->value)->toBe($value);
});
});
describe('Nonce validation rules', function () {
it('throw and error with an invalid uuid', function () {
// GIVEN
$value = new class () implements UuidInterface
{
#[\Override]
public function toString(): string
{
return 'invalid-uuid';
}
#[\Override]
public function compareTo(UuidInterface $other): int
{
throw new \Exception('Not implemented');
}
#[\Override]
public function equals(?object $other): bool
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getBytes(): string
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getFields(): FieldsInterface
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getHex(): Hexadecimal
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getInteger(): Integer
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getUrn(): string
{
throw new \Exception('Not implemented');
}
#[\Override]
public function __toString(): string
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getNumberConverter(): NumberConverterInterface
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getFieldsHex(): array
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getClockSeqHiAndReservedHex(): string
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getClockSeqLowHex(): string
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getClockSequenceHex(): string
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getDateTime(): \DateTimeInterface
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getLeastSignificantBitsHex(): string
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getMostSignificantBitsHex(): string
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getNodeHex(): string
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getTimeHiAndVersionHex(): string
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getTimeLowHex(): string
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getTimeMidHex(): string
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getTimestampHex(): string
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getVariant(): ?int
{
throw new \Exception('Not implemented');
}
#[\Override]
public function getVersion(): ?int
{
throw new \Exception('Not implemented');
}
#[\Override]
public function jsonSerialize(): mixed
{
throw new \Exception('Not implemented');
}
#[\Override]
public function serialize()
{
throw new \Exception('Not implemented');
}
public function __serialize()
{
throw new \Exception('Not implemented');
}
#[\Override]
public function unserialize(string $data)
{
throw new \Exception('Not implemented');
}
public function __unserialize(array $data)
{
throw new \Exception('Not implemented');
}
};
// WHEN
expect(function () use ($value) {
new Nonce($value);
// THEN
})->toThrow(\InvalidArgumentException::class);
});
});