Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Add withoutMix and withMix test helpers #30900

Merged
merged 1 commit into from Dec 23, 2019

Conversation

jasonmccreary
Copy link
Contributor

@jasonmccreary jasonmccreary commented Dec 22, 2019

Similar to withoutExceptionHandling and withExceptionHandling, these two test helpers allow developers to quickly unbinding and rebinding Laravel Mix in the container during testing.

This behavior was added in #26289, but still requires intimate knowledge of the underlying Mix class and proper binding function. Furthermore, it adds a relatively obscure, big block of code for a simple need.

Before

$this->swap(\Illuminate\Foundation\Mix::class, function () {
    return '';
});

After

$this->withoutMix();

Note: Inline with other TestCase methods, withoutMix returns the instance allowing it to be chained with other fluent methods, e.g. $this->withoutMix()->withoutExceptionHandling()->get('/');

@GrahamCampbell GrahamCampbell changed the title Add withoutMix and withMix test helpers [6.x] Add withoutMix and withMix test helpers Dec 22, 2019
@taylorotwell taylorotwell merged commit f32662a into laravel:6.x Dec 23, 2019
@jasonmccreary jasonmccreary deleted the without-mix branch December 23, 2019 15:14
@driesvints
Copy link
Member

Would be cool if we could somehow implement something that disables mix all together for all tests. Like calling this method in the setUp method of the TestCase class.

@driesvints
Copy link
Member

Turns out this doesn't works when using browser kit testing's visit method. Unfortunate but understandable.

@carbontwelve
Copy link

This has proved necessary in a project I just took over with "six mysteriously failing unit tests that pass on our locals." It would have been super helpful if this was documented on https://github.com/laravel/docs/blob/8.x/testing.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants