Skip to content

Commit 67b257e

Browse files
committed
changed PHPUnit assertions to use 'better' assert methods whenever possible
1 parent 6d1b77f commit 67b257e

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

book/testing.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ for its ``DemoController`` (`DemoControllerTest`_) that reads as follows::
144144

145145
$crawler = $client->request('GET', '/demo/hello/Fabien');
146146

147-
$this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
147+
$this->assertGreaterThan(0, $crawler->filter('html:contains("Hello Fabien")')->count());
148148
}
149149
}
150150

@@ -210,7 +210,7 @@ that it actually does what you expect it to. Use the Crawler to make assertions
210210
on the DOM::
211211

212212
// Assert that the response matches a given CSS selector.
213-
$this->assertTrue($crawler->filter('h1')->count() > 0);
213+
$this->assertGreaterThan(0, $crawler->filter('h1')->count());
214214

215215
Or, test against the Response content directly if you just want to assert that
216216
the content contains some text, or if the Response is not an XML/HTML
@@ -258,10 +258,10 @@ document::
258258
useful test assertions::
259259

260260
// Assert that there is more than one h2 tag with the class "subtitle"
261-
$this->assertTrue($crawler->filter('h2.subtitle')->count() > 0);
261+
$this->assertGreaterThan(0, $crawler->filter('h2.subtitle')->count());
262262

263263
// Assert that there are exactly 4 h2 tags on the page
264-
$this->assertEquals(4, $crawler->filter('h2')->count());
264+
$this->assertCount(4, $crawler->filter('h2')->count());
265265

266266
// Assert the the "Content-Type" header is "application/json"
267267
$this->assertTrue($client->getResponse()->headers->contains('Content-Type', 'application/json'));

cookbook/testing/profiling.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ environment)::
2828
// Check that the profiler is enabled
2929
if ($profile = $client->getProfile()) {
3030
// check the number of requests
31-
$this->assertTrue($profile->getCollector('db')->getQueryCount() < 10);
31+
$this->assertLessThan(10, $profile->getCollector('db')->getQueryCount());
3232

3333
// check the time spent in the framework
34-
$this->assertTrue( $profile->getCollector('timer')->getTime() < 0.5);
34+
$this->assertLessThan(0.5, $profile->getCollector('timer')->getTime());
3535
}
3636
}
3737
}
@@ -40,8 +40,9 @@ If a test fails because of profiling data (too many DB queries for instance),
4040
you might want to use the Web Profiler to analyze the request after the tests
4141
finish. It's easy to achieve if you embed the token in the error message::
4242

43-
$this->assertTrue(
44-
$profile->get('db')->getQueryCount() < 30,
43+
$this->assertLessThan(
44+
30,
45+
$profile->get('db')->getQueryCount(),
4546
sprintf('Checks that query count is less than 30 (token %s)', $profile->getToken())
4647
);
4748

0 commit comments

Comments
 (0)