Skip to content

Commit

Permalink
API Upgrade SapphireTest to work with phpunit 9
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jul 23, 2021
1 parent 507c70e commit eb91ac6
Show file tree
Hide file tree
Showing 131 changed files with 4,037 additions and 2,030 deletions.
58 changes: 31 additions & 27 deletions .travis.yml
@@ -1,7 +1,8 @@
version: ~> 1.0

import:
- silverstripe/silverstripe-travis-shared:config/provision/standard.yml
#- silverstripe/silverstripe-travis-shared:config/provision/standard.yml
- silverstripe/silverstripe-travis-shared:config/provision/self.yml

env:
global:
Expand All @@ -15,41 +16,44 @@ jobs:
- php: 7.1
env:
- DB=MYSQL
- REQUIRE_INSTALLER="$REQUIRE_RECIPE"
- PHPCS_TEST=1
#- REQUIRE_INSTALLER="$REQUIRE_RECIPE"
#- PHPCS_TEST=1
- PHPUNIT_TEST=1
- PHPUNIT_SUITE="framework"
- COMPOSER_INSTALL_ARG="--prefer-lowest"
- php: 7.2
env:
- DB=PGSQL
- PDO=1
- REQUIRE_INSTALLER="$REQUIRE_RECIPE"
- PHPUNIT_TEST=1
- PHPUNIT_TEST="framework"
- php: 7.3
env:
- DB=MYSQL
- PDO=1
- REQUIRE_INSTALLER="$REQUIRE_RECIPE"
- PHPUNIT_TEST=1
- PHPUNIT_SUITE="framework"
- php: 7.3
env:
- DB=MYSQL
- REQUIRE_INSTALLER="$REQUIRE_RECIPE"
- PHPUNIT_TEST=1
- PHPUNIT_SUITE="cms"
# - COMPOSER_INSTALL_ARG="--prefer-lowest"
# - php: 7.2
# env:
# - DB=PGSQL
# - PDO=1
# - REQUIRE_INSTALLER="$REQUIRE_RECIPE"
# - PHPUNIT_TEST=1
# - PHPUNIT_TEST="framework"
# - php: 7.3
# env:
# - DB=MYSQL
# - PDO=1
# - REQUIRE_INSTALLER="$REQUIRE_RECIPE"
# - PHPUNIT_TEST=1
# - PHPUNIT_SUITE="framework"
# - REQUIRE_RECIPE_TESTING="dev-two"
# - php: 7.3
# env:
# - DB=MYSQL
# - REQUIRE_INSTALLER="$REQUIRE_RECIPE"
# - PHPUNIT_TEST=1
# - PHPUNIT_SUITE="cms"
# - REQUIRE_RECIPE_TESTING="dev-two"
- php: 7.4
env:
- DB=MYSQL
- REQUIRE_INSTALLER="$REQUIRE_RECIPE"
# - REQUIRE_INSTALLER="$REQUIRE_RECIPE"
- PHPUNIT_TEST=1
- PHPUNIT_SUITE="framework"
- REQUIRE_RECIPE_TESTING="dev-two"
- php: nightly
env:
- DB=MYSQL
- REQUIRE_INSTALLER="$REQUIRE_RECIPE"
# - REQUIRE_INSTALLER="$REQUIRE_RECIPE"
- PHPUNIT_TEST=1
- PHPUNIT_SUITE="framework"
- COMPOSER_INSTALL_ARG="--ignore-platform-reqs"
- REQUIRE_RECIPE_TESTING="dev-two"
75 changes: 70 additions & 5 deletions composer.json
@@ -1,5 +1,6 @@
{
"name": "silverstripe/framework",
"version": "4.99.99",
"type": "silverstripe-vendormodule",
"description": "The SilverStripe framework",
"homepage": "http://silverstripe.org",
Expand Down Expand Up @@ -30,8 +31,8 @@
"monolog/monolog": "~1.16",
"nikic/php-parser": "^3 || ^4",
"psr/container": "1.0.0",
"silverstripe/config": "^1@dev",
"silverstripe/assets": "^1@dev",
"silverstripe/config": "dev-pulls/1/sapphire-test-nine as 1.8.0",
"silverstripe/assets": "dev-pulls/1/sapphire-test-nine as 1.8.0",
"silverstripe/vendor-plugin": "^1.4",
"sminnee/callbacklist": "^0.1",
"swiftmailer/swiftmailer": "~5.4",
Expand All @@ -52,18 +53,82 @@
"ext-xml": "*"
},
"require-dev": {
"sminnee/phpunit": "^5.7.29",
"sminnee/phpunit-mock-objects": "^3.4.9",
"silverstripe/versioned": "^1",
"silverstripe/recipe-testing": "dev-one || dev-two",
"dms/phpunit-arraysubset-asserts": "^0.3.0",
"silverstripe/versioned": "dev-pulls/1/sapphire-test-nine as 1.8.0",
"squizlabs/php_codesniffer": "^3.5"
},
"repositories": [
{
"type": "package",
"package": {
"description": "removed behat-extension from require which includes sminnee/phpunit. removed silverstripe/serve which does not allow php8",
"version": "dev-two",
"dist": {
"url": "https://github.com/silverstripe/recipe-testing/archive/f1299bc6cd7db134d4c873cbddf1aa104f46cabb.zip",
"type": "zip"
},
"name": "silverstripe/recipe-testing",
"type": "silverstripe-recipe",
"require": {
"silverstripe/recipe-plugin": "^1",
"phpunit/phpunit": "^9",
"squizlabs/php_codesniffer": "^3"
},
"extra": {
"project-files": [
"behat.yml",
"*.xml.dist"
]
},
"minimum-stability": "dev",
"prefer-stable": true
}
},
{
"type": "package",
"package": {
"description": "require-dev use silverstripe/recipe-testing instead of phpunit",
"name": "silverstripe/vendor-plugin",
"version": "1.4.99",
"dist": {
"url": "https://github.com/silverstripe/vendor-plugin/archive/bfd57780149fb12d1ddf0082c89b55662b569329.zip",
"type": "zip"
},
"type": "composer-plugin",
"autoload": {
"psr-4": {
"SilverStripe\\VendorPlugin\\": "src/",
"SilverStripe\\VendorPlugin\\Tests\\": "tests/"
}
},
"extra": {
"class": "SilverStripe\\VendorPlugin\\VendorPlugin"
},
"require": {
"composer/installers": "^1.4",
"composer-plugin-api": "^1.1 || ^2",
"php": "^7.1 || ^8"
},
"require-dev": {
"silverstripe/recipe-testing": "dev-one || dev-two",
"squizlabs/php_codesniffer": "^3"
}
}
}
],
"provide": {
"psr/container-implementation": "1.0.0"
},
"extra": {
"expose": [
"client/images",
"client/styles"
],
"project-files-installed": [
"behat.yml",
"phpcs.xml.dist",
"phpunit.xml.dist"
]
},
"autoload": {
Expand Down
20 changes: 11 additions & 9 deletions phpunit.xml.dist
Expand Up @@ -4,15 +4,17 @@ Standard module phpunit configuration.
Requires PHPUnit ^5.7
-->
<phpunit bootstrap="tests/bootstrap.php" colors="true">
<testsuite name="Default">
<directory>tests/php</directory>
</testsuite>
<testsuite name="framework">
<directory>tests/php</directory>
</testsuite>
<testsuite name="cms">
<directory>vendor/silverstripe/cms/tests</directory>
</testsuite>
<testsuites>
<testsuite name="Default">
<directory>tests/php</directory>
</testsuite>
<testsuite name="framework">
<directory>tests/php</directory>
</testsuite>
<testsuite name="cms">
<directory>vendor/silverstripe/cms/tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">.</directory>
Expand Down
26 changes: 15 additions & 11 deletions src/Dev/Constraint/SSListContains.php
Expand Up @@ -2,22 +2,24 @@

namespace SilverStripe\Dev\Constraint;

use PHPUnit_Framework_Constraint;
use PHPUnit_Framework_ExpectationFailedException;
// use PHPUnit_Framework_Constraint;
use PHPUnit\Framework\Constraint\Constraint;
// use PHPUnit_Framework_ExpectationFailedException;
use PHPUnit\Framework\ExpectationFailedException;
use SilverStripe\Dev\SSListExporter;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\SS_List;
use SilverStripe\View\ViewableData;

if (!class_exists(PHPUnit_Framework_Constraint::class)) {
if (!class_exists(Constraint::class)) {
return;
}

/**
* Constraint for checking if a SS_List contains items matching the given
* key-value pairs.
*/
class SSListContains extends PHPUnit_Framework_Constraint implements TestOnly
class SSListContains extends Constraint implements TestOnly
{
/**
* @var array
Expand All @@ -31,9 +33,8 @@ class SSListContains extends PHPUnit_Framework_Constraint implements TestOnly
*/
protected $hasLeftoverItems = false;

public function __construct($matches)
public function __construct(array $matches)
{
parent::__construct();
$this->exporter = new SSListExporter();

$this->matches = $matches;
Expand All @@ -55,9 +56,9 @@ public function __construct($matches)
*
* @return null|bool
*
* @throws PHPUnit_Framework_ExpectationFailedException
* @throws ExpectationFailedException
*/
public function evaluate($other, $description = '', $returnResult = false)
public function evaluate($other, $description = '', $returnResult = false): ?bool
{
$success = true;

Expand Down Expand Up @@ -86,7 +87,7 @@ public function evaluate($other, $description = '', $returnResult = false)
* @param ViewableData $item
* @return bool
*/
protected function checkIfItemEvaluatesRemainingMatches(ViewableData $item)
protected function checkIfItemEvaluatesRemainingMatches(ViewableData $item): bool
{
$success = false;
foreach ($this->matches as $key => $match) {
Expand All @@ -107,7 +108,7 @@ protected function checkIfItemEvaluatesRemainingMatches(ViewableData $item)
*
* @return string
*/
public function toString()
public function toString(): string
{
$matchToString = function ($key, $value) {
return ' "' . $key . '" is "' . $value . '"';
Expand All @@ -132,7 +133,10 @@ public function toString()
return $this->getStubForToString() . $allMatchesAsString;
}

protected function getStubForToString()
/**
* @return string
*/
protected function getStubForToString(): string
{
return ' contains an item matching ';
}
Expand Down
14 changes: 8 additions & 6 deletions src/Dev/Constraint/SSListContainsOnly.php
Expand Up @@ -2,12 +2,14 @@

namespace SilverStripe\Dev\Constraint;

use PHPUnit_Framework_Constraint;
use PHPUnit_Framework_ExpectationFailedException;
// use PHPUnit_Framework_Constraint;
use PHPUnit\Framework\Constraint\Constraint;
// use PHPUnit_Framework_ExpectationFailedException;
use PHPUnit\Framework\ExpectationFailedException;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\SS_List;

if (!class_exists(PHPUnit_Framework_Constraint::class)) {
if (!class_exists(Constraint::class)) {
return;
}

Expand Down Expand Up @@ -40,9 +42,9 @@ class SSListContainsOnly extends SSListContains implements TestOnly
*
* @return null|bool
*
* @throws PHPUnit_Framework_ExpectationFailedException
* @throws ExpectationFailedException
*/
public function evaluate($other, $description = '', $returnResult = false)
public function evaluate($other, $description = '', $returnResult = false): ?bool
{
$success = true;

Expand Down Expand Up @@ -71,7 +73,7 @@ public function evaluate($other, $description = '', $returnResult = false)
return null;
}

protected function getStubForToString()
protected function getStubForToString(): string
{
return $this->itemNotMatching
? parent::getStubForToString()
Expand Down
17 changes: 9 additions & 8 deletions src/Dev/Constraint/SSListContainsOnlyMatchingItems.php
Expand Up @@ -2,21 +2,23 @@

namespace SilverStripe\Dev\Constraint;

use PHPUnit_Framework_Constraint;
use PHPUnit_Framework_ExpectationFailedException;
// use PHPUnit_Framework_Constraint;
use PHPUnit\Framework\Constraint\Constraint;
// use PHPUnit_Framework_ExpectationFailedException;
use PHPUnit\Framework\ExpectationFailedException;
use SilverStripe\Dev\SSListExporter;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\SS_List;

if (!class_exists(PHPUnit_Framework_Constraint::class)) {
if (!class_exists(Constraint::class)) {
return;
}

/**
* Constraint for checking if every item in a SS_List matches a given match,
* e.g. every Member has isActive set to true
*/
class SSListContainsOnlyMatchingItems extends PHPUnit_Framework_Constraint implements TestOnly
class SSListContainsOnlyMatchingItems extends Constraint implements TestOnly
{
/**
* @var array
Expand All @@ -30,7 +32,6 @@ class SSListContainsOnlyMatchingItems extends PHPUnit_Framework_Constraint imple

public function __construct($match)
{
parent::__construct();
$this->exporter = new SSListExporter();

$this->constraint = new ViewableDataContains($match);
Expand All @@ -53,9 +54,9 @@ public function __construct($match)
*
* @return null|bool
*
* @throws PHPUnit_Framework_ExpectationFailedException
* @throws ExpectationFailedException
*/
public function evaluate($other, $description = '', $returnResult = false)
public function evaluate($other, $description = '', $returnResult = false): ?bool
{
$success = true;

Expand All @@ -82,7 +83,7 @@ public function evaluate($other, $description = '', $returnResult = false)
*
* @return string
*/
public function toString()
public function toString(): string
{
return 'contains only Objects where "' . key($this->match) . '" is "' . current($this->match) . '"';
}
Expand Down

0 comments on commit eb91ac6

Please sign in to comment.