ApiServiceTest::itShouldCheckApiSchemaSchemes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
namespace ElevenLabs\Api\Service;
3
4
use ElevenLabs\Api\Schema;
5
use ElevenLabs\Api\Validator\MessageValidator;
6
use Http\Client\HttpClient;
7
use Http\Message\MessageFactory;
8
use Http\Message\UriFactory;
9
use PHPUnit\Framework\TestCase;
10
use Rize\UriTemplate;
11
use Symfony\Component\Serializer\SerializerInterface;
12
13
class ApiServiceTest extends TestCase
14
{
15
    /** @var Schema */
16
    private $schema;
17
    /** @var UriFactory */
18
    private $uriFactory;
19
    /** @var UriTemplate */
20
    private $uriTemplate;
21
    /** @var HttpClient */
22
    private $httpClient;
23
    /** @var MessageFactory */
24
    private $messageFactory;
25
    /** @var MessageValidator */
26
    private $messageValidator;
27
    /** @var SerializerInterface */
28
    private $serializer;
29
    /** @var array */
30
    private $config;
31
32
    public function setUp()
33
    {
34
        $this->schema = $this->prophesize(Schema::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->prophesize(ElevenLabs\Api\Schema::class) of type Prophecy\Prophecy\ObjectProphecy is incompatible with the declared type ElevenLabs\Api\Schema of property $schema.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
35
        $this->uriFactory = $this->prophesize(UriFactory::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->prophesize(Http\Message\UriFactory::class) of type Prophecy\Prophecy\ObjectProphecy is incompatible with the declared type Http\Message\UriFactory of property $uriFactory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
36
        $this->uriTemplate = $this->prophesize(UriTemplate::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->prophesize(Rize\UriTemplate::class) of type Prophecy\Prophecy\ObjectProphecy is incompatible with the declared type Rize\UriTemplate of property $uriTemplate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
37
        $this->httpClient = $this->prophesize(HttpClient::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->prophesize(Http\Client\HttpClient::class) of type Prophecy\Prophecy\ObjectProphecy is incompatible with the declared type Http\Client\HttpClient of property $httpClient.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
38
        $this->messageFactory = $this->prophesize(MessageFactory::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->prophesize(Http\M...\MessageFactory::class) of type Prophecy\Prophecy\ObjectProphecy is incompatible with the declared type Http\Message\MessageFactory of property $messageFactory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
39
        $this->messageValidator = $this->prophesize(MessageValidator::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->prophesize(Eleven...essageValidator::class) of type Prophecy\Prophecy\ObjectProphecy is incompatible with the declared type ElevenLabs\Api\Validator\MessageValidator of property $messageValidator.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
        $this->serializer = $this->prophesize(SerializerInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->prophesize(Symfon...alizerInterface::class) of type Prophecy\Prophecy\ObjectProphecy is incompatible with the declared type Symfony\Component\Serializer\SerializerInterface of property $serializer.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
41
        $this->config = [];
42
    }
43
44
    /** @test */
45
    public function itShouldCheckApiSchemaSchemes()
46
    {
47
        $this->expectException(\LogicException::class);
48
        $this->expectExceptionMessage('You need to provide at least on scheme in your API Schema');
49
50
        $this->getApiService();
51
    }
52
    /** @test */
53
    public function itCheckTheHostInApiSchema()
54
    {
55
        $this->expectException(\LogicException::class);
56
        $this->expectExceptionMessage('The host in the API Schema should not be null');
57
58
        $this->schema->getSchemes()->willReturn(['https']);
59
        $this->schema->getHost()->willReturn(null);
60
61
        $this->getApiService();
62
    }
63
64
    /** @test */
65
    public function itOnlySupportHttpAndHttps()
66
    {
67
        $this->expectException(\RuntimeException::class);
68
        $this->expectExceptionMessage('Cannot choose a proper scheme from the API Schema. Supported: https, http');
69
70
        $this->schema->getSchemes()->willReturn(['ftp']);
71
        $this->schema->getHost()->willReturn('domain.tld');
72
73
        $this->getApiService();
74
    }
75
76
    /** @test */
77
    public function itShouldPreferHttps()
78
    {
79
        $this->schema->getSchemes()->willReturn(['http', 'https']);
80
        $this->schema->getHost()->willReturn('domain.tld');
81
82
        $this->uriFactory->createUri('https://domain.tld')->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method shouldBeCalled() does not exist on Psr\Http\Message\UriInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

82
        $this->uriFactory->createUri('https://domain.tld')->/** @scrutinizer ignore-call */ shouldBeCalled();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
83
84
        $this->getApiService();
85
    }
86
87
    /** @test */
88
    public function itCreateABaseUriUsingTheOneProvidedInTheConfigArray()
89
    {
90
        $this->config['baseUri'] = 'https://somewhere.tld';
91
        $this->uriFactory->createUri('https://somewhere.tld')->shouldBeCalled();
92
93
        $this->getApiService();
94
    }
95
96
    private function getApiService()
97
    {
98
        return new ApiService(
99
            $this->uriFactory->reveal(),
0 ignored issues
show
Bug introduced by
The method reveal() does not exist on Http\Message\UriFactory. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

99
            $this->uriFactory->/** @scrutinizer ignore-call */ 
100
                               reveal(),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
100
            $this->uriTemplate->reveal(),
0 ignored issues
show
Bug introduced by
The method reveal() does not exist on Rize\UriTemplate. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

100
            $this->uriTemplate->/** @scrutinizer ignore-call */ 
101
                                reveal(),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
101
            $this->httpClient->reveal(),
0 ignored issues
show
Bug introduced by
The method reveal() does not exist on Http\Client\HttpClient. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

101
            $this->httpClient->/** @scrutinizer ignore-call */ 
102
                               reveal(),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
102
            $this->messageFactory->reveal(),
0 ignored issues
show
Bug introduced by
The method reveal() does not exist on Http\Message\MessageFactory. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

102
            $this->messageFactory->/** @scrutinizer ignore-call */ 
103
                                   reveal(),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
103
            $this->schema->reveal(),
0 ignored issues
show
Bug introduced by
The method reveal() does not exist on ElevenLabs\Api\Schema. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

103
            $this->schema->/** @scrutinizer ignore-call */ 
104
                           reveal(),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
104
            $this->messageValidator->reveal(),
0 ignored issues
show
Bug introduced by
The method reveal() does not exist on ElevenLabs\Api\Validator\MessageValidator. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

104
            $this->messageValidator->/** @scrutinizer ignore-call */ 
105
                                     reveal(),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
105
            $this->serializer->reveal(),
0 ignored issues
show
Bug introduced by
The method reveal() does not exist on Symfony\Component\Serializer\SerializerInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
            $this->serializer->/** @scrutinizer ignore-call */ 
106
                               reveal(),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
106
            $this->config
107
        );
108
    }
109
}
110