@@ -332,6 +332,41 @@ document::
332
332
// ...or simply check that the response is a redirect to any URL
333
333
$this->assertTrue($client->getResponse()->isRedirect());
334
334
335
+ .. _testing-data-providers :
336
+
337
+ Testing against Different Sets of Data
338
+ --------------------------------------
339
+
340
+ It's common to have to execute the same test against different sets of data to
341
+ check the multiple conditions code must handle. This is solved with PHPUnit's
342
+ `data providers `_, which work both for unit and functional tests.
343
+
344
+ First, add one or more arguments to your test method and use them inside the
345
+ test code. Then, define another method which returns a nested array with the
346
+ arguments to use on each test run. Lastly, add the ``@dataProvider `` annotation
347
+ to associate both methods::
348
+
349
+ /**
350
+ * @dataProvider provideUrls
351
+ */
352
+ public function testPageIsSuccessful($url)
353
+ {
354
+ $client = self::createClient();
355
+ $client->request('GET', $url);
356
+
357
+ $this->assertTrue($client->getResponse()->isSuccessful());
358
+ }
359
+
360
+ public function provideUrls()
361
+ {
362
+ return array(
363
+ array('/'),
364
+ array('/blog'),
365
+ array('/contact'),
366
+ // ...
367
+ );
368
+ }
369
+
335
370
.. index ::
336
371
single: Tests; Client
337
372
@@ -993,3 +1028,4 @@ Learn more
993
1028
.. _`documentation` : https://phpunit.de/manual/current/en/
994
1029
.. _`PHPUnit Bridge component` : https://symfony.com/components/PHPUnit%20Bridge
995
1030
.. _`$_SERVER` : https://php.net/manual/en/reserved.variables.server.php
1031
+ .. _`data providers` : https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.data-providers
0 commit comments