eleven-labs /
api-service
| 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
|
|||||||
| 35 | $this->uriFactory = $this->prophesize(UriFactory::class); |
||||||
|
0 ignored issues
–
show
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); |
||||||
| 37 | $this->httpClient = $this->prophesize(HttpClient::class); |
||||||
|
0 ignored issues
–
show
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); |
||||||
| 39 | $this->messageValidator = $this->prophesize(MessageValidator::class); |
||||||
|
0 ignored issues
–
show
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
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
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
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
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
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(), |
||||||
| 101 | $this->httpClient->reveal(), |
||||||
|
0 ignored issues
–
show
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
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(), |
||||||
| 103 | $this->schema->reveal(), |
||||||
|
0 ignored issues
–
show
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
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
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
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
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
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 |
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..