mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
Merge pull request #157 from open-sausages/pulls/fix-fqn-services
API Upgrade to use new AssetStore service name
This commit is contained in:
commit
18e6b9297e
@ -22,7 +22,7 @@ matrix:
|
||||
before_script:
|
||||
- composer validate
|
||||
- composer install --dev --prefer-dist
|
||||
- composer require silverstripe/config:1.0.x-dev silverstripe/framework:4.0.x-dev --prefer-dist
|
||||
- composer require --update-with-dependencies silverstripe/framework:4.0.x-dev silverstripe/siteconfig:4.0.x-dev silverstripe/config:1.0.x-dev silverstripe/assets:1.0.x-dev silverstripe/versioned:1.0.x-dev --prefer-dist
|
||||
- if [[ $PHPCS_TEST ]]; then pyrus install pear/PHP_CodeSniffer; fi
|
||||
- phpenv rehash
|
||||
|
||||
|
@ -302,7 +302,9 @@ of the `TestSessionEnvironment`, in order to share it with Behat CLI.
|
||||
|
||||
Example: Retrieve the currently logged-in member
|
||||
|
||||
$env = Injector::inst()->get('TestSessionEnvironment');
|
||||
use SilverStripe\TestSession\TestsessionEnvironment;
|
||||
|
||||
$env = Injector::inst()->get(TestSessionEnvironment::class);
|
||||
$state = $env->getState();
|
||||
if(isset($state->session['loggedInAs'])) {
|
||||
$member = \Member::get()->byID($state->session['loggedInAs']);
|
||||
|
@ -28,7 +28,7 @@
|
||||
"behat/mink-extension": "^2.1",
|
||||
"behat/mink-selenium2-driver": "^1.3",
|
||||
"symfony/dom-crawler": "^3",
|
||||
"silverstripe/testsession": "2.0.0-alpha6",
|
||||
"silverstripe/testsession": "~2.0.0@alpha",
|
||||
"silverstripe/framework": "^4@dev",
|
||||
"symfony/finder": "^3.2"
|
||||
},
|
||||
|
@ -36,7 +36,7 @@ There's several parts to this:
|
||||
How the pieces fit together is best illustrated as an example.
|
||||
We'll create a currency rate viewer,
|
||||
based on a [free online webservice](http://www.webservicex.net/CurrencyConvertor.asmx?WSDL).
|
||||
The example assumes you have a basic knowledge of [Behat](http://behat.org) and
|
||||
The example assumes you have a basic knowledge of [Behat](http://behat.org) and
|
||||
the [Behat SilverStripe extension](https://github.com/silverstripe-labs/silverstripe-behat-extension).
|
||||
Let's explain the feature through the Gherkin language as Behat steps:
|
||||
|
||||
@ -81,7 +81,7 @@ class CurrencyGateway {
|
||||
The controller logic for this is really simple.
|
||||
We'll stick to request parameters and plaintext responses just to keep the code
|
||||
manageable, a more realistic controller would likely use a form and HTML formatted responses.
|
||||
Its important that our `CurrencyGateway` is instanciated through the
|
||||
Its important that our `CurrencyGateway` is instanciated through the
|
||||
use of [dependency injection](http://doc.silverstripe.org/framework/en/trunk/reference/injector),
|
||||
so we can replace its implementation with a mock object later.
|
||||
|
||||
@ -114,6 +114,7 @@ Open the already generated `FeatureContext.php` file and add the following code.
|
||||
|
||||
```php
|
||||
// mysite/tests/behat/features/bootstrap/Context/FeatureContext.php
|
||||
use namespace SilverStripe\TestSession\TestSessionStubCodeWriter;
|
||||
class FeatureContext extends SilverStripeContext {
|
||||
|
||||
protected $stubCodeWriter;
|
||||
@ -121,7 +122,7 @@ class FeatureContext extends SilverStripeContext {
|
||||
public function __construct() {
|
||||
// ...
|
||||
|
||||
$this->stubCodeWriter = Injector::inst()->get('TestSessionStubCodeWriter');
|
||||
$this->stubCodeWriter = Injector::inst()->get(TestSessionStubCodeWriter::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -169,7 +170,7 @@ avoid side effects (hence the methods tagged with `@BeforeScenario` and `@AfterS
|
||||
A useful pattern here is to set up objects via `@BeforeScenario`, in our case
|
||||
a mock gateway in `initTestSessionStubCode()`. This object can be used in later
|
||||
step definitions like `stepGivenACurrency()` to mock webservice responses
|
||||
without any further setup or duplication.
|
||||
without any further setup or duplication.
|
||||
|
||||
The generated code which is executed on every web request reads:
|
||||
|
||||
@ -180,8 +181,8 @@ Injector::inst()->registerService($mock, 'CurrencyGateway');
|
||||
Phockito::when($mock->convert('EUR','NZD'))->return(1.56);
|
||||
```
|
||||
|
||||
Keep in mind escaping rules for PHP when placed in a heredoc block:
|
||||
Variables are resolved when the string is constructed, unless escaped with a backslash.
|
||||
Keep in mind escaping rules for PHP when placed in a heredoc block:
|
||||
Variables are resolved when the string is constructed, unless escaped with a backslash.
|
||||
|
||||
The test session started in your browser by Selenium/Behat needs to know
|
||||
which file to include, which is handled by the `getTestSessionState()` method.
|
||||
which file to include, which is handled by the `getTestSessionState()` method.
|
||||
|
@ -761,12 +761,11 @@ class FixtureContext implements Context
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return AssetStore
|
||||
*/
|
||||
protected function getAssetStore()
|
||||
{
|
||||
return singleton('AssetStore');
|
||||
return Injector::inst()->get(AssetStore::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user