From 1993e5d305c047af08442695c2435229ba8319cd Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Tue, 16 May 2017 14:42:47 +1200 Subject: [PATCH] API Upgrade to use new AssetStore service name --- .travis.yml | 2 +- README.md | 4 +++- composer.json | 2 +- docs/webservice-mocking.md | 15 ++++++++------- src/Context/FixtureContext.php | 3 +-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 11ceb94..46b252e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.md b/README.md index 7026628..37e74ba 100644 --- a/README.md +++ b/README.md @@ -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']); diff --git a/composer.json b/composer.json index 7af591c..2e0cccb 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/docs/webservice-mocking.md b/docs/webservice-mocking.md index 3e3b749..d3810f2 100644 --- a/docs/webservice-mocking.md +++ b/docs/webservice-mocking.md @@ -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. \ No newline at end of file +which file to include, which is handled by the `getTestSessionState()` method. diff --git a/src/Context/FixtureContext.php b/src/Context/FixtureContext.php index a64fcd9..1b55843 100644 --- a/src/Context/FixtureContext.php +++ b/src/Context/FixtureContext.php @@ -761,12 +761,11 @@ class FixtureContext implements Context } /** - * * @return AssetStore */ protected function getAssetStore() { - return singleton('AssetStore'); + return Injector::inst()->get(AssetStore::class); } /**