首頁 > 後端開發 > php教程 > Yii2 codecept unit 類別找不到

Yii2 codecept unit 類別找不到

WBOY
發布: 2016-09-08 08:43:54
原創
1119 人瀏覽過

我的測試程式碼如下

<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>
登入後複製
登入後複製

執行的時候會抱以下錯誤:

<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>
登入後複製
登入後複製

下程式碼為我參考官方的

<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>
登入後複製
登入後複製

我的問題到底出在哪裡?謝謝各位不吝賜教。

回覆內容:

我的測試程式碼如下

<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>
登入後複製
登入後複製

執行的時候會抱以下錯誤:

<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>
登入後複製
登入後複製

下程式碼為我參考官方的

<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>
登入後複製
登入後複製

我的問題到底出在哪裡?謝謝各位不吝賜教。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板