phpunit测试在Laravel 5.2中不起作用

时间:2017-05-15 12:01:53

标签: php laravel-5.2 phpunit

这是TestCase.php code ::

<?php

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

    /**
     * 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;
    }
}

这是我的UserTest.php文件代码::

<?php

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class UserTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicExample()
    {

       $user = User::find(1);
        $this->actingAs($user)
            ->visit('/quickscore')
            ->see('Analysis');
    }



}

运行phpunit ::

时,这会给我这个错误
PHPUnit 4.0.20 by Sebastian Bergmann.

Configuration read from /site/phpunit.xml

.    E    

Time: 122 ms, Memory: 14.00MB

There was 1 error:

1) UserTest::testBasicExample
ErrorException: Declaration of Illuminate\Foundation\Testing\Constraints\PageConstraint::fail($crawler, $description, SebastianBergmann\Comparator\ComparisonFailure $comparisonFailure = NULL) should be compatible with PHPUnit_Framework_Constraint::fail($other, $description, PHPUnit_Framework_ComparisonFailure $comparisonFailure = NULL)

/site/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Constraints/PageConstraint.php:114
/site/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Constraints/HasSource.php:5
/site/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:263
/site/tests/UserTest.php:40

FAILURES!                          
Tests: 2, Assertions: 1, Errors: 1.

这段代码错在哪里?请帮助。

以及何时只需删除UserTest.php

中的用户
$this->visit('/quickscore')
            ->see('Analysis');

似乎这个错误::

PHPUnit 4.0.20 by Sebastian Bergmann.

Configuration read from site/phpunit.xml

.    F    

Time: 111 ms, Memory: 14.00MB

There was 1 failure:

1) UserTest::testBasicExample
A request to [http://cudefend.local/login] failed. Received status code [500].

site/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:196
site/app/Http/Controllers/HomeController.php:93
site/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:80
site/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:146
site/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:94
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:52
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
site/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:96
site/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:54
site/vendor/laravel/framework/src/Illuminate/Routing/Route.php:174
site/vendor/laravel/framework/src/Illuminate/Routing/Route.php:140
site/vendor/laravel/framework/src/Illuminate/Routing/Router.php:724
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:52
site/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:64
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:136
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:32
site/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:136
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:32
site/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:64
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:136
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:32
site/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:136
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:32
site/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:59
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:136
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:32
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
site/vendor/laravel/framework/src/Illuminate/Routing/Router.php:726
site/vendor/laravel/framework/src/Illuminate/Routing/Router.php:699
site/vendor/laravel/framework/src/Illuminate/Routing/Router.php:675
site/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:246
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:52
site/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:44
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:136
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:32
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
site/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:132
site/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:99
site/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:515
site/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:78
site/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:138
site/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:80
site/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:61
site/tests/UserTest.php:38

Caused by
ErrorException: Cannot modify header information - headers already sent by (output started at site/vendor/phpunit/phpunit/src/Util/Printer.php:172)

site/app/Http/Controllers/HomeController.php:93
site/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:80
site/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:146
site/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:94
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:52
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
site/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:96
site/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:54
site/vendor/laravel/framework/src/Illuminate/Routing/Route.php:174
site/vendor/laravel/framework/src/Illuminate/Routing/Route.php:140
site/vendor/laravel/framework/src/Illuminate/Routing/Router.php:724
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:52
site/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:64
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:136
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:32
site/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:136
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:32
site/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:64
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:136
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:32
site/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:136
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:32
site/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:59
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:136
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:32
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
site/vendor/laravel/framework/src/Illuminate/Routing/Router.php:726
site/vendor/laravel/framework/src/Illuminate/Routing/Router.php:699
site/vendor/laravel/framework/src/Illuminate/Routing/Router.php:675
site/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:246
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:52
site/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:44
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:136
site/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:32
site/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
site/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:132
site/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:99
site/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:515
site/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:78
site/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:138
site/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:80
site/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:61
site/tests/UserTest.php:38

FAILURES!                            
Tests: 2, Assertions: 1, Failures: 1.

0 个答案:

没有答案