How to do unit tests with phpUnit to the laravel drivers?

0

I still have a lot of doubt about doing unit tests to the drivers that I believe in laravel, for example: employeeController, where this has methods like index, store, edit, Does anyone know how to perform these tests on the controller's methods?

    
asked by Luis Hernandez 09.11.2018 в 04:01
source

1 answer

1

To see these functions provided by Laravel, use the command when creating your controller:

php artisan make:controller EmpleadoController --resource

and your route file

route::resource("EmpleadoController");

Responding to your comment

In your composer.json you must include:

// ...
"require-dev": {
"phpunit/phpunit": "3.7.*" // <--------
},
// ...

then you run from the terminal standing on your project

Composer update

from console you see that everything is fine

vendor/bin/phpunit

Then you create a file for tests in App/prueba.php

we create a function

public function miapp()
{
       $response = $this->call('GET', 'miapp');
       $this->assertResponseOk();
       $this->assertEquals('App de prueba', $response->getContent());
}

You rerun the command:

vendor/bin/phpunit

and in your routes file:

Route::get('miapp', function(){
    return 'Esta es una prueba';
});

and again:

vendor/bin/phpunit

We have the official documentation from Laravel.

Laravel Docs

    
answered by 09.11.2018 / 04:38
source