mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
0d7b8c2b7a
This also includes heavy use of slevomat/coding-standard to apply various checks to the code, based on maintainer (me) preference.
60 lines
2.2 KiB
PHP
60 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Ramsey\Uuid\Test\Provider\Node;
|
|
|
|
use Ramsey\Uuid\Provider\Node\FallbackNodeProvider;
|
|
use Ramsey\Uuid\Provider\NodeProviderInterface;
|
|
use Ramsey\Uuid\Test\TestCase;
|
|
|
|
class FallbackNodeProviderTest extends TestCase
|
|
{
|
|
public function testGetNodeCallsGetNodeOnEachProviderUntilNodeFound(): void
|
|
{
|
|
$providerWithNode = $this->getMockBuilder(NodeProviderInterface::class)->getMock();
|
|
$providerWithNode->expects($this->once())
|
|
->method('getNode')
|
|
->willReturn('57764a07f756');
|
|
$providerWithoutNode = $this->getMockBuilder(NodeProviderInterface::class)->getMock();
|
|
$providerWithoutNode->expects($this->once())
|
|
->method('getNode')
|
|
->willReturn(null);
|
|
|
|
$provider = new FallbackNodeProvider([$providerWithoutNode, $providerWithNode]);
|
|
$provider->getNode();
|
|
}
|
|
|
|
public function testGetNodeReturnsNodeFromFirstProviderWithNode(): void
|
|
{
|
|
$providerWithoutNode = $this->getMockBuilder(NodeProviderInterface::class)->getMock();
|
|
$providerWithoutNode->expects($this->once())
|
|
->method('getNode')
|
|
->willReturn(null);
|
|
$providerWithNode = $this->getMockBuilder(NodeProviderInterface::class)->getMock();
|
|
$providerWithNode->expects($this->once())
|
|
->method('getNode')
|
|
->willReturn('57764a07f756');
|
|
$anotherProviderWithoutNode = $this->getMockBuilder(NodeProviderInterface::class)->getMock();
|
|
$anotherProviderWithoutNode->expects($this->never())
|
|
->method('getNode');
|
|
|
|
$provider = new FallbackNodeProvider([$providerWithoutNode, $providerWithNode, $anotherProviderWithoutNode]);
|
|
$node = $provider->getNode();
|
|
|
|
$this->assertEquals('57764a07f756', $node);
|
|
}
|
|
|
|
public function testGetNodeReturnsNullWhenNoNodesFound(): void
|
|
{
|
|
$providerWithoutNode = $this->getMockBuilder(NodeProviderInterface::class)->getMock();
|
|
$providerWithoutNode->method('getNode')
|
|
->willReturn(null);
|
|
|
|
$provider = new FallbackNodeProvider([$providerWithoutNode]);
|
|
$node = $provider->getNode();
|
|
|
|
$this->assertNull($node);
|
|
}
|
|
}
|