From bae6d3056140cb92a12db9aa22b4b31ec7b14f7a Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 24 Jun 2020 12:52:21 +1200 Subject: [PATCH 1/2] Update travis --- .travis.yml | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6366014..a690712 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,35 +1,36 @@ language: php -dist: precise +dist: xenial -sudo: false +services: + - mysql + - postgresql cache: directories: - $HOME/.composer/cache/files -php: - - 5.6 - -env: - matrix: - - PHPUNIT_TEST=1 - - PHPCS_TEST=1 - matrix: include: - php: 5.6 - env: PHPUNIT_TEST=1 - - php: 7.0 - env: PHPUNIT_TEST=1 - - php: 7.1.2 - env: PHPUNIT_TEST=1 + env: DB=MYSQL RECIPE_VERSION=4.4.x-dev PHPUNIT_TEST=1 PHPCS_TEST=1 + - php: 7.1 + env: DB=MYSQL RECIPE_VERSION=4.5.x-dev PHPUNIT_TEST=1 PDO=1 + - php: 7.2 + env: DB=MYSQL RECIPE_VERSION=4.6.x-dev PHPUNIT_TEST=1 + - php: 7.3 + env: DB=MYSQL RECIPE_VERSION=4.6.x-dev PHPUNIT_TEST=1 + - php: 7.4 + env: DB=MYSQL RECIPE_VERSION=4.x-dev PHPUNIT_TEST=1 before_script: - export PATH=~/.composer/vendor/bin:$PATH + - echo 'memory_limit = 2G' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - composer validate - composer install --dev --prefer-dist - - composer require --prefer-dist --no-update silverstripe/recipe-core:1.0.x-dev + - composer require --prefer-dist --no-update silverstripe/recipe-cms:$RECIPE_VERSION + # Fix for running phpunit 5 on php 7.4+ + - composer require --no-update sminnee/phpunit-mock-objects:^3.4.7 - composer update - if [[ $PHPCS_TEST ]]; then composer global require squizlabs/php_codesniffer:^3 --prefer-dist --no-interaction --no-progress --no-suggest -o; fi - phpenv rehash From 4d6bd1890cf1f9e6eed17cb32dc17f04ee92e6dc Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 19 Jan 2021 11:33:18 +1300 Subject: [PATCH 2/2] MNT Travis shared config, use sminnee/phpunit --- .travis.yml | 42 ++---------------- build.php | 61 --------------------------- composer.json | 9 ++-- init.php | 19 --------- phpcs.xml.dist | 17 ++++++++ phpunit.xml.dist | 4 +- src/Context/SilverStripeContext.php | 2 +- tests/php/SilverStripeContextTest.php | 9 +--- 8 files changed, 27 insertions(+), 136 deletions(-) delete mode 100644 build.php delete mode 100644 init.php create mode 100644 phpcs.xml.dist diff --git a/.travis.yml b/.travis.yml index a690712..c244c3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,40 +1,4 @@ -language: php +version: ~> 1.0 -dist: xenial - -services: - - mysql - - postgresql - -cache: - directories: - - $HOME/.composer/cache/files - -matrix: - include: - - php: 5.6 - env: DB=MYSQL RECIPE_VERSION=4.4.x-dev PHPUNIT_TEST=1 PHPCS_TEST=1 - - php: 7.1 - env: DB=MYSQL RECIPE_VERSION=4.5.x-dev PHPUNIT_TEST=1 PDO=1 - - php: 7.2 - env: DB=MYSQL RECIPE_VERSION=4.6.x-dev PHPUNIT_TEST=1 - - php: 7.3 - env: DB=MYSQL RECIPE_VERSION=4.6.x-dev PHPUNIT_TEST=1 - - php: 7.4 - env: DB=MYSQL RECIPE_VERSION=4.x-dev PHPUNIT_TEST=1 - -before_script: - - export PATH=~/.composer/vendor/bin:$PATH - - echo 'memory_limit = 2G' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - - composer validate - - composer install --dev --prefer-dist - - composer require --prefer-dist --no-update silverstripe/recipe-cms:$RECIPE_VERSION - # Fix for running phpunit 5 on php 7.4+ - - composer require --no-update sminnee/phpunit-mock-objects:^3.4.7 - - composer update - - if [[ $PHPCS_TEST ]]; then composer global require squizlabs/php_codesniffer:^3 --prefer-dist --no-interaction --no-progress --no-suggest -o; fi - - phpenv rehash - -script: - - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/php; fi - - if [[ $PHPCS_TEST ]]; then composer run-script lint; fi +import: + - silverstripe/silverstripe-travis-shared:config/provision/standard-jobs-range.yml diff --git a/build.php b/build.php deleted file mode 100644 index 8bd98ff..0000000 --- a/build.php +++ /dev/null @@ -1,61 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -$filename = 'silverstripe_extension.phar'; - -if (file_exists($filename)) { - unlink($filename); -} - -$phar = new \Phar($filename, 0, 'extension.phar'); -$phar->setSignatureAlgorithm(\Phar::SHA1); -$phar->startBuffering(); - -foreach (findFiles('src') as $path) { - $phar->addFromString($path, file_get_contents(__DIR__ . '/' . $path)); -} - -$phar->addFromString('init.php', file_get_contents(__DIR__ . '/init.php')); - -$phar->setStub(<< - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -Phar::mapPhar('extension.phar'); - -return require 'phar://extension.phar/init.php'; - -__HALT_COMPILER(); -STUB -); -$phar->stopBuffering(); - -function findFiles($dir) -{ - $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::CHILD_FIRST); - - $files = array(); - foreach ($iterator as $path) { - if ($path->isFile()) { - $files[] = $path->getPath() . DIRECTORY_SEPARATOR . $path->getFilename(); - } - } - - return $files; -} diff --git a/composer.json b/composer.json index 7451eee..b34633c 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ ], "require": { "php": ">=5.6", - "phpunit/phpunit": "^5.7", + "sminnee/phpunit": "^5.7", + "squizlabs/php_codesniffer": "^3", "behat/behat": "^3.2", "behat/mink": "^1.7", "behat/mink-extension": "^2.1", @@ -34,11 +35,7 @@ }, "autoload": { "psr-4": { - "SilverStripe\\BehatExtension\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { + "SilverStripe\\BehatExtension\\": "src/", "SilverStripe\\BehatExtension\\Tests\\": "tests/php/" } }, diff --git a/init.php b/init.php deleted file mode 100644 index f3021e5..0000000 --- a/init.php +++ /dev/null @@ -1,19 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -spl_autoload_register(function ($class) { - if (false !== strpos($class, 'SilverStripe\\BehatExtension')) { - require_once(__DIR__ . '/src/' . str_replace('\\', '/', $class) . '.php'); - return true; - } -}, true, false); - -return new SilverStripe\BehatExtension\Extension; diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..ddbffb0 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,17 @@ + + + CodeSniffer ruleset for SilverStripe coding conventions. + + src + tests + + + + + + + + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2e0ac12..fbea586 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,5 @@ - + tests/php - + diff --git a/src/Context/SilverStripeContext.php b/src/Context/SilverStripeContext.php index e666f54..242ef89 100644 --- a/src/Context/SilverStripeContext.php +++ b/src/Context/SilverStripeContext.php @@ -87,7 +87,7 @@ abstract class SilverStripeContext extends MinkContext implements SilverStripeAw */ public function __construct(array $parameters = null) { - if (!preg_match('/\\FeatureContext$/', get_class($this))) { + if (!preg_match('#[\\\]FeatureContext$#', get_class($this))) { throw new InvalidArgumentException( 'Subclasses of SilverStripeContext must be named FeatureContext. Found "' . get_class($this) . '""' ); diff --git a/tests/php/SilverStripeContextTest.php b/tests/php/SilverStripeContextTest.php index 9f3c96c..e9b8c1a 100644 --- a/tests/php/SilverStripeContextTest.php +++ b/tests/php/SilverStripeContextTest.php @@ -11,18 +11,11 @@ use Behat\Mink\Element\Element; use SilverStripe\BehatExtension\Tests\SilverStripeContextTest\FeatureContext; use SilverStripe\Dev\SapphireTest; -class SilverStripeContextTest extends \PHPUnit_Framework_TestCase +class SilverStripeContextTest extends SapphireTest { protected $backupGlobals = false; - public static function setUpBeforeClass() - { - // Bootstrap test environment - parent::setUpBeforeClass(); - SapphireTest::start(); - } - /** * @expectedException \LogicException * @expectedExceptionMessage Cannot find 'region_map' in the behat.yml