Skip to content

Commit b60bb6f

Browse files
committed
Added an assertion for a 200 status to provide better error messages
1 parent fc36fe4 commit b60bb6f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Functional/BaseTestCase.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace Symfony\Cmf\Component\Testing\Functional;
1414

1515
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
16+
use Symfony\Component\HttpFoundation\Response;
1617
use Symfony\Component\DependencyInjection\Container;
1718

1819
/**
@@ -121,4 +122,21 @@ protected static function createKernel(array $options = array())
121122

122123
return parent::createKernel($options);
123124
}
125+
126+
protected function assertResponseSuccess(Response $response)
127+
{
128+
libxml_use_internal_errors(true);
129+
130+
$dom = new \DomDocument();
131+
$dom->loadHTML($response->getContent());
132+
133+
$xpath = new \DOMXpath($dom);
134+
$result = $xpath->query('//div[contains(@class,"text-exception")]/h1');
135+
$exception = null;
136+
if ($result->length) {
137+
$exception = $result->item(0)->nodeValue;
138+
}
139+
140+
$this->assertEquals(200, $response->getStatusCode(), $exception ? 'Exception: "'.$exception.'"' : null);
141+
}
124142
}

0 commit comments

Comments
 (0)