-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from larriereguichet/feature/tests
Feature/tests
- Loading branch information
Showing
6 changed files
with
184 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
tests/SmokerBundle/Response/Handler/ResponseCodeHandlerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
|
||
namespace LAG\SmokerBundle\Tests\Response\Handler; | ||
|
||
use Goutte\Client; | ||
use LAG\SmokerBundle\Exception\Exception; | ||
use LAG\SmokerBundle\Response\Handler\ResponseCodeHandler; | ||
use LAG\SmokerBundle\Response\Handler\ResponseHandlerInterface; | ||
use LAG\SmokerBundle\Tests\BaseTestCase; | ||
use Symfony\Component\BrowserKit\Response; | ||
use Symfony\Component\DomCrawler\Crawler; | ||
|
||
class ResponseCodeHandlerTest extends BaseTestCase | ||
{ | ||
public function testServiceExists() | ||
{ | ||
$this->assertServiceExists(ResponseCodeHandler::class); | ||
$this->assertServiceExists(ResponseHandlerInterface::class); | ||
} | ||
|
||
public function testSupports() | ||
{ | ||
$handler = $this->createResponseHandler([ | ||
'existent_route' => [ | ||
'handlers' => [ | ||
'response_code' => '200', | ||
], | ||
], | ||
'bad_bad_route' => [], | ||
]); | ||
|
||
$this->assertFalse($handler->supports('non_existent_route')); | ||
$this->assertFalse($handler->supports('bad_bad_route')); | ||
$this->assertTrue($handler->supports('existent_route')); | ||
} | ||
|
||
public function testHandle() | ||
{ | ||
$crawler = $this->createMock(Crawler::class); | ||
$goutte = $this->createMock(Client::class); | ||
$goutte | ||
->expects($this->exactly(4)) | ||
->method('getResponse') | ||
->willReturn(new Response()) | ||
; | ||
|
||
$handler = $this->createResponseHandler([ | ||
'existent_route' => [ | ||
'handlers' => [ | ||
'response_code' => '200', | ||
], | ||
], | ||
'existent_route_too' => [ | ||
'handlers' => [ | ||
'response_code' => [ | ||
'code' => '200' | ||
], | ||
], | ||
], | ||
]); | ||
$handler->handle('existent_route', $crawler, $goutte); | ||
$handler->handle('existent_route_too', $crawler, $goutte); | ||
} | ||
|
||
public function testHandleExpecting302() | ||
{ | ||
$crawler = $this->createMock(Crawler::class); | ||
$goutte = $this->createMock(Client::class); | ||
$goutte | ||
->expects($this->exactly(2)) | ||
->method('getResponse') | ||
->willReturn(new Response('', 302)) | ||
; | ||
|
||
$handler = $this->createResponseHandler([ | ||
'existent_route' => [ | ||
'handlers' => [ | ||
'response_code' => '302', | ||
], | ||
] | ||
]); | ||
$handler->handle('existent_route', $crawler, $goutte); | ||
} | ||
|
||
public function testHandleInvalidStatusCode() | ||
{ | ||
$crawler = $this->createMock(Crawler::class); | ||
$goutte = $this->createMock(Client::class); | ||
$goutte | ||
->expects($this->exactly(2)) | ||
->method('getResponse') | ||
->willReturn(new Response('', 302)) | ||
; | ||
|
||
$handler = $this->createResponseHandler([ | ||
'existent_route' => [ | ||
'handlers' => [ | ||
'response_code' => '200', | ||
], | ||
] | ||
]); | ||
$this->assertExceptionRaised(Exception::class, function () use ($handler, $crawler, $goutte) { | ||
$handler->handle('existent_route', $crawler, $goutte); | ||
}); | ||
} | ||
|
||
public function testHandleWithInvalidCrawler() | ||
{ | ||
$crawler = $this->createMock(Crawler::class); | ||
$goutte = $this->createMock(Client::class); | ||
|
||
$handler = $this->createResponseHandler([ | ||
'existent_route' => [ | ||
'handlers' => [ | ||
'response_code' => '200', | ||
], | ||
] | ||
]); | ||
|
||
$this->assertExceptionRaised(Exception::class, function () use ($handler, $crawler, $goutte) { | ||
$handler->handle('existent_route', $crawler, $goutte); | ||
}); | ||
} | ||
|
||
public function testGetName() | ||
{ | ||
$this->assertEquals('response_code', $this->createResponseHandler()->getName()); | ||
} | ||
|
||
private function createResponseHandler(array $routes = []) | ||
{ | ||
$handler = new ResponseCodeHandler($routes); | ||
|
||
return $handler; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/SmokerBundle/Response/Registry/ResponseHandlerRegistryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace LAG\SmokerBundle\Tests\Response\Registry; | ||
|
||
use LAG\SmokerBundle\Exception\Exception; | ||
use LAG\SmokerBundle\Response\Handler\ResponseHandlerInterface; | ||
use LAG\SmokerBundle\Response\Registry\ResponseHandlerRegistry; | ||
use LAG\SmokerBundle\Tests\BaseTestCase; | ||
|
||
class ResponseHandlerRegistryTest extends BaseTestCase | ||
{ | ||
public function testServiceExists() | ||
{ | ||
$this->assertServiceExists(ResponseHandlerRegistry::class); | ||
} | ||
|
||
public function testRegistry() | ||
{ | ||
$handler = $this->createMock(ResponseHandlerInterface::class); | ||
|
||
$registry = new ResponseHandlerRegistry(); | ||
$registry->add('my_handler', $handler); | ||
|
||
$this->assertEquals($handler, $registry->get('my_handler')); | ||
$this->assertTrue($registry->has('my_handler')); | ||
$this->assertFalse($registry->has(('wrong_handler'))); | ||
|
||
$this->assertCount(1, $registry->all()); | ||
$this->assertEquals($handler, $registry->all()['my_handler']); | ||
|
||
$this->assertExceptionRaised(Exception::class, function () use ($registry) { | ||
$registry->get('wrong_handler'); | ||
}); | ||
} | ||
} |