I get this error when trying to run my behat tests from the command line.
The full output of the error looks like this:
$ behat
Feature: View a list of current custom tariffs
In order to provide custom call pricing to customers
As a user of the Voxbeam Admin site
I expect to be able to correctly administrate a users custom tariffs
@sahi
Scenario: Listing existing custom tariffs # features/custom_tariff_admin.feature:7
PHP Fatal error: Call to a member function getSession() on a non-object in /Users/stuart/bin/vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php on line 81
PHP Stack trace:
PHP 1. {main}() /Users/stuart/bin/vendor/behat/behat/bin/behat:0
PHP 2. Symfony\Component\Console\Application->run() /Users/stuart/bin/vendor/behat/behat/bin/behat:32
PHP 3. Behat\Behat\Console\BehatApplication->doRun() /Users/stuart/bin/vendor/symfony/console/Symfony/Component/Console/Application.php:106
PHP 4. Symfony\Component\Console\Application->doRun() /Users/stuart/bin/vendor/behat/behat/src/Behat/Behat/Console/BehatApplication.php:68
PHP 5. Symfony\Component\Console\Command\Command->run() /Users/stuart/bin/vendor/symfony/console/Symfony/Component/Console/Application.php:193
PHP 6. Behat\Behat\Console\Command\BehatCommand->execute() /Users/stuart/bin/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:240
PHP 7. Behat\Behat\Console\Command\BehatCommand->runFeatures() /Users/stuart/bin/vendor/behat/behat/src/Behat/Behat/Console/Command/BehatCommand.php:128
PHP 8. Behat\Gherkin\Node\AbstractNode->accept() /Users/stuart/bin/vendor/behat/behat/src/Behat/Behat/Console/Command/BehatCommand.php:150
PHP 9. Behat\Behat\Tester\FeatureTester->visit() /Users/stuart/bin/vendor/behat/gherkin/src/Behat/Gherkin/Node/AbstractNode.php:42
PHP 10. Behat\Gherkin\Node\AbstractNode->accept() /Users/stuart/bin/vendor/behat/behat/src/Behat/Behat/Tester/FeatureTester.php:88
PHP 11. Behat\Behat\Tester\ScenarioTester->visit() /Users/stuart/bin/vendor/behat/gherkin/src/Behat/Gherkin/Node/AbstractNode.php:42
PHP 12. Behat\Behat\Tester\ScenarioTester->visitStep() /Users/stuart/bin/vendor/behat/behat/src/Behat/Behat/Tester/ScenarioTester.php:87
PHP 13. Behat\Gherkin\Node\AbstractNode->accept() /Users/stuart/bin/vendor/behat/behat/src/Behat/Behat/Tester/ScenarioTester.php:148
PHP 14. Behat\Behat\Tester\StepTester->visit() /Users/stuart/bin/vendor/behat/gherkin/src/Behat/Gherkin/Node/AbstractNode.php:42
PHP 15. Behat\Behat\Tester\StepTester->executeStep() /Users/stuart/bin/vendor/behat/behat/src/Behat/Behat/Tester/StepTester.php:95
PHP 16. Behat\Behat\Tester\StepTester->executeStepDefinition() /Users/stuart/bin/vendor/behat/behat/src/Behat/Behat/Tester/StepTester.php:126
PHP 17. Behat\Behat\Definition\Annotation\Definition->run() /Users/stuart/bin/vendor/behat/behat/src/Behat/Behat/Tester/StepTester.php:157
PHP 18. call_user_func_array() /Users/stuart/bin/vendor/behat/behat/src/Behat/Behat/Definition/Annotation/Definition.php:155
PHP 19. Behat\MinkExtension\Context\MinkContext->visit() /Users/stuart/bin/vendor/behat/behat/src/Behat/Behat/Definition/Annotation/Definition.php:155
PHP 20. Behat\MinkExtension\Context\RawMinkContext->getSession() /Users/stuart/bin/vendor/behat/mink-extension/src/Behat/MinkExtension/Context/MinkContext.php:45
My behat.yml is:
# behat.yml
default:
paths:
features: features
bootstrap: %behat.paths.features%/bootstrap
extensions:
Behat\MinkExtension\Extension:
base_url: 'http://dev.example.com'
goutte: ~
sahi: ~
annotations:
paths:
features: features/annotations
closures:
paths:
features: features/closures
I have a very simple FeatureContext:
<?php
use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\BehatContext,
Behat\Behat\Exception\PendingException,
Behat\Behat\Context\Step;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;
//
// Require 3rd-party libraries here:
//
// require_once 'PHPUnit/Autoload.php';
// require_once 'PHPUnit/Framework/Assert/Functions.php';
//
/**
* Features context.
*/
class FeatureContext extends MinkContext
{
/**
* @Given /^I am logged in as "([^"]*)" with password "([^"]*)"$/
*/
public function iAmLoggedInAsWithPassword($userName, $password)
{
return array(
new Step\Given('I am on "/login"'),
new Step\Given('I should see "fert"')
);
}
//
// Place your definition and hook methods here:
//
// /**
// * @Given /^I have done something with "([^"]*)"$/
// */
// public function iHaveDoneSomethingWith($argument)
// {
// doSomethingWith($argument);
// }
//
}
and an equally simple feature:
Feature: Administer a customers custom tariffs
In order to provide custom call pricing to customers
As a user of the Admin site
I expect to be able to correctly administrate a users custom tariffs
Scenario: Listing existing custom tariffs
Given I am on "/"
I should see "Fert"
Make sure your behat.yml file is in the correct location. It should be in the root of your project, not in any subdirectories.
If the advice of Stuart Grimshaw doesn't owrk, it can be because of two reasons :
- Your composer.json configuration is not correct; it is tricky to get the correct versions of the 5 or 6 different modules that are needed to make Mink, Behat, Goutte, Selenium, Zombie, maybe Symfony2.. all work together; so please check manually, in each composer.json of those extensions, the required versions of other components; also, try not to use mink-bundle, whose versions of required dependancies seem old
- Do not run the bin\behat command (under Windows or Linux) from your bundle directory; otherwise the .yml configuration file is not found (for sure some obscure reason related to relative paths). You should run the bin\behat command from the root of your project (run the cd command to it first
Ahad Ali
I was getting a similar fatal error as well
PHP Fatal error: Call to a member function getSession() on a non-object in /home/ahad/sites/symfony/vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php on line 101
I have put my answer over here Struggling to get Mink working with Behat
Which solved my problem.
来源:https://stackoverflow.com/questions/14629942/call-to-a-member-function-getsession-on-a-non-object-in-vendor-behat-mink-exte