Skip to content

Commit

Permalink
Merge pull request #766 from odolbeau/avoid-array-to-string-conversion
Browse files Browse the repository at this point in the history
Avoid "array to string conversion" error
  • Loading branch information
willdurand committed Dec 11, 2015
2 parents 19d4e37 + d3bc49c commit 93b189b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Annotation/ApiDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,10 @@ public function setRoute(Route $route)
$this->host = $route->getHost() ? : null;

//replace route placeholders
foreach ($route->getDefaults() as $key => $value) {
$this->host = str_replace('{' . $key . '}', $value, $this->host);
foreach ($route->getDefaults() as $key => $value) {
if (is_string($value)) {
$this->host = str_replace('{' . $key . '}', $value, $this->host);
}
}
} else {
$this->host = null;
Expand Down
25 changes: 25 additions & 0 deletions Tests/Annotation/ApiDocTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Nelmio\ApiDocBundle\Tests\TestCase;
use Symfony\Component\Routing\Route;

class ApiDocTest extends TestCase
{
Expand Down Expand Up @@ -373,4 +374,28 @@ public function testAlignmentOfOutputAndResponseModels2()
$this->assertArrayHasKey(400, $map);
$this->assertEquals($apiDoc->getOutput(), $map[200]);
}

public function testSetRoute()
{
$route = new Route(
'/path/{foo}',
[
'foo' => 'bar',
'nested' => [
'key1' => 'value1',
'key2' => 'value2',
]
],
[],
[],
'{foo}.awesome_host.com'
);

$apiDoc = new ApiDoc([]);
$apiDoc->setRoute($route);

$this->assertSame($route, $apiDoc->getRoute());
$this->assertEquals('bar.awesome_host.com', $apiDoc->getHost());
$this->assertEquals('ANY', $apiDoc->getMethod());
}
}

0 comments on commit 93b189b

Please sign in to comment.