Behatch / contexts

Behat extension with most custom helper steps
Other
394 stars 203 forks source link

Step "the response should be in JSON" is already defined in Behatch\Context\JsonContext::theResponseShouldBeInJson() #288

Open kevin-schmitt opened 4 years ago

kevin-schmitt commented 4 years ago

Hi, Can you help me please? I have this error when i extends my class with JsonContext or RestContext. my conf behat.yml

suites:
        default:
            contexts:
                - behatch:context:json
                - behatch:context:rest
                - Context\ProductContext:
                    kernel: '@kernel'
                - Context\FeatureContext:
                    kernel: '@kernel'
            paths: [ "%paths.base%/tests/api", "%paths.base%/tests/behat"]

Scénario ouput

Scenario: Can get product data # tests/behat/api/solution_view.feature:12
      Then test                    # tests/behat/api/solution_view.feature:14
        Step "the response should be in JSON" is already defined in Behatch\Context\JsonContext::theResponseShouldBeInJson()

        Behatch\Context\JsonContext::theResponseShouldBeInJson()
        Context\ProductContext::theResponseShouldBeInJson()

class context where i want access json

<?php

declare(strict_types=1);

namespace Context;

use App\Entity\Product;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\MinkExtension\Context\MinkContext;
use Behatch\Context\JsonContext;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelInterface;
use Behatch\Context\RestContext;
use Symfony\Component\HttpClient\HttpClient;
use Context\Auth0HelperTrait;

use Exception;

/**
 * This context class contains the definitions of the steps used by the demo
 * feature file. Learn how to get started with Behat and BDD on Behat's website.
 *
 * @see http://behat.org/en/latest/quick_start.html
 */
class ProductContext extends JsonContext implements Context
{
    use Auth0HelperTrait;

    /**
     * @var Response|null
     */
    private $response;

    private $token;

    public function __construct(KernelInterface $kernel)
    {
        $this->entityManager = $kernel->getContainer()->get('doctrine.orm.entity_manager');
        $this->auth0Credentials();
        $this->token = $this->handlerTokenStore();
    }

    /**
     * @BeforeScenario
    */
    public function initTokenApp(BeforeScenarioScope $scope)
    {
        $this->restContext = $scope->getEnvironment()->getContext(RestContext::class);
        $this->restContext->iAddHeaderEqualTo('Authorization', "Bearer $this->token");
    }

    /**
     * @Then test
     */
    public function test()
    {
        $this->getJson();
    }
}

Thanks

guyenot-jeremy commented 4 years ago

Hi, i have the same problem.