我有一个简单的" phpunit.xml"
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="autoload.php">
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
</php>
<testsuites>
<testsuite name="SignIn Test Suite">
<file>../vendor/item/signin-api-bundle/Tests/Controller/SignInControllerTest.php</file>
</testsuite>
</testsuites>
</phpunit>
我的测试:
class ControllerTest extends WebTestCase
{
/**
* @dataProvider provideLoginMissing
*/
public function testLoginMissing($requestData)
{
$client = static::createClient();
$client->request('POST', '/login', array(), array(), array(), json_encode($requestData));
static::assertContains('417', (string)$client->getResponse()->getStatusCode());
}
public function provideLoginMissing() {
return [
'testLoginAndUsernameMissing' => array(
array(
'requestData' => array(
'loginData' => array(
'password' => 'TopSecret',
)
)
)
),
'testLoginAndPasswordMissing' => array(
array(
'requestData' => array(
'loginData' => array(
'username' => 'Simon',
)
)
)
)
];
}
}
,结果是
PHPUnit 5.6.8 by Sebastian Bergmann and contributors.
Failed asserting that '200' contains "417".
....\Controller.php:45
Time: 3.28 seconds, Memory: 8.50MB
FAILURES!
Tests: 2, Assertions: 2, Failures: 1.
Remaining deprecation notices (440)
Process finished with exit code 1
没有数据提供者无效的信息(testLoginAndUsernameMissing或testLoginAndPasswordMissing)。 这个列表将来会更长,所以我不认为我可以使用dataproviders。它在旧系统(Symfony 2.8,PHPUnit 5.6)上,但我希望我能解决这个问题。这里需要某种额外的配置吗?
谢谢你&amp;最诚挚的问候