Skip to content

[5.8] Teardown test suite after using fail() method#29267

Merged
taylorotwell merged 5 commits into
laravel:5.8from
themsaid:tearDownAfterFail
Jul 25, 2019
Merged

[5.8] Teardown test suite after using fail() method#29267
taylorotwell merged 5 commits into
laravel:5.8from
themsaid:tearDownAfterFail

Conversation

@themsaid

@themsaid themsaid commented Jul 23, 2019

Copy link
Copy Markdown
Member

This PR has 2 changes:

  1. Ensures all beforeApplicationDestroyedCallbacks are called by catching any exceptions thrown during one of the callbacks.
  2. It removes the once() method so mockery doesn't run verifications on the count, this will allow our mechanism to handle failure using $this->fail();

@themsaid themsaid changed the title Teardown test suite after using fail Teardown test suite after using fail() method Jul 23, 2019
@themsaid themsaid changed the title Teardown test suite after using fail() method [5.8] Teardown test suite after using fail() method Jul 23, 2019

@paulhenri-l paulhenri-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well this seems ok to me :)

@paulhenri-l

Copy link
Copy Markdown
Contributor

I had not seen your new changes with the addition of the callbackException property.

Well I guess this will work since we are no longer preventing other callbacks from running.

Well done :)

@paulhenri-l

Copy link
Copy Markdown
Contributor

Changes will still need to be replicated in orchestral/testbench-core#25 though.

Do you want me to do it or will you?

@taylorotwell

Copy link
Copy Markdown
Member

What problem is this solving? Thanks!

@paulhenri-l

paulhenri-l commented Jul 23, 2019

Copy link
Copy Markdown
Contributor

@taylorotwell This one #29246

Steps to reproduce can be found at the bottom of the issue (#29246 (comment))

This bug is kind of hard to explain but I'll do my best :)

Currently if you use expectsOutput in a test and the expectation fails the test suite cannot properly tear down.

That is because InteractsWithConsole calls $this->fail() in its afterApplicationDestroyed callback. Under the hood $this->fails() throws an exception.

This exception breaks the flow of execution of the tearDown() method preventing subsequent afterApplicationDestroyed callbacks from being called as-well as the rest of the tearDown() method.

    /**
     * Clean up the testing environment before the next test.
     *
     * @return void
     */
    protected function tearDown(): void
    {
        if ($this->app) {
            foreach ($this->beforeApplicationDestroyedCallbacks as $callback) {
                call_user_func($callback); // <------- The exception is thrown here.
                // Everything below this line is thus never executed
            }

            $this->app->flush();
            $this->app = null;
        }
        
       // ... Code here won't get executed as-well
    }

I can give more details about the bug if you want but I think this will give you enough informations.

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.

7 participants