Skip to content

Commit

Permalink
test wrap NotFound exception
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-gribanov committed Aug 1, 2017
1 parent b70591a commit ead8f5a
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/Service/BrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use AnimeDb\Bundle\ShikimoriBrowserBundle\Service\Browser;
use AnimeDb\Bundle\ShikimoriBrowserBundle\Service\ErrorDetector;
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Exception\ClientException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;

Expand Down Expand Up @@ -245,6 +246,64 @@ public function methods()
];
}

/**
* @expectedException \AnimeDb\Bundle\ShikimoriBrowserBundle\Exception\NotFoundException
* @dataProvider methods
*
* @param string $method
*/
public function testWrapNotFoundException($method)
{
$path = 'baz';

/* @var $exception \PHPUnit_Framework_MockObject_MockObject|ClientException */
$exception = $this
->getMockBuilder(ClientException::class)
->disableOriginalConstructor()
->getMock()
;
$exception
->expects($this->once())
->method('getResponse')
->will($this->returnValue($this->response))
;

$this->response
->expects($this->once())
->method('getStatusCode')
->will($this->returnValue(404))
;

$this->client
->expects($this->once())
->method('request')
->with($method, $this->host.$this->prefix.$path, [
'headers' => [
'User-Agent' => $this->app_client,
],
])
->will($this->throwException($exception))
;

switch ($method) {
case 'GET':
$this->browser->get($path);
break;
case 'POST':
$this->browser->post($path);
break;
case 'PUT':
$this->browser->put($path);
break;
case 'PATCH':
$this->browser->patch($path);
break;
case 'DELETE':
$this->browser->delete($path);
break;
}
}

/**
* @expectedException \AnimeDb\Bundle\ShikimoriBrowserBundle\Exception\ErrorException
* @dataProvider methods
Expand Down

0 comments on commit ead8f5a

Please sign in to comment.