Skip to content

Commit

Permalink
Allowing 'sitemap' option to be either true or false or array (#107)
Browse files Browse the repository at this point in the history
* Allowing 'sitemap' option to be either true or false or array

* Fixed unit tests

* Fixed phpunit tests
  • Loading branch information
Yann Eugoné committed Jun 7, 2016
1 parent d7eb095 commit ea93373
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
19 changes: 17 additions & 2 deletions EventListener/RouteAnnotationEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,23 @@ public function getOptions($name, Route $route)
}
}

if (!filter_var($option, FILTER_VALIDATE_BOOLEAN) && !is_array($option)) {
throw new \InvalidArgumentException('the sitemap option must be "true" or an array of parameters');
if (!is_array($option) && !is_bool($option)) {
$bool = filter_var($option, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);

if (null === $bool) {
throw new \InvalidArgumentException(
sprintf(
'The sitemap option must be of type "boolean" or "array", got "%s"',
$option
)
);
}

$option = $bool;
}

if (!$option) {
return null;
}

$options = $this->defaults;
Expand Down
13 changes: 6 additions & 7 deletions Tests/EventListener/RouteAnnotationEventListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,20 @@ public function testNoAnnotation()
}

/**
* test "sitemap"=false annotation
* test "sitemap"="anything" annotation
*/
public function testInvalidSitemapFalse()
public function testInvalidSitemapArbitrary()
{
$this->setExpectedException('InvalidArgumentException');
$this->assertEquals(-1, $this->getListener()->getOptions('route1', $this->getRoute(false)), 'sitemap = false throws an exception');
$this->assertEquals(-1, $this->getListener()->getOptions('route1', $this->getRoute('anything')), 'sitemap = "anything" throws an exception');
}

/**
* test "sitemap"="anything" annotation
* test "sitemap"=false annotation
*/
public function testInvalidSitemapArbitrary()
public function testSitemapFalse()
{
$this->setExpectedException('InvalidArgumentException');
$this->assertEquals(-1, $this->getListener()->getOptions('route1', $this->getRoute('anything')), 'sitemap = "anything" throws an exception');
$this->assertNull($this->getListener()->getOptions('route1', $this->getRoute(false)), 'sitemap = false returns null');
}

/**
Expand Down

0 comments on commit ea93373

Please sign in to comment.