2017-10-08 06:29:08 +02:00
|
|
|
<?php
|
|
|
|
|
2021-01-23 21:09:16 +01:00
|
|
|
namespace Pterodactyl\Tests\Traits;
|
2017-10-08 06:29:08 +02:00
|
|
|
|
|
|
|
use Mockery as m;
|
|
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
use Ramsey\Uuid\UuidFactory;
|
|
|
|
|
2017-10-08 22:29:46 +02:00
|
|
|
trait MocksUuids
|
2017-10-08 06:29:08 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The known UUID string.
|
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
protected string $knownUuid = 'ffb5c3a6-ab17-43ab-97f0-8ff37ccd7f5f';
|
2017-10-08 06:29:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup a factory mock to produce the same UUID whenever called.
|
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
public function setKnownUuidFactory(): void
|
2017-10-08 06:29:08 +02:00
|
|
|
{
|
|
|
|
$uuid = Uuid::fromString($this->getKnownUuid());
|
|
|
|
$factoryMock = m::mock(UuidFactory::class . '[uuid4]', [
|
|
|
|
'uuid4' => $uuid,
|
|
|
|
]);
|
|
|
|
|
|
|
|
Uuid::setFactory($factoryMock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the known UUID for tests to use.
|
|
|
|
*/
|
|
|
|
public function getKnownUuid(): string
|
|
|
|
{
|
|
|
|
return $this->knownUuid;
|
|
|
|
}
|
|
|
|
}
|