Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - understand how testing works

I am a beginner with the framework laravel 5.2

I want to understand how the unit test work. I made this test :

public function testPageLogin()
{
    $this->visit('/login')
    ->see('Connexion');
}

When I run the script : all is fine.

Then I made this test :

$this->visit('/login')
     ->type('[email protected]', 'email')
     ->type('toto', 'password')
     ->check('souvenir')
     ->press('Connexion')
     ->seePageIs('/login');

Of course the fields 'email', 'password', 'souvenir' exists in the html page. And with these values, the page "login" must be displayed because these values are not known into the DB.

When I run the script, I have a failure

Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Co ntracts\Debug\ExceptionHandler] is not instantiable. in C:\wamp\www\ecole\vendor \laravel\framework\src\Illuminate\Container\Container.php on line 748

Certainly I must do something wrong somewhere, but I do not see where. Any help will be appreciated. Merci.

Dominique

like image 257
Dom Avatar asked Jul 09 '16 15:07

Dom


People also ask

What is testing in Laravel?

In Laravel, there are two ways to test your app. One is with Unit testing while other is with Feature testing. Unit testing allows to test your classes models, controllers etc, while Feature testing enables you to test your code base.

What should be tested in Laravel?

Laravel is built with testing in mind. In fact, support for testing with PHPUnit is included out of the box and a phpunit.xml file is already set up for your application. The framework also ships with convenient helper methods that allow you to expressively test your applications.

What is TDD in Laravel?

Test Driven Development (TDD) is a programming style that can help you write well-designed and error-free code. In this tutorial, learn how to build a Laravel app using TDD. By Wern Ancheta. #php #laravel #tdd. Aug 8, 2022.

What is the difference between unit and feature test?

The unit test ensures that individual code i.e. small piece of code works fine. An integration test is done to ensure that - when one or more units are integrated, it works fine. The feature test is the testing of features just like an actual user. Like how the actual user will use the feature.


1 Answers

This is a known bug within Laravel when using a later version of PHPUnit. I believe this bug still hasn't been fixed;

https://github.com/laravel/framework/issues/10808

In the meantime, there's some workarounds below;

1) Instead of using the global PHPUnit, use *project*/vendor/bin/phpunit.

2) Downgrade your version of PHPUnit so that Laravel is compatible with it, to do this, run the below commands;

composer global remove phpunit/phpunit
composer global require 'phpunit/phpunit=~4.0'

Hope this helps.

like image 85
JayIsTooCommon Avatar answered Oct 19 '22 07:10

JayIsTooCommon