Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavier Coureau committed Aug 5, 2014
1 parent 5ec1bd2 commit b08c2f1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
8 changes: 4 additions & 4 deletions Event/Subscriber/WordpressResponseSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
class WordpressResponseSubscriber implements EventSubscriberInterface
{
/**
* @var string
* @var string|array
*/
protected $httpHeaderCallback;

/**
* @param string $httpHeaderCallback
* @param string|array $httpHeaderCallback
*/
public function __construct($httpHeaderCallback = 'wp_get_http_headers')
public function __construct($httpHeaderCallback)
{
$this->httpHeaderCallback = $httpHeaderCallback;
}
Expand Down Expand Up @@ -55,7 +55,7 @@ public function onKernelResponse(FilterResponseEvent $event)
}

if ($wp_query->is_404()) {
$response->setStatusCode(WordpressResponse::HTTP_NOT_FOUND);
$response->setStatusCode(404);
}
}

Expand Down
2 changes: 2 additions & 0 deletions Resources/config/hooks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

<service id="ekino.wordpress.response_subscriber" class="%ekino.wordpress.response_subscriber.class%">
<tag name="kernel.event_subscriber" />

<argument>wp_get_http_headers</argument>
</service>

</services>
Expand Down
2 changes: 2 additions & 0 deletions Tests/Controller/WordpressControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
class WordpressControllerTest extends \PHPUnit_Framework_TestCase
{
protected $wp_query;

/**
* @var \Ekino\WordpressBundle\Wordpress\Wordpress
*/
Expand Down
27 changes: 10 additions & 17 deletions Tests/Event/Subscriber/WordpressResponseSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function setUp()
$this->response = $this->getMockBuilder('Ekino\WordpressBundle\Wordpress\WordpressResponse')->disableOriginalConstructor()->getMock();
$this->request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->disableOriginalConstructor()->getMock();

$this->subscriber = new WordpressResponseSubscriber();
$this->subscriber = new WordpressResponseSubscriber(array($this, 'getHeadersMock'));
}

public function testGetSubscribedEvents()
Expand All @@ -37,7 +37,7 @@ public function testGetSubscribedEvents()

public function testGetHttpHeadersCallback()
{
$this->assertEquals('wp_get_http_headers', $this->subscriber->getHttpHeadersCallback());
$this->assertEquals(array($this, 'getHeadersMock'), $this->subscriber->getHttpHeadersCallback());
}

public function testOnKernelResponseNoWordpressResponse()
Expand Down Expand Up @@ -87,8 +87,6 @@ public function testOnKernelResponseNoWpQuery()

public function testOnKernelResponseNo404()
{
$subscriber = new WordpressResponseSubscriberMock();

$this->event->expects($this->once())
->method('getRequest')
->will($this->returnValue($this->request));
Expand All @@ -107,13 +105,11 @@ public function testOnKernelResponseNo404()
->method('getUri')
->will($this->returnValue('http://wwww.test.com/random-test'));

$subscriber->onKernelResponse($this->event);
$this->subscriber->onKernelResponse($this->event);
}

public function testOnKernelResponse()
{
$subscriber = new WordpressResponseSubscriberMock();

$this->event->expects($this->once())
->method('getRequest')
->will($this->returnValue($this->request));
Expand All @@ -135,18 +131,15 @@ public function testOnKernelResponse()
->method('setStatusCode')
->with($this->equalTo(404));

$subscriber->onKernelResponse($this->event);
}
}

final class WordpressResponseSubscriberMock extends WordpressResponseSubscriber
{
public function getHttpHeadersCallback()
{
return array($this, 'getHeaders');
$this->subscriber->onKernelResponse($this->event);
}

public function getHeaders($uri)
/**
* @param string $uri
*
* @return array
*/
public function getHeadersMock($uri)
{
return array();
}
Expand Down

0 comments on commit b08c2f1

Please sign in to comment.