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

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

Merged
merged 5 commits into from
Jul 25, 2019

Conversation

themsaid
Copy link
Member

@themsaid themsaid commented Jul 23, 2019

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
Copy link
Contributor

@paulhenri-l paulhenri-l left a comment

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
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
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
Member

What problem is this solving? Thanks!

@paulhenri-l
Copy link
Contributor

paulhenri-l commented Jul 23, 2019

@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