• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Yii2 codecept unit 类找不到

php 搞代码 3年前 (2022-01-23) 24次浏览 已收录 0个评论
文章目录[隐藏]

我的测试代码如下

<code><?phpuse 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.00MBThere was 1 error:---------1) UserSourceUintTest: Me Test  tests/unit/UserSourceUintTest.php:testMe                                                     [Error] Class 'app\models\UserSource' not found                                                     #1  UserSourceUintTest->testMeERRORS!Tests: 1, Assertions: 0, Errors: 1.</code>

下代码为我参照官方的

<code>Classical Unit TestingUnit tests in Codeception are written in absolutely the same way as it is done in PHPUnit:<?phpclass 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><?phpuse <em>8本文来源gao.dai.ma.com搞@代*码(网$</em><pre>搞代gaodaima码

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>Unit Tests (1) --------------------------------------------------------------------------E UserSourceUintTest: Me -----------------------------------------------------------------------------------------Time: 40 ms, Memory: 6.00MBThere was 1 error:---------1) UserSourceUintTest: Me Test  tests/unit/UserSourceUintTest.php:testMe                                                     [Error] Class 'app\models\UserSource' not found                                                     #1  UserSourceUintTest->testMeERRORS!Tests: 1, Assertions: 0, Errors: 1.</code>

下代码为我参照官方的

<code>Classical Unit TestingUnit tests in Codeception are written in absolutely the same way as it is done in PHPUnit:<?phpclass 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>

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


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Yii2 codecept unit 类找不到

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址