PHPUnit类未找到但包含正确

时间:2015-08-31 12:27:42

标签: php cakephp phpunit

我正在使用phpunit和cakephp进行测试,但是当我尝试运行某个测试类时会抛出致命错误,但是这个类被正确插入,甚至没有被PHPStorm指责错过文件错误。

执行测试用例的命令:

  

C:\ XAMPP \ htdocs中\ PROJETOS \购物\厂商\&的PHPUnit GT; PHPUnit的   “C:/xampp/htdocs/PROJETOS/Shopping/tests/TestCase/Model/Table/UsersTableTest.php”

致命错误:

  

致命错误:找不到类'Cake \ TestSuite \ TestCase'   C:\ XAMPP \ htdocs中\ PROJET   第12行的OS \ Shopping \ tests \ TestCase \ Model \ Table \ UsersTableTest.php

测试用例:

<?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

我的文件夹结构:

inserir a descrição da imagem aqui

配置和测试文件夹:

enter image description here

phpunit文件夹(在供应商文件夹内(与作曲家一起安装))

enter image description here

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

enter image description here

当我用作曲家删除phpunit时,请按照以下答案:How to remove unused dependencies from composer? 仍然有一个文件夹phpunit与一个奇怪的文件(这没关系?)

enter image description here

注意:我正在使用CakePHP 3.0.11和PHPHUnit 4.8

1 个答案:

答案 0 :(得分:3)

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

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

如果您没有此类可执行文件,则可能安装了“错误”phpunit。您应该删除它(和vendor/phpunit文件夹)并使用以下命令重新安装它:

php composer.phar require phpunit/phpunit:4.8