Rumah > pembangunan bahagian belakang > tutorial php > Yii2 codecept unit 类找不到

Yii2 codecept unit 类找不到

WBOY
Lepaskan: 2016-09-08 08:43:54
asal
1118 orang telah melayarinya

我的测试代码如下

<code><?php use app\models\UserSource;

class UserSourceUintTest extends \PHPUnit_Framework_TestCase
{
    protected function setUp()
    {
    }

    protected function tearDown()
    {
    }

    // tests
    public function testMe()
    {

        $params = [
            'user_id' => 1,
            'channel_id' => 2,
        ];
        $this->assertTrue(UserSource::recordUserReg($params));



    }
}</code>
Salin selepas log masuk
Salin selepas log masuk

执行的时候会抱如下错误:

<code>Unit Tests (1) --------------------------------------------------------------------------
E UserSourceUintTest: Me 
-----------------------------------------------------------------------------------------


Time: 40 ms, Memory: 6.00MB

There was 1 error:

---------
1) UserSourceUintTest: Me
 Test  tests/unit/UserSourceUintTest.php:testMe
                                                   
  [Error] Class 'app\models\UserSource' not found  
                                                   
#1  UserSourceUintTest->testMe

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
</code>
Salin selepas log masuk
Salin selepas log masuk

下代码为我参照官方的

<code>Classical Unit Testing
Unit tests in Codeception are written in absolutely the same way as it is done in PHPUnit:

<?php class UserTest extends \Codeception\Test\Unit
{
    public function testValidation()
    {
        $user = User::create();

        $user->username = null;
        $this->assertFalse($user->validate(['username']));

        $user->username = 'toolooooongnaaaaaaameeee';
        $this->assertFalse($user->validate(['username']));

        $user->username = 'davert';
        $this->assertTrue($user->validate(['username']));           
    }
}</code>
Salin selepas log masuk
Salin selepas log masuk

我的问题到底出在哪里?谢谢各位不吝赐教。

回复内容:

我的测试代码如下

<code><?php use app\models\UserSource;

class UserSourceUintTest extends \PHPUnit_Framework_TestCase
{
    protected function setUp()
    {
    }

    protected function tearDown()
    {
    }

    // tests
    public function testMe()
    {

        $params = [
            'user_id' => 1,
            'channel_id' => 2,
        ];
        $this->assertTrue(UserSource::recordUserReg($params));



    }
}</code>
Salin selepas log masuk
Salin selepas log masuk

执行的时候会抱如下错误:

<code>Unit Tests (1) --------------------------------------------------------------------------
E UserSourceUintTest: Me 
-----------------------------------------------------------------------------------------


Time: 40 ms, Memory: 6.00MB

There was 1 error:

---------
1) UserSourceUintTest: Me
 Test  tests/unit/UserSourceUintTest.php:testMe
                                                   
  [Error] Class 'app\models\UserSource' not found  
                                                   
#1  UserSourceUintTest->testMe

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
</code>
Salin selepas log masuk
Salin selepas log masuk

下代码为我参照官方的

<code>Classical Unit Testing
Unit tests in Codeception are written in absolutely the same way as it is done in PHPUnit:

<?php class UserTest extends \Codeception\Test\Unit
{
    public function testValidation()
    {
        $user = User::create();

        $user->username = null;
        $this->assertFalse($user->validate(['username']));

        $user->username = 'toolooooongnaaaaaaameeee';
        $this->assertFalse($user->validate(['username']));

        $user->username = 'davert';
        $this->assertTrue($user->validate(['username']));           
    }
}</code>
Salin selepas log masuk
Salin selepas log masuk

我的问题到底出在哪里?谢谢各位不吝赐教。

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan