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

Errors with BDD example on documentation page #128

Open
prondubuisi opened this issue Mar 2, 2019 · 2 comments
Open

Errors with BDD example on documentation page #128

prondubuisi opened this issue Mar 2, 2019 · 2 comments

Comments

@prondubuisi
Copy link

prondubuisi commented Mar 2, 2019

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

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

@prondubuisi
Copy link
Author

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

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

2 participants