Skip to content
This repository was archived by the owner on Apr 20, 2021. It is now read-only.
This repository was 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

@kevin-schmitt

Description

@kevin-schmitt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions