在 yii 中使用 phpunit - 父类未被识别

发布于 2025-01-08 04:07:07 字数 1144 浏览 0 评论 0原文

我为在 Yii 中创建的模型编写了一个小测试用例,当我尝试运行测试时,它给出了: 致命错误:类

'.....\ActiveRecord' not found in Commissions.php'

现在,我的类 (commissions.php) 继承了 Yii 中的 ActiveRecord 类,但我怎么知道PHPunit 哪里可以找到呢?我尝试在 Commissions.php 中使用 include 语句,但它找不到 ActiveRecord 继承的类等等。

<?php

include_once('Commissions.php');

class CommissionsTest extends PHPUnit_Framework_TestCase
{
    // Here, the idea would be to check one or two employees manually or based on the SQL query
    // Or even a previous value using the function so that when any changes are made, the value
    // remains the same while using the same arguments.
    public function setUp()
    {
        $this->employee = new Commissions();
        $this->employee->employeeId = 'V1S';
        $this->employee->year = 2012;
        $this->employee->period = 1;
    }

    public function testAttributes()
    {
        $this->assertEquals('V1S', $this->employee->employeeId);
        $this->assertEquals(2012, $this->employee->year);
        $this->assertEquals(1, $this->employee->period);
    }
}

?>

I wrote a little test case for a model I created in Yii and when I try to run the test, it gives me: Fatal error: Class

'.....\ActiveRecord' not found in Commissions.php'

Now, my class (commissions.php) inherits the ActiveRecord class in Yii but how can I tell PHPunit where to find it? I've tried using an include statement in Commissions.php but then it can't find the class that ActiveRecord inherits and so on.

<?php

include_once('Commissions.php');

class CommissionsTest extends PHPUnit_Framework_TestCase
{
    // Here, the idea would be to check one or two employees manually or based on the SQL query
    // Or even a previous value using the function so that when any changes are made, the value
    // remains the same while using the same arguments.
    public function setUp()
    {
        $this->employee = new Commissions();
        $this->employee->employeeId = 'V1S';
        $this->employee->year = 2012;
        $this->employee->period = 1;
    }

    public function testAttributes()
    {
        $this->assertEquals('V1S', $this->employee->employeeId);
        $this->assertEquals(2012, $this->employee->year);
        $this->assertEquals(1, $this->employee->period);
    }
}

?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

刘备忘录 2025-01-15 04:07:07

您的测试用例开头应该包含以下内容:

Yii:import('application.models.Commissions'); //or whatever your model is called
class CommissionsTest extends CDbTestCase { //Not PHPUnit_Framework_TestCase

What you should have at the beginning of your testcase is:

Yii:import('application.models.Commissions'); //or whatever your model is called
class CommissionsTest extends CDbTestCase { //Not PHPUnit_Framework_TestCase
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文