Skip to content

Commit 5e63315

Browse files
committed
Merge pull request #100 from symfony-cmf/improve_functional_test_errors
Added an assertion for a 200 status to provide better error messages
2 parents fc36fe4 + ecd3cc2 commit 5e63315

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ matrix:
3232
- php: 5.6
3333
env: SYMFONY_VERSION=3.0.*
3434

35-
before_script:
36-
- composer self-update
35+
before_install:
36+
- composer self-update || true
37+
38+
install:
3739
- composer require symfony/symfony:${SYMFONY_VERSION} --no-update
3840
- composer update --prefer-source $COMPOSER_FLAGS
3941

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)