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

[8.x] Adds withoutDeprecationHandling #39261

Merged
merged 3 commits into from
Oct 19, 2021

Conversation

nunomaduro
Copy link
Member

@nunomaduro nunomaduro commented Oct 19, 2021

This pull request adds withoutDeprecationHandling to the base Laravel's Test Case class so people can opt-in to have deprecations as exceptions in their test suites. Here is an example:

// routes/web.php
Route::get('/', function () {
    str_contains(null, null);

    return view('welcome');
});

// Test A
it('has a home page', function () {
    $response = $this->get('/');

    $response->assertStatus(200); // passes ✅
});

// Test B
it('has a home page', function () {
    $this->withoutDeprecationHandling();

    $response = $this->get('/');

    $response->assertStatus(200); // 🛑 Expected response status code [200] but received 500. The following exception occurred during the request: ErrorException: str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated in /Users/nunomaduro/code/laravel/laravel/routes/web.php:17
});

@taylorotwell If this pull request gets merged, let me know if this deserves a section on the docs.

@taylorotwell
Copy link
Member

taylorotwell commented Oct 19, 2021

The naming feels a bit confusing? withoutDeprecationHandling makes it sound like I won't get exceptions, but this enables exceptions.

@nunomaduro
Copy link
Member Author

@taylorotwell Well, when you use existing withoutExceptionHandling in your tests, the exception does not get caught by the framework and the bubbles up to the test case. Here is the same, when you use withoutDeprecationHandling in your tests, the deprecation does not get caught by the framework and the bubbles up (after being converted to exception) to the test case.

One thing that could be discussed thought, is the fact that this code converts the deprecation to exception. We could eventually do not convert the deprecation to exception, only bubble up a real deprecation to using https://www.php.net/manual/en/function.trigger-error.php. I prefer the former, as we don't have to add the "convertDeprecationsToExceptions" to phpunit.xml.

@taylorotwell
Copy link
Member

Yeah I guess that's a good point. 👍

@taylorotwell taylorotwell merged commit a161262 into 8.x Oct 19, 2021
@taylorotwell taylorotwell deleted the feat/without-deprecation-handling branch October 19, 2021 18:36
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.

2 participants