aaronsaray/laravel-test-helpers

This package is abandoned and no longer maintained. No replacement package was suggested.

Laravel test helpers by Aaron Saray.

1.1.0 2019-06-14 00:12 UTC

This package is auto-updated.

Last update: 2020-02-14 02:03:20 UTC


README

These are helper methods that I end up using in my unit tests a lot.

Helpers

Stop DB Access

In unit tests, I do not want database access. Integration tests are where I integrate with the database. In some cases, with misconfigured Unit tests we might introduce database dependencies. To stop that, use the following:

use AaronSaray\LaravelTestHelpers\StopDBAccess

And then in your setUp() method (or in each method you have in your unit test), call $this->stopDBAccess()

Please note that this will technically warn after Database access, not stop it. Afterward it will throw a AaronSaray\LaravelTestHelper\Exceptions\DatabaseAccessException

Create Acting As

Often, you might want to create a user first, then set them as the acting as user in unit tests. You can do that with:

use AaronSaray\LaravelTestHelpers\CreatingActingAs

Then, you can call $this->createActingAs($passToFactory) which will set $this->actingAs to the user model after setting it in the context of this test.

Seed After Refresh

When you need to seed your data immediately after the first migration (re)fresh:

use AaronSaray\LaravelTestHelpers\SeedAfterRefresh

Now, when the migrate:fresh is called, db:seed will be called after (at the beginning of the test suite.)

Mark Test Skipped Because Todo

Sometimes you might not have all the time you need for all your tests (for shame!) but that doesn't mean you want to forget about them.

use AaronSaray\LaravelTestHelpers\HasTodo

Then call $this->todo(); which will mark the test as incomplete and give stderr a message with the test name.