Files
php-uuid/tests/Provider/Node/FallbackNodeProviderTest.php
T
Ben Ramsey 0d7b8c2b7a Update coding style to include PSR-12, among other options
This also includes heavy use of slevomat/coding-standard to apply
various checks to the code, based on maintainer (me) preference.
2020-01-18 12:13:55 -06:00

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);
}
}