Testing with the testing environment with Pest in Laravel

Here I wanted to quickly demonstrate the importance of this file, as well as the TestCase file with PHPUnit that we made before, if we remove the file:

test/Pest.php

When running the tests, an error occurred and it couldn't even connect to the database. I had one that was precisely with the get one, but anyway, regardless of what error it's going to give you, here you can see that you need that file to be able to run the tests:

test('test all', function () {
Category::factory(10);
$categories = Category::get()->toArray();

$this->get('/api/category/all',[ 'Authorization' => 'Bearer ' . generateTokenAuth()]
)->assertOk()->assertJson($categories);
});

So if not it will not do anything I think this is the part, it could be this connection part, it was the connection part because again it does not have the database, so it cannot connect here you can see that the first error it gives is with the get methods:

get(). Did you forget to use the [uses()] function? Read more at: https://pestphp.com/docs/configuring-tests
 A facade root has not been set.

Because it doesn't know what the hell that method is and well it's telling you that the amounts for that you would use Pest.php to indicate that well what the hell is this in that case Pest.php is already internally implemented because here we're not placing anything unlike php unit and in the end what's being imported is this class so well If you see an error like this because you surely don't have this class here I say this file then well it was to do that obviously we already corrected it so that the import finds it, we execute it and everything continues working correctly.

- Andrés Cruz

En español

Andrés Cruz

Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz In Udemy

I agree to receive announcements of interest about this Blog.

!Courses from!

10$

On Udemy

There are 1d 16:40!


Udemy

!Courses from!

4$

In Academy

View courses

!Books from!

1$

See the books
¡Become an affiliate on Gumroad!