我正在使用PHPUnit和CakePHP来测试自定义查找器,但是每次都跳过测试,我不知道是什么原因
好的,但不完整,跳过或有风险的测试!
测试用例:
class UsersTableTest extends TestCase
{
public $fixtures = [
'app.users',
'app.user_types',
'app.bookings',
'app.stores'
];
public function setUp()
{
parent::setUp();
$this->Users = TableRegistry::get('Users');
}
public function testFindUser(){
$query = $this->Users->find('user', [
'fields' => ['Users.id', 'Users.email', 'Users.password',
'Users.username'],
'conditions' => ['Users.id' => 900000]
]);
$this->assertInstanceOf('Cake\ORM\Query', $query);
$result = $query->hydrate(false)->toArray();
$expected = [
[
'id' => 900000,
'email' => 'usuariocomum1@gmail.com',
'password' => 'usuariocomum1senha',
'username' => 'usuariocomum1username'
]
];
$this->assertEquals($expected, $result);
}
测试方法:
public function findUser(Query $query, array $options){
$query->where($options);
return $query;
}
用户夹具:
public $records = [
[
'id' => 900000,
'email' => 'usuariocomum1@gmail.com',
'password' => 'usuariocomum1senha',
'username' => 'usuariocomum1username',
'user_type_id' => 900000,
'created' => '2015-07-17 18:46:47',
'modified' => '2015-07-17 18:46:47'
]
]
我正在阅读本教程CakePHP 3.0 Testing
[编辑1]
使用--verbose标志:
c:\xampp\htdocs\PROJETOS\Shopping>vendor\bin\phpunit --verbose tests\TestCase\Mo
del\Table\UsersTableTest
PHPUnit 4.8.6 by Sebastian Bergmann and contributors.
Runtime: PHP 5.6.3
Configuration: C:\xampp\htdocs\PROJETOS\Shopping\phpunit.xml.dist
III.
Time: 15.87 seconds, Memory: 7.50Mb
There were 3 incomplete tests:
1) App\Test\TestCase\Model\Table\UsersTableTest::testInitialize
Not implemented yet.
C:\xampp\htdocs\PROJETOS\Shopping\tests\TestCase\Model\Table\UsersTableTest.php:
58
2) App\Test\TestCase\Model\Table\UsersTableTest::testValidationDefault
Not implemented yet.
C:\xampp\htdocs\PROJETOS\Shopping\tests\TestCase\Model\Table\UsersTableTest.php:
71
3) App\Test\TestCase\Model\Table\UsersTableTest::testBuildRules
Not implemented yet.
C:\xampp\htdocs\PROJETOS\Shopping\tests\TestCase\Model\Table\UsersTableTest.php:
81
OK, but incomplete, skipped, or risky tests!
Tests: 4, Assertions: 2, Incomplete: 3.
[编辑2]
当我将测试更改为:
public function testFindUser(){
$query = $this->Users->find('user', [
'fields' => ['Users.id', 'Users.email', 'Users.password',
'Users.username', 'Users.user_type_id', 'Users.created',
'Users.modified'],
'conditions' => ['Users.id' => 900000]
]);
$this->assertInstanceOf('Cake\ORM\Query', $query);
$result = $query->hydrate(false)->toArray();
$expected = [
[
'id' => 900000,
'email' => 'usuariocomum1@gmail.com',
'password' => 'usuariocomum1senha',
'username' => 'usuariocomum1username',
'user_type_id' => 900000,
'created' => '2015-07-17 18:46:47',
'modified' => '2015-07-17 18:46:47'
]
];
$this->assertEquals($expected, $result);
}
测试已执行但失败(hidrate(false)
可以创建和修改原始对象)(为什么现在可以工作?为什么显示'user_type_id' => 900000
)
我的控制台:
c:\xampp\htdocs\PROJETOS\Shopping>vendor\bin\phpunit tests\TestCase\Model\Table\
UsersTableTest
PHPUnit 4.8.6 by Sebastian Bergmann and contributors.
IIIF
Time: 8.13 seconds, Memory: 7.75Mb
There was 1 failure:
1) App\Test\TestCase\Model\Table\UsersTableTest::testFindUser
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
'user_type_id' => 900000
- 'created' => '2015-07-17 18:46:47'
- 'modified' => '2015-07-17 18:46:47'
+ 'created' => Cake\I18n\Time Object (...)
+ 'modified' => Cake\I18n\Time Object (...)
)
)
C:\xampp\htdocs\PROJETOS\Shopping\tests\TestCase\Model\Table\UsersTableTest.php:
107
FAILURES!
Tests: 4, Assertions: 2, Failures: 1, Incomplete: 3.
[编辑3]
我清理我的TestCase并删除所有未实现的测试(由bake创建),这是输出:
c:\xampp\htdocs\PROJETOS\Shopping>vendor\bin\phpunit tests\TestCase\Model\Table\
UsersTableTest
PHPUnit 4.8.6 by Sebastian Bergmann and contributors.
.
Time: 6.06 seconds, Memory: 7.50Mb
OK (1 test, 2 assertions)
**NOTE** CakePHP 3.0.11 PHPUnit 4.8.6
答案 0 :(得分:1)
我们在你的另一个问题中有这个,我们不是吗? testFindUser
测试不被跳过,它可以正常运行,因为您可以从PHPUnit输出中判断,并且当您更改代码时收到失败消息这一事实产生和错误,如果它被跳过,就没有失败,输出将是IIIS
。
确定,但不完整,跳过或有风险的测试!
测试: 4 ,断言:2,不完整: 3 。
*强调我的
共计4次测试,3次不完整,= 1次测试
该消息只是表示有不完整/未实施的测试,另外到运行OK
的测试。
详细级别输出使这一点更加清晰,向您展示哪些测试不完整 - 这些测试都不是您的testFindUser
测试。
您可能希望仔细查看文档,以掌握如何解释输出。