本文介绍了phpunit找不到类,PHP致命错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 我获得phpunit,并使用此链接将其安装用于测试目的的最简单方法.

  1. I get phpunit and install it as this link using the simplest way for test purposes.

我只是下载phpunit.phar文件chmod&重命名移至/usr/local/bin然后,我运行phpunit --version,没问题.

I just download the phpunit.phar file, chmod & rename & move to /usr/local/bin Then, I run phpunit --version, its ok.

PHPUnit 3.7.27 by Sebastian Bergmann

我写了一个简单的测试

public function testSomething(){

   $this -> assertTrue(true)
}

然后我进入源文件文件夹phpunit --colors Test

Then I go into the source file folder, phpunit --colors Test

有效.因此,我决定编写一个复杂的演示.

It works. So, I decide write a complex demo.

我的项目文件夹结构是这样的.

My project folder structure is like this.

Project Name
   --> app
       --> api
       --> tests

现在我在app/api/FlyApi.php

<?php

 class FlyApi {

     public function makeFly(){
        //do something else
     }
 }

然后我为FlyApi.php编写另一个测试类

Then I write another test class for FlyApi.php

<?php

 class FlyApiTest extends PHPUnit_Framework_TestCase {

     public function testFly(){
        //new a FlyApi
        $flyApi = new FlyApi();

        //do something
     }
 }

在这行$flyApi = new FlyApi()我收到了错误消息.

At this line $flyApi = new FlyApi() I got the error.

PHP致命错误:在第23行的/home/kevin/Workspace/fly/app/api/FlyApi.php中找不到类'FlyApi'

PHP Fatal error: Class 'FlyApi' not found in /home/kevin/Workspace/fly/app/api/FlyApi.php on line 23

是的,这行$flyApi = new FlyApi()

推荐答案

您没有加载FlyApi类的定义.

此解决方案特定于Laravel:

This solution is Laravel specific:

您应该扩展TestCase而不是PHPUnit_Framework_TestCase.

这篇关于phpunit找不到类,PHP致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 14:49