minor #105 Add integration with FriendsOfBehat/PageObjectExtension (pamil)
This PR was merged into the 2.1-dev branch.
Discussion
----------
Commits
-------
6d40a32f7c Add integration with FriendsOfBehat/PageObjectExtension
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
|
||||
final class SomeContext implements Context {
|
||||
private $homepage;
|
||||
|
||||
public function __construct(Homepage $homepage)
|
||||
{
|
||||
$this->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:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use FriendsOfBehat\PageObjectExtension\Page\Page;
|
||||
|
||||
final class Homepage extends Page
|
||||
{
|
||||
public function getContent(): string
|
||||
{
|
||||
return $this->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
|
||||
Reference in New Issue
Block a user