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

ErrorTester don't work with Behat Exception #2

Open
pocky opened this issue Dec 4, 2016 · 7 comments
Open

ErrorTester don't work with Behat Exception #2

pocky opened this issue Dec 4, 2016 · 7 comments

Comments

@pocky
Copy link
Collaborator

pocky commented Dec 4, 2016

error_get_last() return NULL for Behat Exception so exemplify can't work. Could you confirm this?

Feature: Test project

  Scenario:                               # features/beer.feature:3
    Given I am a customer                 # FeatureContext::iAmACustomer()
    When I want a beer                    # FeatureContext::iWantABeer()
    Then the bartender should give me one # FeatureContext::theBartenderShouldGiveOne()
    And I say thanks "Tom"                # FeatureContext::iSayThanks()
      Fatal error: Call to undefined method Customer::thanks() (Behat\Testwork\Call\Exception\FatalThrowableError)
    And I drink my beer                   # FeatureContext::iDrinkMyBeer()
    And I am "drunk"                      # FeatureContext::iAm()

--- Failed scenarios:

    features/beer.feature:3

1 scenario (1 failed)
6 steps (3 passed, 1 failed, 2 skipped)
0m0.02s (8.77Mb)
/Users/pocky/Sites/behat-phpspec/BehatSpec/src/Extension/ErrorExtension/src/Tester/ErrorTester.php:93:
NULL
    /**
     * @Then I say thanks :name
     */
    public function iSayThanks($name)
    {
        if ($name !== $this->customer->thanks()) {
            throw new \Exception();
        }
    }

BehatSpec/src/Extension/ErrorExtension/src/Tester/ErrorTester.php line 89

public function registerShutdownFunction()
    {
        register_shutdown_function(function () {

            var_dump(error_get_last());

            if ($error = error_get_last()) {
                $errorMessages = [
                    sprintf('The error "%s"', $error['message']),
                    sprintf('occurred in file %s', $error['file']),
                    sprintf('at line %s', $error['line']),
                ];

                $formatter = new FormatterHelper();
                $formattedBlock = $formatter->formatBlock($errorMessages, 'error', true);
                $this->output->writeln('');
                $this->output->writeln($formattedBlock);
                $this->output->writeln('');

                foreach ($this->observers as $observer) {
                    $observer->notify($error);
                }
            }
        });
    }
@pocky
Copy link
Collaborator Author

pocky commented Dec 4, 2016

I don't know how to handle the exception, I tried with events and try/catch on setUp but this is (apparently) not the solution.

@stof
Copy link

stof commented Dec 5, 2016

this is totally expected, because error_get_last does not deal with exceptions at all in PHP, but only with errors (warnings, notices, etc...)

@pocky
Copy link
Collaborator Author

pocky commented Dec 6, 2016

Got It! PR incoming!

phpspec

@pocky pocky removed the help wanted label Dec 6, 2016
@RemiWoler
Copy link

@pocky Any luck with the PR? If it's not PR-ready, could you at least make a gist of the modification needed to get it to work?

@richardmiller-zz
Copy link
Owner

Is this with the exceptions and handlers introduced in behat 3.2? If so I think they should remove the need for this extension altogether if they are used instead of this extension's error observers.

@pocky
Copy link
Collaborator Author

pocky commented Dec 27, 2016

@RemiWoler The problem is the gap between current version (phpspec 2, multi-repository) and my working one (phpspec3, monorep, many PR on extensions). I didn't take time to apply/tests changes on 0.3.0 with Behat 2/3 and phpspec 2 (I tried quickly and it was not good).

Working version for behat 3/phpspec 3 is here pocky/BehatSpec@f72ea6a

@pocky
Copy link
Collaborator Author

pocky commented Jan 4, 2017

@RemiWoler Working version for Behat3/phpspec2 is here richardmiller-zz/BehatSpec#11

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

No branches or pull requests

4 participants