Sono venuto a questo post cercando qualcosa di simile. Ho questo TestCase:
/**
* test routing logic (numbers method returns an array of numbers and expected outputs to test)
* @dataProvider numbers
*/
function testRoute($input,$expected)
{
$route = new Route($input,'',false);
$route->route();
$this->assertEquals($expected,$route->routingResult);
}
e il mio metodo di numeri è questo:
/**
* read pairs of numbers (input <tab> expected) from tests.input separater by tab
* return an array like this: array(array(number1,expected1), array(number2,expected2), ...)
* provide this array to my tests by returning it
*/
function numbers()
{
$testcases = file('tests.input');
$tests = array();
foreach($testcases as $test_case)
{
list($input,$output) = explode("\t",$test_case,2);
$tests[] = array(trim($input),trim($output));
}
return $tests;
}
Ciò che accade è che si ottiene un output come questo da phpunit:
Starting test 'RouteTest::testRoute with data set #0 ('8596000000', 'rejected (dp not found)x')'.
F
Starting test 'RouteTest::testRoute with data set #1 ('8596000001', 'rejected (rejected by scheme)')'.
.
Starting test 'RouteTest::testRoute with data set #2 ('8596000003', '1599000003')'.
.
Non sarà indica il risultato effettivo della funzione testata a meno che il test non abbia esito positivo, ma almeno riesci a visualizzare tutti i valori asseriti.
L'ovvia domanda ... perché? –
Questa è una richiesta insolita. La maggior parte delle persone non vorrebbe farlo. Per questo motivo, nulla di simile sarebbe implementato da PHPUnit. Dovresti farlo da solo. – ryeguy
Domanda non correlata, ma perché ne hai bisogno? "normalmente", non si dovrebbe produrre output durante i test, perché lo scopo è quello di essere eseguito automaticamente (un essere umano non dovrebbe leggere l'output se tutto è andato bene) –