From beda9e158fefa41aac6cd59c266da247251eb965 Mon Sep 17 00:00:00 2001
From: Damian Mooyman
Date: Fri, 21 Apr 2017 11:58:27 +1200
Subject: [PATCH] API Namespace and update for ss 4.0
---
.editorconfig | 2 +-
.travis.yml | 26 +++++----
.upgrade.yml | 6 ++
_config.php | 7 +--
_config/_config.yml | 8 ---
_config/processors.yml | 8 +++
_config/services.yml | 8 +++
{javascript => client/js}/testsession.js | 0
{css => client/styles}/styles.css | 0
composer.json | 56 +++++++++++--------
phpcs.xml.dist | 10 ++++
{code => src}/TestSessionController.php | 17 +++---
{code => src}/TestSessionEnvironment.php | 31 ++++++----
{code => src}/TestSessionRequestFilter.php | 17 +++---
{code => src}/TestSessionStubCodeWriter.php | 6 +-
templates/Includes/TestSession_State.ss | 8 +--
templates/TestSession_end.ss | 2 +-
templates/TestSession_inprogress.ss | 2 +-
templates/TestSession_start.ss | 2 +-
.../TestSessionStubCodeWriterTest.php | 3 +
20 files changed, 137 insertions(+), 82 deletions(-)
create mode 100644 .upgrade.yml
delete mode 100644 _config/_config.yml
create mode 100644 _config/processors.yml
create mode 100644 _config/services.yml
rename {javascript => client/js}/testsession.js (100%)
rename {css => client/styles}/styles.css (100%)
create mode 100644 phpcs.xml.dist
rename {code => src}/TestSessionController.php (96%)
rename {code => src}/TestSessionEnvironment.php (96%)
rename {code => src}/TestSessionRequestFilter.php (83%)
rename {code => src}/TestSessionStubCodeWriter.php (98%)
rename tests/{unit => }/TestSessionStubCodeWriterTest.php (93%)
diff --git a/.editorconfig b/.editorconfig
index 47ae637..7d56e29 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -10,7 +10,7 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
-[{*.yml,package.json}]
+[{*.yml,*.json}]
indent_size = 2
# The indent size used in the package.json file cannot be changed:
diff --git a/.travis.yml b/.travis.yml
index 84d2a6b..a6d3823 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,28 +1,34 @@
-# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details
-
language: php
sudo: false
-php:
- - 5.5
-
env:
- matrix:
- - DB=MYSQL CORE_RELEASE=master
+ global:
+ - COMPOSER_ROOT_VERSION=2.0.x-dev
+ - CORE_RELEASE=master
matrix:
include:
- php: 5.6
- env: DB=PGSQL CORE_RELEASE=master
+ env:
+ - PHPUNIT_TEST=1
+ - DB=PGSQL
- php: 5.6
- env: DB=MYSQL CORE_RELEASE=master
+ env:
+ - PHPUNIT_TEST=1
+ - DB=MYSQL
+ - php: 5.6
+ env:
+ - PHPCS_TEST=1
+ - DB=MYSQL
before_script:
+ - if [[ $PHPCS_TEST ]]; then pyrus install pear/PHP_CodeSniffer; fi
- phpenv rehash
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
- cd ~/builds/ss
script:
- - vendor/bin/phpunit testsession/tests/unit/
+ - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit testsession/tests/; fi
+ - if [[ $PHPCS_TEST ]]; then (cd testsession && composer run-script lint); fi
diff --git a/.upgrade.yml b/.upgrade.yml
new file mode 100644
index 0000000..91af6bd
--- /dev/null
+++ b/.upgrade.yml
@@ -0,0 +1,6 @@
+mappings:
+ TestSessionController: SilverStripe\TestSession\TestSessionController
+ TestSessionEnvironment: SilverStripe\TestSession\TestSessionEnvironment
+ TestSessionRequestFilter: SilverStripe\TestSession\TestSessionRequestFilter
+ TestSessionStubCodeWriter: SilverStripe\TestSession\TestSessionStubCodeWriter
+ TestSessionStubCodeWriterTest: SilverStripe\TestSession\Tests\TestSessionStubCodeWriterTest
diff --git a/_config.php b/_config.php
index 237dd1a..7bd9a34 100644
--- a/_config.php
+++ b/_config.php
@@ -1,11 +1,10 @@
get('TestSessionEnvironment')->loadFromFile();
+TestSessionEnvironment::singleton()->loadFromFile();
/**
* This closure will run every time a Resque_Event is forked (just before it is forked, so it applies to the parent
@@ -20,7 +19,7 @@ if(class_exists('Resque_Event') && class_exists('SSResqueRun')) {
// calling {@link TestSessionEnvironment::loadFromFile()}.
DB::connect($databaseConfig);
- $testEnv = Injector::inst()->get('TestSessionEnvironment');
+ $testEnv = TestSessionEnvironment::singleton();
if($testEnv->isRunningTests()) {
$testEnv->loadFromFile();
diff --git a/_config/_config.yml b/_config/_config.yml
deleted file mode 100644
index b3afead..0000000
--- a/_config/_config.yml
+++ /dev/null
@@ -1,8 +0,0 @@
----
-Name: testsessionprocessors
----
-SilverStripe\Core\Injector\Injector:
- RequestProcessor:
- properties:
- filters:
- - '%$TestSessionRequestFilter'
diff --git a/_config/processors.yml b/_config/processors.yml
new file mode 100644
index 0000000..d52ef3c
--- /dev/null
+++ b/_config/processors.yml
@@ -0,0 +1,8 @@
+---
+Name: testsessionprocessors
+---
+SilverStripe\Core\Injector\Injector:
+ SilverStripe\Control\RequestProcessor:
+ properties:
+ filters:
+ - '%$SilverStripe\TestSession\TestSessionRequestFilter'
diff --git a/_config/services.yml b/_config/services.yml
new file mode 100644
index 0000000..69c915f
--- /dev/null
+++ b/_config/services.yml
@@ -0,0 +1,8 @@
+---
+Name: testsessionservices
+---
+SilverStripe\Core\Injector\Injector:
+ SilverStripe\TestSession\TestSessionEnvironment:
+ class: SilverStripe\TestSession\TestSessionEnvironment
+ # shorthand alias for FQN
+ TestSessionEnvironment: %$SilverStripe\TestSession\TestSessionEnvironment
diff --git a/javascript/testsession.js b/client/js/testsession.js
similarity index 100%
rename from javascript/testsession.js
rename to client/js/testsession.js
diff --git a/css/styles.css b/client/styles/styles.css
similarity index 100%
rename from css/styles.css
rename to client/styles/styles.css
diff --git a/composer.json b/composer.json
index 1528c21..9627fb2 100644
--- a/composer.json
+++ b/composer.json
@@ -1,24 +1,36 @@
{
- "name": "silverstripe/testsession",
- "type": "silverstripe-module",
- "description": "Support module for browser-based test sessions, e.g. for Behat behaviour testing",
- "homepage": "http://silverstripe.org",
- "license": "BSD-3-Clause",
- "keywords": ["silverstripe", "testing"],
- "authors": [
- {
- "name": "SilverStripe",
- "homepage": "http://silverstripe.com"
- }
- ],
- "require": {
- "composer/installers": "*",
- "silverstripe/framework": "^4@dev"
- },
- "extra": {
- "branch-alias": {
- "dev-master": "2.0.x-dev"
- }
- },
- "minimum-stability": "dev"
+ "name": "silverstripe/testsession",
+ "type": "silverstripe-module",
+ "description": "Support module for browser-based test sessions, e.g. for Behat behaviour testing",
+ "homepage": "http://silverstripe.org",
+ "license": "BSD-3-Clause",
+ "keywords": [
+ "silverstripe",
+ "testing"
+ ],
+ "authors": [
+ {
+ "name": "SilverStripe",
+ "homepage": "http://silverstripe.com"
+ }
+ ],
+ "require": {
+ "composer/installers": "*",
+ "silverstripe/framework": "^4@dev"
+ },
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.x-dev"
+ }
+ },
+ "scripts": {
+ "lint": "phpcs -s src/ tests/"
+ },
+ "autoload": {
+ "psr-4": {
+ "SilverStripe\\TestSession\\": "src/",
+ "SilverStripe\\TestSession\\Tests\\": "tests/"
+ }
+ },
+ "minimum-stability": "dev"
}
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
new file mode 100644
index 0000000..5a8fb14
--- /dev/null
+++ b/phpcs.xml.dist
@@ -0,0 +1,10 @@
+
+
+ CodeSniffer ruleset for SilverStripe coding conventions.
+
+
+
+
+
+
+
diff --git a/code/TestSessionController.php b/src/TestSessionController.php
similarity index 96%
rename from code/TestSessionController.php
rename to src/TestSessionController.php
index b26410d..9ec1112 100644
--- a/code/TestSessionController.php
+++ b/src/TestSessionController.php
@@ -1,5 +1,7 @@
environment = Injector::inst()->get('TestSessionEnvironment');
+ $this->environment = TestSessionEnvironment::singleton();
}
public function init()
@@ -75,7 +80,7 @@ class TestSessionController extends Controller
}
Requirements::javascript('http://code.jquery.com/jquery-1.7.2.min.js');
- Requirements::javascript('testsession/javascript/testsession.js');
+ Requirements::javascript('testsession/client/js/testsession.js');
}
public function Link($action = null)
@@ -104,7 +109,7 @@ class TestSessionController extends Controller
if (!empty($params['globalTestSession'])) {
$id = null;
} else {
- $generator = Injector::inst()->get('SilverStripe\\Security\\RandomGenerator');
+ $generator = Injector::inst()->get(RandomGenerator::class);
$id = substr($generator->randomToken(), 0, 10);
Session::set('TestSessionId', $id);
}
@@ -358,12 +363,6 @@ class TestSessionController extends Controller
return SapphireTest::using_temp_db();
}
- public function setState($data)
- {
- Deprecation::notice('3.1', 'TestSessionController::setState() is no longer used, please use '
- . 'TestSessionEnvironment instead.');
- }
-
/**
* @return ArrayList
*/
diff --git a/code/TestSessionEnvironment.php b/src/TestSessionEnvironment.php
similarity index 96%
rename from code/TestSessionEnvironment.php
rename to src/TestSessionEnvironment.php
index 4a0878e..a1e837d 100644
--- a/code/TestSessionEnvironment.php
+++ b/src/TestSessionEnvironment.php
@@ -1,16 +1,23 @@
constructExtensions();
if ($id) {
$this->id = $id;
@@ -288,11 +298,10 @@ class TestSessionEnvironment extends Object
$sql = file_get_contents($path);
// Split into individual query commands, removing comments
- $sqlCmds = array_filter(
- preg_split('/;\n/',
- preg_replace(array('/^$\n/m', '/^(\/|#).*$\n/m'), '', $sql)
- )
- );
+ $sqlCmds = array_filter(preg_split(
+ '/;\n/',
+ preg_replace(array('/^$\n/m', '/^(\/|#).*$\n/m'), '', $sql)
+ ));
// Execute each query
foreach ($sqlCmds as $sqlCmd) {
@@ -380,7 +389,7 @@ class TestSessionEnvironment extends Object
$state = $this->getState();
$dbConn = DB::get_schema();
$dbExists = $dbConn->databaseExists($state->database);
- if($dbExists) {
+ if ($dbExists) {
// Clean up temp database
$dbConn->dropDatabase($state->database);
file_put_contents('php://stdout', "Deleted temp database: $state->database" . PHP_EOL);
diff --git a/code/TestSessionRequestFilter.php b/src/TestSessionRequestFilter.php
similarity index 83%
rename from code/TestSessionRequestFilter.php
rename to src/TestSessionRequestFilter.php
index 70ea3d3..bbf3bb3 100644
--- a/code/TestSessionRequestFilter.php
+++ b/src/TestSessionRequestFilter.php
@@ -1,24 +1,24 @@
testSessionEnvironment = Injector::inst()->get('TestSessionEnvironment');
+ $this->testSessionEnvironment = TestSessionEnvironment::singleton();
}
public function preRequest(HTTPRequest $request, Session $session, DataModel $model)
{
- if (!$this->testSessionEnvironment->isRunningTests()) {
+ $isRunningTests = $this->testSessionEnvironment->isRunningTests();
+ if (!$isRunningTests) {
return;
}
@@ -45,8 +46,8 @@ class TestSessionRequestFilter implements RequestFilter
// Register mailer
if (isset($testState->mailer)) {
$mailer = $testState->mailer;
- Injector::inst()->registerService(new $mailer(), 'SilverStripe\\Control\\Email\\Mailer');
- Config::inst()->update("SilverStripe\\Control\\Email\\Email", "send_all_emails_to", null);
+ Injector::inst()->registerService(new $mailer(), Mailer::class);
+ Email::config()->set("send_all_emails_to", null);
}
// Allows inclusion of a PHP file, usually with procedural commands
diff --git a/code/TestSessionStubCodeWriter.php b/src/TestSessionStubCodeWriter.php
similarity index 98%
rename from code/TestSessionStubCodeWriter.php
rename to src/TestSessionStubCodeWriter.php
index f442a6c..b1a476c 100644
--- a/code/TestSessionStubCodeWriter.php
+++ b/src/TestSessionStubCodeWriter.php
@@ -1,11 +1,13 @@
+<% if $State %>
Show testing state
- <% loop State %>
- - $Name: $Value
+ <% loop $State %>
+ - $Name: $Value
<% end_loop %>
-<% end_if %>
\ No newline at end of file
+<% end_if %>
diff --git a/templates/TestSession_end.ss b/templates/TestSession_end.ss
index d3c3516..b630505 100644
--- a/templates/TestSession_end.ss
+++ b/templates/TestSession_end.ss
@@ -5,7 +5,7 @@
<% base_tag %>
$MetaTags
<% require css('framework/client/dist/styles/debug.css') %>
- <% require css('testsession/css/styles.css') %>
+ <% require css('testsession/client/styles/styles.css') %>
diff --git a/templates/TestSession_inprogress.ss b/templates/TestSession_inprogress.ss
index 31d78f1..f629b62 100644
--- a/templates/TestSession_inprogress.ss
+++ b/templates/TestSession_inprogress.ss
@@ -5,7 +5,7 @@
<% base_tag %>
$MetaTags
<% require css('framework/client/dist/styles/debug.css') %>
- <% require css('testsession/css/styles.css') %>
+ <% require css('testsession/client/styles/styles.css') %>
diff --git a/templates/TestSession_start.ss b/templates/TestSession_start.ss
index 2498c0b..ee6a893 100644
--- a/templates/TestSession_start.ss
+++ b/templates/TestSession_start.ss
@@ -5,7 +5,7 @@
<% base_tag %>
$MetaTags
<% require css('framework/client/dist/styles/debug.css') %>
- <% require css('testsession/css/styles.css') %>
+ <% require css('testsession/client/styles/styles.css') %>
diff --git a/tests/unit/TestSessionStubCodeWriterTest.php b/tests/TestSessionStubCodeWriterTest.php
similarity index 93%
rename from tests/unit/TestSessionStubCodeWriterTest.php
rename to tests/TestSessionStubCodeWriterTest.php
index 4f2a982..96acf7c 100644
--- a/tests/unit/TestSessionStubCodeWriterTest.php
+++ b/tests/TestSessionStubCodeWriterTest.php
@@ -1,6 +1,9 @@