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

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

@paulhenri-l
Copy link
Contributor

left a comment

Well this seems ok to me :)

@paulhenri-l

This comment has been minimized.

Copy link
Contributor

commented Jul 23, 2019

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

This comment has been minimized.

Copy link
Contributor

commented Jul 23, 2019

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

Do you want me to do it or will you?

@taylorotwell

This comment has been minimized.

Copy link
Member

commented Jul 23, 2019

What problem is this solving? Thanks!

@paulhenri-l

This comment has been minimized.

Copy link
Contributor

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.

taylorotwell added some commits Jul 25, 2019

@taylorotwell taylorotwell merged commit 1f93eab into laravel:5.8 Jul 25, 2019

1 check passed

continuous-integration/styleci/pr The analysis has passed
Details
@Brenneisen

This comment has been minimized.

Copy link

commented on 42c19bd Aug 5, 2019

This breaks tests like these:

$this->artisan('command:list')
            ->expectsOutput('+----+------+---------------+')
            ->expectsOutput('| ID | Name | Params        |')
            ->expectsOutput('+----+------+---------------+')
            ->expectsOutput('| 1  | Test | {"foo":"bar"} |')
            ->expectsOutput('+----+------+---------------+')
            ->assertExitCode(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.