-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ChainSegmentFactoryTest.php
48 lines (39 loc) · 1.76 KB
/
ChainSegmentFactoryTest.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
<?php
declare(strict_types=1);
namespace Pheature\Test\Core\Toggle\Read;
use Pheature\Core\Toggle\Exception\InvalidSegmentTypeGiven;
use Pheature\Core\Toggle\Read\ChainSegmentFactory;
use Pheature\Core\Toggle\Read\Segment;
use Pheature\Core\Toggle\Read\SegmentFactory;
use PHPUnit\Framework\TestCase;
final class ChainSegmentFactoryTest extends TestCase
{
private const SEGMENT_ID = 'some_segment_id';
private const SEGMENT_TYPE = 'some_segment_type';
private const PAYLOAD = [
'some' => 'data',
];
public function testItShouldThrowAnExceptionWhenItCantCreateAToggleStrategyType(): void
{
$this->expectException(InvalidSegmentTypeGiven::class);
$segmentFactory = $this->createMock(SegmentFactory::class);
$chainSegmentFactory = new ChainSegmentFactory($segmentFactory);
$chainSegmentFactory->create(self::SEGMENT_ID, self::SEGMENT_TYPE, self::PAYLOAD);
}
public function testItShouldBeCreatedWithAtLeastOneSegmentFactoryInstance(): void
{
$segmentFactory = $this->createMock(SegmentFactory::class);
$segmentFactory->expects(self::atLeastOnce())
->method('types')
->willReturn([self::SEGMENT_TYPE]);
$expectedSegment = $this->createMock(Segment::class);
$segmentFactory->expects(self::once())
->method('create')
->with(self::SEGMENT_ID, self::SEGMENT_TYPE, self::PAYLOAD)
->willReturn($expectedSegment);
$chainSegmentFactory = new ChainSegmentFactory($segmentFactory);
$current = $chainSegmentFactory->create(self::SEGMENT_ID, self::SEGMENT_TYPE, self::PAYLOAD);
$this->assertSame($expectedSegment, $current);
$this->assertSame([self::SEGMENT_TYPE], $chainSegmentFactory->types());
}
}