Completed
Push — fix/scrutinizer-config ( 160cd0 )
by Guillem
02:50
created

itShouldBuildAnApiServiceFromCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 18
rs 9.8666
c 0
b 0
f 0
1
<?php
2
namespace ElevenLabs\Api\Service;
3
4
use ElevenLabs\Api\Schema;
5
use PHPUnit\Framework\TestCase;
6
use Psr\Cache\CacheItemInterface;
7
use Psr\Cache\CacheItemPoolInterface;
8
9
class ApiServiceBuilderTest extends TestCase
10
{
11
    /** @test */
12
    public function itShouldBuildAnApiService()
13
    {
14
        $schemaFixture = __DIR__.'/fixtures/httpbin.yml';
15
        $apiService = ApiServiceBuilder::create()->build('file://'.$schemaFixture);
16
17
        assertThat($apiService, isInstanceOf(ApiService::class));
18
    }
19
20
    /** @test */
21
    public function itShouldBuildAnApiServiceFromCache()
22
    {
23
        $schemaFile = 'file://fake-schema.yml';
24
25
        $schema = $this->prophesize(Schema::class);
26
        $schema->getSchemes()->willReturn(['https']);
27
        $schema->getHost()->willReturn('domain.tld');
28
29
        $item = $this->prophesize(CacheItemInterface::class);
30
        $item->isHit()->shouldBeCalled()->willReturn(true);
31
        $item->get()->shouldBeCalled()->willReturn($schema);
32
33
        $cache = $this->prophesize(CacheItemPoolInterface::class);
34
        $cache->getItem('3f470a326a5926a2e323aaadd767c0e64302a080')->willReturn($item);
35
36
        ApiServiceBuilder::create()
37
            ->withCacheProvider($cache->reveal())
38
            ->build($schemaFile);
39
    }
40
}
41