Good day. I'm learning some PHP BDD testing with Behat. I've been following closely this Behat 3
tutorial: http://docs.behat.org/en/latest/quick_start.html
I'm on Windows 10, using php 5.6.33. I've added composer.phar
and composer.json
to my project folder and the latter file looks like this:
{
"require-dev": {
"behat/behat": "~3.0.4",
"phpunit/phpunit": "~4.1.0"
}
}
Then, as tutorial suggests, I run commands in the following order:
-
php composer.phar install
. -
vendor/bin/behat --init
. - I've placed
sample.feature
file intofeatures
folder.
Feature file looks like this:
Feature: Product basket
In order to buy products
As a customer
I need to be able to put interesting products into a basket
Rules:
- VAT is 20%
- Delivery for basket under £10 is £3
- Delivery for basket over £10 is £2
Scenario: Buying a single product under £10
Given there is a "Sith Lord Lightsaber", which costs £5
When I add the "Sith Lord Lightsaber" to the basket
Then I should have 1 product in the basket
And the overall basket price should be £9
Scenario: Buying a single product over £10
Given there is a "Sith Lord Lightsaber", which costs £15
When I add the "Sith Lord Lightsaber" to the basket
Then I should have 1 product in the basket
And the overall basket price should be £20
Scenario: Buying two products over £10
Given there is a "Sith Lord Lightsaber", which costs £10
And there is a "Jedi Lightsaber", which costs £5
When I add the "Sith Lord Lightsaber" to the basket
And I add the "Jedi Lightsaber" to the basket
Then I should have 2 products in the basket
And the overall basket price should be £20
But when I run vendor/bin/behat --init
I get this exception which actually do not prevent code snippets from being generated:
ReflectionException: Method FeatureContext::__construct does not have a prototype in D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Behat\Context\Reader\AnnotatedContextReader.php on line 86
Call Stack:
0.0054 237328 1. {main}() D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\bin\behat:0
0.5684 2249712 2. Symfony\Component\Console\Application->run(???, ???) D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\bin\behat:31
0.7328 2785200 3. Behat\Testwork\Cli\Application->doRun(class Symfony\Component\Console\Input\ArgvInput, class Symfony\Component\Console\Output\ConsoleOutput) D:\Projects\php-projects\local-behat-phpunit-2\vendor\symfony\console\Application.php:117
5.8172 12067888 4. Symfony\Component\Console\Application->doRun(class Symfony\Component\Console\Input\ArgvInput, class Symfony\Component\Console\Output\ConsoleOutput) D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Testwork\Cli\Application.php:102
5.8180 12068848 5. Symfony\Component\Console\Application->doRunCommand(class Behat\Testwork\Cli\Command, class Symfony\Component\Console\Input\ArgvInput, class Symfony\Component\Console\Output\ConsoleOutput) D:\Projects\php-projects\local-behat-phpunit-2\vendor\symfony\console\Application.php:193
5.8181 12069424 6. Symfony\Component\Console\Command\Command->run(class Symfony\Component\Console\Input\ArgvInput, class Symfony\Component\Console\Output\ConsoleOutput) D:\Projects\php-projects\local-behat-phpunit-2\vendor\symfony\console\Application.php:843
5.8252 12079976 7. Behat\Testwork\Cli\Command->execute(class Symfony\Component\Console\Input\ArgvInput, class Symfony\Component\Console\Output\ConsoleOutput) D:\Projects\php-projects\local-behat-phpunit-2\vendor\symfony\console\Command\Command.php:241
5.8558 12157688 8. Behat\Testwork\Tester\Cli\ExerciseController->execute(class Symfony\Component\Console\Input\ArgvInput, class Symfony\Component\Console\Output\ConsoleOutput) D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Testwork\Cli\Command.php:63
5.9129 12222752 9. Behat\Testwork\Tester\Cli\ExerciseController->testSpecifications(class Symfony\Component\Console\Input\ArgvInput, array(2)) D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Testwork\Tester\Cli\ExerciseController.php:108
5.9802 12264200 10. Behat\Testwork\EventDispatcher\Tester\EventDispatchingExercise->test(array(2), bool) D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Testwork\Tester\Cli\ExerciseController.php:146
5.9802 12264432 11. Behat\Testwork\Tester\Runtime\RuntimeExercise->test(array(2), bool) D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Testwork\EventDispatcher\Tester\EventDispatchingExercise.php:70
6.0493 12324584 12. Behat\Testwork\EventDispatcher\Tester\EventDispatchingSuiteTester->setUp(class Behat\Behat\Context\Environment\UninitializedContextEnvironment, class Behat\Testwork\Specification\GroupedSpecificationIterator, bool) D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Testwork\Tester\Runtime\RuntimeExercise.php:69
6.0691 12342664 13. Behat\Testwork\Hook\Tester\HookableSuiteTester->setUp(class Behat\Behat\Context\Environment\UninitializedContextEnvironment, class Behat\Testwork\Specification\GroupedSpecificationIterator, bool) D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Testwork\EventDispatcher\Tester\EventDispatchingSuiteTester.php:59
6.0976 12359008 14. Behat\Testwork\Hook\HookDispatcher->dispatchScopeHooks(class Behat\Testwork\Hook\Scope\BeforeSuiteScope) D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Testwork\Hook\Tester\HookableSuiteTester.php:63
6.0976 12359192 15. Behat\Testwork\Hook\HookRepository->getScopeHooks(class Behat\Testwork\Hook\Scope\BeforeSuiteScope) D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Testwork\Hook\HookDispatcher.php:57
6.0976 12359280 16. Behat\Testwork\Hook\HookRepository->getEnvironmentHooks(class Behat\Behat\Context\Environment\UninitializedContextEnvironment) D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Testwork\Hook\HookRepository.php:67
6.0977 12359352 17. Behat\Testwork\Environment\EnvironmentManager->readEnvironmentCallees(class Behat\Behat\Context\Environment\UninitializedContextEnvironment) D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Testwork\Hook\HookRepository.php:50
6.0977 12359600 18. Behat\Behat\Context\Environment\Reader\ContextEnvironmentReader->readEnvironmentCallees(class Behat\Behat\Context\Environment\UninitializedContextEnvironment) D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Testwork\Environment\EnvironmentManager.php:115
6.0978 12360208 19. Behat\Behat\Context\Environment\Reader\ContextEnvironmentReader->readContextCallees(class Behat\Behat\Context\Environment\UninitializedContextEnvironment, string(14)) D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Behat\Context\Environment\Reader\ContextEnvironmentReader.php:66
6.1051 12363528 20. Behat\Behat\Context\Reader\ContextReaderCachedPerContext->readContextCallees(class Behat\Behat\Context\Environment\UninitializedContextEnvironment, string(14)) D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Behat\Context\Environment\Reader\ContextEnvironmentReader.php:87
6.1052 12363616 21. Behat\Behat\Context\Reader\AnnotatedContextReader->readContextCallees(class Behat\Behat\Context\Environment\UninitializedContextEnvironment, string(14)) D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Behat\Context\Reader\ContextReaderCachedPerContext.php:52
6.1052 12365152 22. Behat\Behat\Context\Reader\AnnotatedContextReader->readMethodCallees(string(14), class ReflectionMethod) D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Behat\Context\Reader\AnnotatedContextReader.php:64
6.1053 12365328 23. ReflectionMethod->getPrototype() D:\Projects\php-projects\local-behat-phpunit-2\vendor\behat\behat\src\Behat\Behat\Context\Reader\AnnotatedContextReader.php:86
I've just started to learn PHP, but as far as I understand it interface AnnotatedContextReader
indeed does not have a prototype for __construct
method, but mentioned interface extends Context
interface and this one has such method prototype. So, I decided to skip that exception for the time being and completed provided tutorial. I can run my behat tests, but console is full of ReflectionExceptions
complaining about absence of prototypes for my test steps. This drastically increases execution time and definitely should not be happening. Any ideas of what am I doing wrong? For code snippets please refer to tutorial link I've provided.