Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

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

Open
kevin-schmitt opened this issue Jul 9, 2020 · 1 comment

Comments

@kevin-schmitt
Copy link

kevin-schmitt commented Jul 9, 2020

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

Hi, i have the same problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants