Skip to content

ErrorTester don't work with Behat Exception #2

@pocky

Description

@pocky

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);
                }
            }
        });
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions