我正在尝试在我的(几乎)骨架CakePHP(版本:3.5.4)应用程序上运行一些简单的PHPUnit测试。
我运行CLI命令来迁移Table' admin_users'。它还可以动态创建一些测试用例。到目前为止一切都很好。
当我尝试使用./vendor/bin/phpunit /myapplication/tests/TestCase/Model/Table/AdminUsersTableTest.php
测试此测试用例时,我收到以下结果:
糟糕的是,我运行的测试用例并不重要,它总是说它找不到任何类。此外,找不到TestCase类。
我错过了一些配置吗?我在app根文件夹中也有一个phpunit.xml.dist文件。这个文件可能有问题吗?
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
</php>
<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="App Test Suite">
<directory>./tests/TestCase</directory>
</testsuite>
<!-- Add plugin test suites here. -->
</testsuites>
<!-- Setup a listener for fixtures -->
<listeners>
<listener
class="\Cake\TestSuite\Fixture\FixtureInjector"
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php">
<arguments>
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
</arguments>
</listener>
</listeners>
<!-- Ignore vendor tests in code coverage reports -->
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
<directory suffix=".php">./plugins/*/src/</directory>
</whitelist>
</filter>
</phpunit>
这是TestCase文件的一部分:
<?php
namespace App\Test\TestCase\Model\Table;
use App\Model\Table\AdminUsersTable;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
/**
* App\Model\Table\AdminUsersTable Test Case
*/
class AdminUsersTableTest extends TestCase
{
/**
* Test subject
*
* @var \App\Model\Table\AdminUsersTable
*/
public $AdminUsers;
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'app.admin_users'
];
/**
* setUp method
*
* @return void
*/
public function setUp()
{
parent::setUp();
$config = TableRegistry::exists('AdminUsers') ? [] : ['className' => AdminUsersTable::class];
$this->AdminUsers = TableRegistry::get('AdminUsers', $config);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown()
{
unset($this->AdminUsers);
parent::tearDown();
}
/**
* Test initialize method
*
* @return void
*/
public function testInitialize()
{
$this->markTestIncomplete('Not implemented yet.');
}
...