1
|
|
|
<?php |
2
|
|
|
namespace ElevenLabs\Api\Factory; |
3
|
|
|
|
4
|
|
|
use ElevenLabs\Api\Schema; |
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Prophecy\Argument; |
7
|
|
|
use Psr\Cache\CacheItemInterface; |
8
|
|
|
use Psr\Cache\CacheItemPoolInterface; |
9
|
|
|
|
10
|
|
|
class CachedSchemaFactoryDecoratorTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** @test */ |
13
|
|
|
public function itShouldSaveASchemaInACacheStore() |
14
|
|
|
{ |
15
|
|
|
$schemaFile = 'file://fake-schema.yml'; |
16
|
|
|
$schema = $this->prophesize(Schema::class); |
17
|
|
|
|
18
|
|
|
$item = $this->prophesize(CacheItemInterface::class); |
19
|
|
|
$item->isHit()->shouldBeCalled()->willReturn(false); |
20
|
|
|
$item->set($schema)->shouldBeCalled()->willReturn($item); |
21
|
|
|
|
22
|
|
|
$cache = $this->prophesize(CacheItemPoolInterface::class); |
23
|
|
|
$cache->getItem('3f470a326a5926a2e323aaadd767c0e64302a080')->willReturn($item); |
24
|
|
|
$cache->save($item)->willReturn(true); |
25
|
|
|
|
26
|
|
|
$schemaFactory = $this->prophesize(SchemaFactory::class); |
27
|
|
|
$schemaFactory->createSchema($schemaFile)->willReturn($schema); |
28
|
|
|
|
29
|
|
|
$cachedSchema = new CachedSchemaFactoryDecorator( |
30
|
|
|
$cache->reveal(), |
31
|
|
|
$schemaFactory->reveal() |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
$expectedSchema = $schema->reveal(); |
35
|
|
|
$actualSchema = $cachedSchema->createSchema($schemaFile); |
36
|
|
|
|
37
|
|
|
assertThat($actualSchema, isInstanceOf(Schema::class)); |
38
|
|
|
assertThat($actualSchema, equalTo($expectedSchema)); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** @test */ |
42
|
|
|
public function itShouldLoadASchemaFromACacheStore() |
43
|
|
|
{ |
44
|
|
|
$schemaFile = 'file://fake-schema.yml'; |
45
|
|
|
$schema = $this->prophesize(Schema::class); |
46
|
|
|
|
47
|
|
|
$item = $this->prophesize(CacheItemInterface::class); |
48
|
|
|
$item->isHit()->shouldBeCalled()->willReturn(true); |
49
|
|
|
$item->get()->shouldBeCalled()->willReturn($schema); |
50
|
|
|
|
51
|
|
|
$cache = $this->prophesize(CacheItemPoolInterface::class); |
52
|
|
|
$cache->getItem('3f470a326a5926a2e323aaadd767c0e64302a080')->willReturn($item); |
53
|
|
|
|
54
|
|
|
$schemaFactory = $this->prophesize(SchemaFactory::class); |
55
|
|
|
$schemaFactory->createSchema(Argument::any())->shouldNotBeCalled(); |
56
|
|
|
|
57
|
|
|
$cachedSchema = new CachedSchemaFactoryDecorator( |
58
|
|
|
$cache->reveal(), |
59
|
|
|
$schemaFactory->reveal() |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$expectedSchema = $schema->reveal(); |
63
|
|
|
$actualSchema = $cachedSchema->createSchema($schemaFile); |
64
|
|
|
|
65
|
|
|
assertThat($actualSchema, isInstanceOf(Schema::class)); |
66
|
|
|
assertThat($actualSchema, equalTo($expectedSchema)); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|