diff --git a/composer.json b/composer.json index 901a2aa..adebade 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ "behat/mink-extension": "^2.2", "behat/mink-selenium2-driver": "^1.3", "friends-of-behat/service-container-extension": "^1.0", + "friends-of-behat/page-object-extension": "^0.3.1", "phpstan/phpstan-shim": "^0.11", "sylius-labs/coding-standard": "^3.0", "symfony/browser-kit": "^3.4|^4.2", diff --git a/features/fob_page_object_integration/fob_page_object_integration.feature b/features/fob_page_object_integration/fob_page_object_integration.feature new file mode 100644 index 0000000..d7c3c79 --- /dev/null +++ b/features/fob_page_object_integration/fob_page_object_integration.feature @@ -0,0 +1,109 @@ +Feature: FriendsOfBehat/PageObjectExtension integration + + Background: + Given a working Symfony application with SymfonyExtension configured + And a Behat configuration containing: + """ + default: + extensions: + Behat\MinkExtension: + base_url: "http://localhost:8080/" + default_session: symfony + sessions: + symfony: + symfony: ~ + + suites: + default: + contexts: + - App\Tests\SomeContext + """ + And a feature file containing: + """ + Feature: + Scenario: + When I visit the homepage + Then I should see "Hello world!" on the page + """ + And a context file "tests/SomeContext.php" containing: + """ + homepage = $homepage; + } + + /** @When I visit the homepage */ + public function visitPage(): void + { + $this->homepage->open(); + } + + /** @Then I should see :content on the page */ + public function shouldSeeContentOnPage(string $content): void + { + assert(false !== strpos($this->homepage->getContent(), $content)); + } + } + """ + And a page file "tests/Homepage.php" containing: + """ + getDocument()->getContent(); + } + + protected function getUrl(array $urlParameters = []): string + { + return 'http://localhost:8080/hello-world'; + } + } + """ + + Scenario: Injecting page into the context + Given a YAML services file containing: + """ + services: + App\Tests\Homepage: + arguments: + - '@behat.mink.default_session' + - '@behat.mink.parameters' + + App\Tests\SomeContext: + public: true + arguments: + - '@App\Tests\Homepage' + """ + When I run Behat + Then it should pass + + Scenario: Autowiring and autoconfiguring page + Given a YAML services file containing: + """ + services: + _defaults: + autowire: true + autoconfigure: true + + App\Tests\Homepage: ~ + + App\Tests\SomeContext: ~ + """ + When I run Behat + Then it should pass