/
FallbackBuilderTest.php
52 lines (42 loc) · 1.58 KB
/
FallbackBuilderTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
namespace Ramsey\Uuid\Test\Builder;
use Mockery;
use Ramsey\Uuid\Builder\FallbackBuilder;
use Ramsey\Uuid\Builder\UuidBuilderInterface;
use Ramsey\Uuid\Codec\CodecInterface;
use Ramsey\Uuid\Exception\BuilderNotFoundException;
use Ramsey\Uuid\Exception\InvalidArgumentException;
use Ramsey\Uuid\Test\TestCase;
class FallbackBuilderTest extends TestCase
{
public function testBuildThrowsExceptionAfterAllConfiguredBuildersHaveErrored(): void
{
$codec = Mockery::mock(CodecInterface::class);
$fields = ['someFields'];
$builder1 = Mockery::mock(UuidBuilderInterface::class);
$builder1
->shouldReceive('build')
->once()
->with($codec, $fields)
->andThrow(InvalidArgumentException::class);
$builder2 = Mockery::mock(UuidBuilderInterface::class);
$builder2
->shouldReceive('build')
->once()
->with($codec, $fields)
->andThrow(InvalidArgumentException::class);
$builder3 = Mockery::mock(UuidBuilderInterface::class);
$builder3
->shouldReceive('build')
->once()
->with($codec, $fields)
->andThrow(InvalidArgumentException::class);
$fallbackBuilder = new FallbackBuilder([$builder1, $builder2, $builder3]);
$this->expectException(BuilderNotFoundException::class);
$this->expectExceptionMessage(
'Could not find a suitable builder for the provided codec and fields'
);
$fallbackBuilder->build($codec, $fields);
}
}