Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] API Upgrade SapphireTest to work with phpunit 9 - inner version #10030

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/Dev/Constraint/SSListContains.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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): ?null
{
$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
Original file line number Diff line number Diff line change
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
25 changes: 13 additions & 12 deletions src/Dev/Constraint/ViewableDataContains.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

namespace SilverStripe\Dev\Constraint;

use PHPUnit_Framework_Constraint;
use PHPUnit_Framework_ExpectationFailedException;
use PHPUnit_Util_InvalidArgumentHelper;
// use PHPUnit_Framework_Constraint;
use PHPUnit\Framework\Constraint\Constraint;
// use PHPUnit_Framework_ExpectationFailedException;
use PHPUnit\Framework\ExpectationFailedException;
// use PHPUnit_Util_InvalidArgumentHelper;
use SilverStripe\Dev\TestOnly;
use SilverStripe\View\ViewableData;
use SilverStripe\Dev\SapphireTest;

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

/**
* Constraint for checking if a ViewableData (e.g. ArrayData or any DataObject) contains fields matching the given
* key-value pairs.
*/
class ViewableDataContains extends PHPUnit_Framework_Constraint implements TestOnly
class ViewableDataContains extends Constraint implements TestOnly
{
/**
* @var array
Expand All @@ -27,12 +30,10 @@ class ViewableDataContains extends PHPUnit_Framework_Constraint implements TestO
* ViewableDataContains constructor.
* @param array $match
*/
public function __construct($match)
public function __construct(array $match)
{
parent::__construct();

if (!is_array($match)) {
throw PHPUnit_Util_InvalidArgumentHelper::factory(
throw SapphireTest::createPHPUnitFrameworkException(
1,
'array'
);
Expand All @@ -57,9 +58,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 Down Expand Up @@ -89,7 +90,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
15 changes: 8 additions & 7 deletions src/Dev/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace SilverStripe\Dev;

use PHPUnit_Framework_AssertionFailedError;
// use PHPUnit_Framework_AssertionFailedError;
use PHPUnit\Framework\AssertionFailedError;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\Session;
Expand Down Expand Up @@ -81,7 +82,7 @@ public function session()
return $this->mainSession->session();
}

protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down Expand Up @@ -113,7 +114,7 @@ protected function setUp()
SecurityToken::disable();
}

protected function tearDown()
protected function tearDown(): void
{
SecurityToken::enable();
unset($this->mainSession);
Expand Down Expand Up @@ -267,7 +268,7 @@ public function cssParser()
* @param string $selector A basic CSS selector, e.g. 'li.jobs h3'
* @param array|string $expectedMatches The content of at least one of the matched tags
* @param string $message
* @throws PHPUnit_Framework_AssertionFailedError
* @throws AssertionFailedError
*/
public function assertPartialMatchBySelector($selector, $expectedMatches, $message = null)
{
Expand Down Expand Up @@ -304,7 +305,7 @@ public function assertPartialMatchBySelector($selector, $expectedMatches, $messa
* @param string $selector A basic CSS selector, e.g. 'li.jobs h3'
* @param array|string $expectedMatches The content of *all* matching tags as an array
* @param string $message
* @throws PHPUnit_Framework_AssertionFailedError
* @throws AssertionFailedError
*/
public function assertExactMatchBySelector($selector, $expectedMatches, $message = null)
{
Expand Down Expand Up @@ -339,7 +340,7 @@ public function assertExactMatchBySelector($selector, $expectedMatches, $message
* @param string $selector A basic CSS selector, e.g. 'li.jobs h3'
* @param array|string $expectedMatches The content of at least one of the matched tags
* @param string $message
* @throws PHPUnit_Framework_AssertionFailedError
* @throws AssertionFailedError
*/
public function assertPartialHTMLMatchBySelector($selector, $expectedMatches, $message = null)
{
Expand Down Expand Up @@ -377,7 +378,7 @@ public function assertPartialHTMLMatchBySelector($selector, $expectedMatches, $m
* @param string $selector A basic CSS selector, e.g. 'li.jobs h3'
* @param array|string $expectedMatches The content of *all* matched tags as an array
* @param string $message
* @throws PHPUnit_Framework_AssertionFailedError
* @throws AssertionFailedError
*/
public function assertExactHTMLMatchBySelector($selector, $expectedMatches, $message = null)
{
Expand Down
Loading