Behat / docs

Behat documentation repository
http://behat.org
28 stars 69 forks source link

Errors with BDD example on documentation page #128

Closed prondubuisi closed 2 weeks ago

prondubuisi commented 5 years ago

I am following the BDD examples on Quick guide and I ran into some errors this is what my composer.json looks like

{
    "require-dev": {
        "behat/behat": "^3.5",
        "phpunit/phpunit": "^8.0"
    }
}

Code sample from quick start page

<?php
// features/bootstrap/FeatureContext.php

use Behat\Behat\Tester\Exception\PendingException;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;

class FeatureContext implements SnippetAcceptingContext
{
    private $shelf;
    private $basket;

    public function __construct()
    {
        $this->shelf = new Shelf();
        $this->basket = new Basket($this->shelf);
    }

    /**
     * @Given there is a :product, which costs £:price
     */
    public function thereIsAWhichCostsPs($product, $price)
    {
        $this->shelf->setProductPrice($product, floatval($price));
    }

    /**
     * @When I add the :product to the basket
     */
    public function iAddTheToTheBasket($product)
    {
        $this->basket->addProduct($product);
    }

    /**
     * @Then I should have :count product(s) in the basket
     */
    public function iShouldHaveProductInTheBasket($count)
    {
        PHPUnit_Framework_Assert::assertCount(
            intval($count),
            $this->basket
        );
    }

    /**
     * @Then the overall basket price should be £:price
     */
    public function theOverallBasketPriceShouldBePs($price)
    {
        PHPUnit_Framework_Assert::assertSame(
            floatval($price),
            $this->basket->getTotalPrice()
        );
    }
}

First error is Fatal error: Class 'PHPUnit_Framework_Assert' not found (Behat\Testwork\Call\Exception\FatalThrowableError)

This is the case because PHPUnit_Framework_Assert used in method theOverallBasketPriceShouldBePs and else where is not defined or imported, this can be solved by adding the line

use PHPUnit\Framework\Assert as PHPUnit_Framework_Assert; Just below the import statements

I would like to work on this issue if it is confirmed Note I installed PHPUnit with composer require --dev phpunit/phpunit

bocharsky-bw commented 5 years ago

Could you provide a bit more information? What error? What example exactly? It would help a lot

prondubuisi commented 5 years ago

Could you provide a bit more information? What error? What example exactly? It would help a lot

I thought I added description, let me do that ASAP