Skip to content

Commit

Permalink
Ensure we use streams when mocking guzzle responses
Browse files Browse the repository at this point in the history
  • Loading branch information
duncan3dc committed Nov 18, 2024
1 parent c43130e commit bdfaa80
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
3 changes: 2 additions & 1 deletion tests/Providers/AbstractProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use duncan3dc\Speaker\Exceptions\ProviderException;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Utils;
use Mockery;
use Mockery\MockInterface;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -55,7 +56,7 @@ public function testSendRequest(): void
{
$response = Mockery::mock(ResponseInterface::class);
$response->shouldReceive("getStatusCode")->once()->andReturn("200");
$response->shouldReceive("getBody")->once()->andReturn("mp3");
$response->shouldReceive("getBody")->once()->andReturn(Utils::streamFor("mp3"));

$this->client->shouldReceive("request")
->once()
Expand Down
7 changes: 4 additions & 3 deletions tests/Providers/AcapelaProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use duncan3dc\Speaker\Exceptions\InvalidArgumentException;
use duncan3dc\Speaker\Providers\AcapelaProvider;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Utils;
use Mockery;
use Mockery\MockInterface;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -37,7 +38,7 @@ public function testTextToSpeech(): void
{
$response = Mockery::mock(ResponseInterface::class);
$response->shouldReceive("getStatusCode")->once()->andReturn("200");
$response->shouldReceive("getBody")->once()->andReturn("mp3");
$response->shouldReceive("getBody")->once()->andReturn(Utils::streamFor("mp3"));

$this->client->shouldReceive("request")
->once()
Expand All @@ -58,7 +59,7 @@ public function testWithVoice(): void

$response = Mockery::mock(ResponseInterface::class);
$response->shouldReceive("getStatusCode")->once()->andReturn("200");
$response->shouldReceive("getBody")->once()->andReturn("mp3");
$response->shouldReceive("getBody")->once()->andReturn(Utils::streamFor("mp3"));

$this->client->shouldReceive("request")
->once()
Expand Down Expand Up @@ -87,7 +88,7 @@ public function testWithSpeed(): void

$response = Mockery::mock(ResponseInterface::class);
$response->shouldReceive("getStatusCode")->once()->andReturn("200");
$response->shouldReceive("getBody")->once()->andReturn("mp3");
$response->shouldReceive("getBody")->once()->andReturn(Utils::streamFor("mp3"));

$this->client->shouldReceive("request")
->once()
Expand Down
5 changes: 3 additions & 2 deletions tests/Providers/GoogleProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use duncan3dc\Speaker\Exceptions\InvalidArgumentException;
use duncan3dc\Speaker\Providers\GoogleProvider;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Utils;
use Mockery;
use Mockery\MockInterface;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -37,7 +38,7 @@ public function testTextToSpeech(): void
{
$response = Mockery::mock(ResponseInterface::class);
$response->shouldReceive("getStatusCode")->once()->andReturn("200");
$response->shouldReceive("getBody")->once()->andReturn("mp3");
$response->shouldReceive("getBody")->once()->andReturn(Utils::streamFor("mp3"));

$this->client->shouldReceive("request")
->once()
Expand All @@ -58,7 +59,7 @@ public function testWithLanguage(): void

$response = Mockery::mock(ResponseInterface::class);
$response->shouldReceive("getStatusCode")->once()->andReturn("200");
$response->shouldReceive("getBody")->once()->andReturn("mp3");
$response->shouldReceive("getBody")->once()->andReturn(Utils::streamFor("mp3"));

$this->client->shouldReceive("request")
->once()
Expand Down
3 changes: 2 additions & 1 deletion tests/Providers/ResponsiveVoiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use duncan3dc\Speaker\Exceptions\InvalidArgumentException;
use duncan3dc\Speaker\Providers\ResponsiveVoiceProvider;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Utils;
use Mockery;
use Mockery\MockInterface;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -37,7 +38,7 @@ public function testTextToSpeech(): void
{
$response = Mockery::mock(ResponseInterface::class);
$response->shouldReceive("getStatusCode")->once()->andReturn("200");
$response->shouldReceive("getBody")->once()->andReturn("mp3");
$response->shouldReceive("getBody")->once()->andReturn(Utils::streamFor("mp3"));

$this->client->shouldReceive("request")
->once()
Expand Down
9 changes: 5 additions & 4 deletions tests/Providers/VoiceRssProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use duncan3dc\Speaker\Exceptions\ProviderException;
use duncan3dc\Speaker\Providers\VoiceRssProvider;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Utils;
use Mockery;
use Mockery\MockInterface;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -38,7 +39,7 @@ public function testTextToSpeech(): void
{
$response = Mockery::mock(ResponseInterface::class);
$response->shouldReceive("getStatusCode")->once()->andReturn("200");
$response->shouldReceive("getBody")->once()->andReturn("mp3");
$response->shouldReceive("getBody")->once()->andReturn(Utils::streamFor("mp3"));

$this->client->shouldReceive("request")
->once()
Expand All @@ -53,7 +54,7 @@ public function testTextToSpeechFailure(): void
{
$response = Mockery::mock(ResponseInterface::class);
$response->shouldReceive("getStatusCode")->once()->andReturn("200");
$response->shouldReceive("getBody")->once()->andReturn("ERROR: Test Message");
$response->shouldReceive("getBody")->once()->andReturn(Utils::streamFor("ERROR: Test Message"));

$this->client->shouldReceive("request")
->once()
Expand All @@ -76,7 +77,7 @@ public function testWithLanguage(): void

$response = Mockery::mock(ResponseInterface::class);
$response->shouldReceive("getStatusCode")->once()->andReturn("200");
$response->shouldReceive("getBody")->once()->andReturn("mp3");
$response->shouldReceive("getBody")->once()->andReturn(Utils::streamFor("mp3"));

$this->client->shouldReceive("request")
->once()
Expand Down Expand Up @@ -105,7 +106,7 @@ public function testWithSpeed(): void

$response = Mockery::mock(ResponseInterface::class);
$response->shouldReceive("getStatusCode")->once()->andReturn("200");
$response->shouldReceive("getBody")->once()->andReturn("mp3");
$response->shouldReceive("getBody")->once()->andReturn(Utils::streamFor("mp3"));

$this->client->shouldReceive("request")
->once()
Expand Down

0 comments on commit bdfaa80

Please sign in to comment.