未找到 PHPUnit class 但已正确包含

PHPUnit class not found but included correctly

我正在使用带有 cakephp 的 phpunit 进行测试,但是当我尝试 运行 某些测试时 class 抛出一个 致命错误 但是这个 class 被正确插入,甚至没有被 PHPStorm 指责丢失文件错误。

执行测试用例的命令:

c:\xampp\htdocs\PROJETOS\Shopping\vendor\phpunit>phpunit "C:/xampp/htdocs/PROJETOS/Shopping/tests/TestCase/Model/Table/UsersTableTest.php"

致命错误:

Fatal error: Class 'Cake\TestSuite\TestCase' not found in C:\xampp\htdocs\PROJET OS\Shopping\tests\TestCase\Model\Table\UsersTableTest.php on line 12

测试用例:

<?php
namespace App\Test\TestCase\Model\Table;

use App\Model\Table\UsersTable;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;

/**
 * App\Model\Table\UsersTable Test Case
 */
class UsersTableTest extends TestCase
{

    /**
     * Fixtures
     *
     * @var array
     */
    public $fixtures = [
        'app.users',
        'app.user_types',
        'app.bookings',
        'app.stores'
    ];

    /**
     * setUp method
     *
     * @return void
     */
    public function setUp()
    {
        parent::setUp();
        $config = TableRegistry::exists('Users') ? [] : ['className' => 'App\Model\Table\UsersTable'];
        $this->Users = TableRegistry::get('Users', $config);
    }

    /**
     * tearDown method
     *
     * @return void
     */
    public function tearDown()
    {
        unset($this->Users);

        parent::tearDown();
    }

    /**
     * Test initialize method
     *
     * @return void
     */
    public function testInitialize()
    {
        $this->markTestIncomplete('Not implemented yet.');
    }

    /**
     * Test validationDefault method
     *
     * @return void
     */
    // Método que deverá testar o método "validationDefault()" de "UsersTable",
    // mas como e quando este método será chamado?
    // A ferramenta seleciona o método a ser executado
    public function testValidationDefault()
    {
        $this->markTestIncomplete('Not implemented yet.');
    }

    /**
     * Test buildRules method
     *
     * @return void
     */
    public function testBuildRules()
    {
        $this->markTestIncomplete('Not implemented yet.');
    }

    public function testFindUserById(){
        $query = $this->Users->find('userById', [
            'conditions' => ['Users.id' => 900000],
            'fields' => ['Users.id', 'Users.email', 'Users.password',
                'Users.username', 'Users.user_type_id', 'Users.created',
                'Users.modified']
        ]);
        $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);
    }
}

在文件夹中:[ProjectName]/tests/ 有 2 个文件夹 Fixture 和 TestCase 以及 1 个文件 bootstrap.php

我的文件夹结构:

配置和测试文件夹:

phpunit 文件夹(在 vendor 文件夹内(随 composer 安装))

供应商文件夹中的 bin 文件夹

当我使用 composer 删除 phpunit 时,请遵循以下答案:How to remove unused dependencies from composer? 仍然有一个文件夹 phpunit 有一个奇怪的文件(可以吗?)

注意:我使用的是 CakePHP 3.0.11 和 PHPHUnit 4.8

根据 CakePHP documentation,您应该 运行 phpunit 可执行文件位于 vendor/bin 文件夹中(在您的 CakePHP 应用程序中有一个 phpunit.xml.dist 文件所以你应该 运行 根文件夹中的可执行文件):

C:\...\Shopping> vendor\bin\phpunit tests\TestCase\Model\Table\UsersTableTest.php

如果您没有这样的可执行文件,您可能有 "bad" phpunit 安装。您应该删除它(以及 vendor/phpunit 文件夹)并使用以下方法重新安装它:

php composer.phar require phpunit/phpunit:4.8