MNT Travis shared config, use sminnee/phpunit

This commit is contained in:
Steve Boyd 2021-01-19 11:33:18 +13:00
parent 8940d2882d
commit 4d6bd1890c
8 changed files with 27 additions and 136 deletions

View File

@ -1,40 +1,4 @@
language: php version: ~> 1.0
dist: xenial import:
- silverstripe/silverstripe-travis-shared:config/provision/standard-jobs-range.yml
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

View File

@ -1,61 +0,0 @@
<?php
/*
* This file is part of the Behat/SilverStripeExtension
*
* (c) Michał Ochman <ochman.d.michal@gmail.com>
*
* 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(<<<STUB
<?php
/*
* This file is part of the SilverStripe-Behaviour-Testing-Framework
*
* (c) Michał Ochman <ochman.d.michal@gmail.com>
*
* 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;
}

View File

@ -22,7 +22,8 @@
], ],
"require": { "require": {
"php": ">=5.6", "php": ">=5.6",
"phpunit/phpunit": "^5.7", "sminnee/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^3",
"behat/behat": "^3.2", "behat/behat": "^3.2",
"behat/mink": "^1.7", "behat/mink": "^1.7",
"behat/mink-extension": "^2.1", "behat/mink-extension": "^2.1",
@ -34,11 +35,7 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"SilverStripe\\BehatExtension\\": "src/" "SilverStripe\\BehatExtension\\": "src/",
}
},
"autoload-dev": {
"psr-4": {
"SilverStripe\\BehatExtension\\Tests\\": "tests/php/" "SilverStripe\\BehatExtension\\Tests\\": "tests/php/"
} }
}, },

View File

@ -1,19 +0,0 @@
<?php
/*
* This file is part of the Behat/SilverStripeExtension
*
* (c) Michał Ochman <ochman.d.michal@gmail.com>
*
* 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;

17
phpcs.xml.dist Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="SilverStripe">
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>
<file>src</file>
<file>tests</file>
<!-- base rules are PSR-2 -->
<rule ref="PSR2" >
<!-- Current exclusions -->
<exclude name="PSR1.Methods.CamelCapsMethodName" />
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore" />
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
<exclude name="Generic.Files.LineLength.TooLong" />
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
</rule>
</ruleset>

View File

@ -1,5 +1,5 @@
<phpunit colors="true"> <phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
<testsuite name="Default"> <testsuite name="Default">
<directory>tests/php</directory> <directory>tests/php</directory>
</testsuite> </testsuite>
</phpunit> </phpunit>

View File

@ -87,7 +87,7 @@ abstract class SilverStripeContext extends MinkContext implements SilverStripeAw
*/ */
public function __construct(array $parameters = null) public function __construct(array $parameters = null)
{ {
if (!preg_match('/\\FeatureContext$/', get_class($this))) { if (!preg_match('#[\\\]FeatureContext$#', get_class($this))) {
throw new InvalidArgumentException( throw new InvalidArgumentException(
'Subclasses of SilverStripeContext must be named FeatureContext. Found "' . get_class($this) . '""' 'Subclasses of SilverStripeContext must be named FeatureContext. Found "' . get_class($this) . '""'
); );

View File

@ -11,18 +11,11 @@ use Behat\Mink\Element\Element;
use SilverStripe\BehatExtension\Tests\SilverStripeContextTest\FeatureContext; use SilverStripe\BehatExtension\Tests\SilverStripeContextTest\FeatureContext;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
class SilverStripeContextTest extends \PHPUnit_Framework_TestCase class SilverStripeContextTest extends SapphireTest
{ {
protected $backupGlobals = false; protected $backupGlobals = false;
public static function setUpBeforeClass()
{
// Bootstrap test environment
parent::setUpBeforeClass();
SapphireTest::start();
}
/** /**
* @expectedException \LogicException * @expectedException \LogicException
* @expectedExceptionMessage Cannot find 'region_map' in the behat.yml * @expectedExceptionMessage Cannot find 'region_map' in the behat.yml