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

Fix expectsOutput bug #25

Closed
wants to merge 4 commits into from
Closed

Fix expectsOutput bug #25

wants to merge 4 commits into from

Conversation

paulhenri-l
Copy link
Contributor

Hey there!

In order to fix this issue: laravel/framework#29246

I've made a PR on the laravel/framework repository: laravel/framework#29252

As it is changing code in the TestCase class I need to replicate the changes here as-well in order to make the tests pass.

So as requested by @GrahamCampbell I'am opening this PR.

@coveralls
Copy link

coveralls commented Jul 21, 2019

Coverage Status

Coverage decreased (-1.3%) to 86.517% when pulling aa26717 on paulhenri-l:fix-expects-output-bug into 2ab439a on orchestral:3.9.

src/Concerns/Testing.php Outdated Show resolved Hide resolved
@crynobone
Copy link
Member

I would only merge this if @taylorotwell accept the PR on laravel/framework

@GrahamCampbell
Copy link
Contributor

I would only merge this if @taylorotwell accept the PR on laravel/framework

Yeh. I think acceptance needs to be mutual, or not at all. :)

$this->afterApplicationCreatedCallbacks = [];
$this->beforeApplicationDestroyedCallbacks = [];

Artisan::forgetBootstrappers();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screen Shot 2019-07-22 at 9 33 21 AM

I don't get why we need two nested try, surely one is enough since outside of if ($this->app) condition we are only unsetting the values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nested tries are from @GrahamCampbell he can correct me if I am wrong.

As far as I understand the idea is that if in the same tearDown

  • a beforeApplicationDestroyed callback throws the app will still get flushed.
  • an afterApplicationDestroyedCallback throws the variables will still get reset.

My initial fix had only the outter try/finally but it makes the assumption that beforeApplicationDestroyed callbacks won't throw.

While being a bit clunky the nested try/finally seems to really add value here. Or maybe there is another way?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just use rescue() for this TBH.

if ($this->app) {
    foreach ($this->beforeApplicationDestroyedCallbacks as $callback) {
        \rescue($callback, null, false);
    }
    
    $this->app->flush();
    $this->app = null;

    foreach ($this->afterApplicationDestroyedCallbacks as $callback) {
        \rescue($callback, null, false);
    }
}

cc @GrahamCampbell

Copy link
Contributor Author

@paulhenri-l paulhenri-l Jul 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didn't know about this helper.

Well then I guess using rescue is definitely a better option.

I'll make the changes.

Copy link
Contributor Author

@paulhenri-l paulhenri-l Jul 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh actually we can't use rescue here.

calls to the this->fails() method of phpunit throws. If we use rescue then phpunit won't be able to display these errors.

I guess we can call the beforeApplicationDestroyedCallbacks with rescue and the afterApplicationDestroyedCallbacks without it.

If a test trait needs to call $this->fail() it will need to do so in an afterApplicationDestroyed callback.

I'll check if laravel's provided test trait do so and update them accordingly if we go that route.

Maybe @GrahamCampbell as another idea?

@crynobone
Copy link
Member

Please resubmit PR with changes based on accepted PR to laravel/framework

@crynobone crynobone closed this Jul 25, 2019
@paulhenri-l
Copy link
Contributor Author

Yep I'll do that

@paulhenri-l paulhenri-l deleted the fix-expects-output-bug branch July 25, 2019 17:10
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.

4 participants