简体   繁体   中英

laravel unit testing not giving right response with “phpunit”

I need to make unit tests for my laravel app. So far I have started to code the test, but when i ran it it returned not what i expected, so far i have not seen this anywhere on the internet. So I must be doing somethng stupid or missing something, right?

my testing class in tests/tests.php

<?php

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

class Tests extends TestCase
{
public function testLoad(){
    $this->call('GET', '/');

    $this->assertResponseOk();

    $response = $this->action('GET', 'mainController@load');

    $this->visit('/')
         ->see('Todo seznam');

    $this->assertViewHas('tasks');
}

public function dbTest(){
    $this->call('GET', '/delete');

    $this->assertHasOldInput();
}
}

so I presumed i have to install phpunit (I'm on ubuntu 16.04) and then I ran it in root of my project with "phpunit" like everyone else who succeded but got this result:

..............................................................................

Time: 70 ms, Memory: 4.00MB

PHP Fatal error:  Uncaught Error: Call to undefined method PHPUnit_Framework_TestResult::warningCount() in /usr/share/php/PHPUnit/TextUI/ResultPrinter.php:185
Stack trace:
#0 /home/matic/Documents/todo-app/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(446): PHPUnit_TextUI_ResultPrinter->printResult(Object(PHPUnit_Framework_TestResult))
#1 /usr/share/php/PHPUnit/TextUI/Command.php(155): PHPUnit_TextUI_TestRunner->doRun(Array)
#2 /usr/share/php/PHPUnit/TextUI/Command.php(106): PHPUnit_TextUI_Command->run(Array, true)
#3 /usr/bin/phpunit(29): PHPUnit_TextUI_Command::main()
#4 {main}
  thrown in /usr/share/php/PHPUnit/TextUI/ResultPrinter.php on line 185

..............................................................................

a bunch of files i have done no changes to whasoever.

Then i figured i would just make a new project and phpunit there but the result was the same, but even more errors.

............................................................................

Time: 107 ms, Memory: 10.00MB

PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Container/Container.php:748
Stack trace:
#0 /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Container/Container.php(629): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(697): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 [internal function]: Illuminate\Foundation\Bootstrap\HandleE in /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 748
PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Container/Container.php:748
Stack trace:
#0 /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Container/Container.php(629): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(697): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 /home/matic/Documents/unit/vendor/laravel/framework/src/Illu in /home/matic/Documents/unit/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 748

...........................................................................

Am I wrong for thinking there is something fishy here?

How should i go about fixing this? Is it normal?

Thanks for any help you give me I will be so greatfull.

I'm a bit sad nobody helped might have saved me some time. but here goes. Idk what the problem was, but i deleted the vendor folder and ran composer install , which repalced it and now it works

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM