I am trying to make behat work with symfony/apiplatform and can't even get past installation.
Whenever I run "vendor/behat/behat/bin/behat", I am greeted with `FeatureContext` context class not found and can not be used..
I put my "behat.yml" in "config" folder, and features should be in "tests/features", so per google and your doc my conf file looks like :
default:
calls:
error_reporting: 16383 # E_ALL & ~E_USER_DREPRECATED
autoload:
: '../tests/features/bootstrap'
: '../tests/features/'
suites:
default:
paths:
features: ../tests/features
bootstrap: ../tests/features/bootstrap
contexts:
- FeatureContext
- Behat\MinkExtension\Context\MinkContext
- Behatch\Context\RestContext
- Behatch\Context\JsonContext
formatters:
pretty: true
gherkin:
cache: ~
filters:
tags: ~@wip
extensions:
Behat\Symfony2Extension:
kernel:
bootstrap: ../tests/features/bootstrap/bootstrap.php
class: "App\\Kernel"
Behat\MinkExtension:
base_url: "http://localhost:8081/xxxxxxx/api"
sessions:
default:
symfony2: ~
Behatch\Extension: ~
The thing is, if I run "vendor/behat/behat/bin/behat --init", it creates the FeatureContext file in a folder : '.., yes, that's its name. The full path to the generated FeatureContext that I am supposed to edit in order to get past the horribly uninformative errors is /home/xxx/apiplatform_project/: '../tests/features/bootstrap' : '../tests/features/'/FeatureContext.php
Fine, I edit that misplaced file and put
use Behat\Behat\Context\Context;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* 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 FeatureContext implements Context
{
/**
* @var KernelInterface
*/
private $kernel;
/**
* @var Response|null
*/
private $response;
public function __construct(KernelInterface $kernel)
{
$this->kernel = $kernel;
}
}
And am still stuck with Can not find a matching value for an argument `$kernel` of the method `FeatureContext::__construct()`.
I would just like default tests for an empty project to pass......
Whenever I run "vendor/behat/behat/bin/behat",
is it the same if you run vendor/bin/behat ?
It seems so.
I played around more with my behat.yml and added back the kernal attr for featureContext
- FeatureContext:
kernel: '@kernel'
In this case I have the following error
Can not find a matching value for an argument `$request` of the method `Behatch\Context\RestContext::__construct()`.
Aside from this problem, I would like to know the way to define were to put my FeatureContext file. I don't want it to stay in "config/features/bootstrap...".
I had the same problem with autoload: in behat.yml. I decided to simply use my composer.json with PSR-4:
composer.json
"autoload": {
"psr-4": {
"My\\Namespace\\": "src/"
}
}
src/FeatureContext.php
<?php
namespace My\Namespace
class FeatureContext implements Context, SnippetAcceptingContext
{
//...
}
Note: Don't forget to update your composer.lock by running composer install.
Most helpful comment
I had the same problem with
autoload:inbehat.yml. I decided to simply use my composer.json with PSR-4:composer.json
src/FeatureContext.php
Note: Don't forget to update your composer.lock by running
composer install.