PHP致命错误:Class' TestCase'未找到

时间:2016-03-15 08:35:27

标签: laravel laravel-5.2

我在Laravel 5.2上,我试图第一次运行测试,我知道这个错误已经在SO上讨论了,但是我找不到任何答案..

我跑:

php artisan make:test TerritoryTest

然后,在项目根目录中:

phpunit

但是,我收到了这个错误:

PHP Fatal error:  Class 'TestCase' not found in /share/tests/TerritoryTest.php on line 8

那么,谁可以帮忙?

1 个答案:

答案 0 :(得分:3)

我找到答案,首先:

"tests/TestCase.php"我必须添加"autoload-dev": { "classmap": [ "tests/TestCase.php" ] },

class TestCase extends Illuminate\Foundation\Testing\TestCase
{
    /**
     * The base URL to use while testing the application.
     *
     * @var string
     */
    protected $baseUrl = 'http://localhost';

    /**
     * Creates the application.
     *
     * @return \Illuminate\Foundation\Application
     */
    public function createApplication()
    {
        $app = require __DIR__.'/../bootstrap/app.php';

        $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();

        return $app;
    }
}

然后,我在tests文件夹中手动添加了TestCase.php:

[contact-form-7 id="2" title="Form"] <!-- #Form shortcode-->
         <input type="button" id="more_fields" onclick="add_fields();" value="Add form" />  <!-- #Form shortcode-->

<script>
    function add_fields() {
       var d = document.getElementById("content");

       d.innerHTML += "[contact-form-7 id='2' title="Form"]";
    }
</script>

我希望这会对某人有所帮助..