Skip to content

Commit

Permalink
Merge pull request silverstripe#338 from creative-commoners/pulls/1/s…
Browse files Browse the repository at this point in the history
…apphire-test-nine

[WIP] API phpunit 9 support
  • Loading branch information
Maxime Rainville authored Nov 1, 2021
2 parents 3628e23 + 9b39e92 commit 775371a
Show file tree
Hide file tree
Showing 27 changed files with 100 additions and 100 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
}
],
"require": {
"silverstripe/framework": "^4.7",
"php": "^7.3 || ^8.0",
"silverstripe/framework": "^4.10",
"symfony/cache": "^3.4 || ^4",
"silverstripe/vendor-plugin": "^1"
},
"require-dev": {
"sminnee/phpunit": "^5.7",
"silverstripe/recipe-testing": "^2",
"dms/phpunit-arraysubset-asserts": "^0.3.0",
"silverstripe/graphql": "^3.5 || ^4",
"squizlabs/php_codesniffer": "^3"
},
Expand Down
12 changes: 5 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<!--
Standard module phpunit configuration.
Requires PHPUnit ^5.7
-->
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
<testsuite name="Default">
<directory>tests/php</directory>
</testsuite>
<testsuites>
<testsuite name="Default">
<directory>tests/php</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Caching/ProxyCacheFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class ProxyCacheFactoryTest extends SapphireTest
{
protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
9 changes: 5 additions & 4 deletions tests/php/ChangeSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace SilverStripe\Versioned\Tests;

use BadMethodCallException;
use PHPUnit_Framework_ExpectationFailedException;
use PHPUnit\Framework\ExpectationFailedException;
use SebastianBergmann\Comparator\ComparisonFailure;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\DataObject;
Expand Down Expand Up @@ -32,7 +32,7 @@ class ChangeSetTest extends SapphireTest
ChangeSetTest\UnstagedObject::class,
];

protected function tearDown()
protected function tearDown(): void
{
// Reset overridden permissions
foreach ($this->getExtraDataObjects() as $dataObjectClass) {
Expand Down Expand Up @@ -85,7 +85,7 @@ protected function assertChangeSetLooksLike($cs, $match)
}
}

throw new PHPUnit_Framework_ExpectationFailedException(
throw new ExpectationFailedException(
'Change set didn\'t include expected item',
new ComparisonFailure(
['Class' => $class, 'ID' => $objectID, 'Added' => $mode],
Expand All @@ -106,11 +106,12 @@ protected function assertChangeSetLooksLike($cs, $match)
'ChangeType' => $item->getChangeType()
];
}
throw new PHPUnit_Framework_ExpectationFailedException(
throw new ExpectationFailedException(
'Change set included items that weren\'t expected',
new ComparisonFailure([], $extra, '', print_r($extra, true))
);
}
$this->assertTrue(true, 'Exception was thrown when it should not have been');
}

public function testAddObject()
Expand Down
6 changes: 3 additions & 3 deletions tests/php/DataDifferencerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DataDifferencerTest extends SapphireTest
DataDifferencerTest\HasOneRelationObject::class
];

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

Expand All @@ -40,7 +40,7 @@ public function setUp()
}
}

public function tearDown()
protected function tearDown(): void
{
TestAssetStore::reset();
parent::tearDown();
Expand All @@ -57,7 +57,7 @@ public static function assertContainsIgnoreWhitespace($needle, $haystack, $messa
{
$needle = preg_replace('#\s+#', '', $needle);
$haystack = preg_replace('#\s+#', '', $haystack);
return parent::assertContains($needle, $haystack, $message);
return parent::assertStringContainsString($needle, $haystack, $message);
}

public function testArrayValues()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DataObjectScaffolderExtensionTest extends SapphireTest
Fake::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (!class_exists(Manager::class)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/php/GraphQL/Legacy/Extensions/ReadExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ReadExtensionTest extends SapphireTest
Fake::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (!class_exists(Manager::class)) {
Expand All @@ -53,7 +53,7 @@ public function testReadExtensionAppliesFilters()
$read = new Read(Fake::class);
$read->setUsePagination(false);
$readScaffold = $read->scaffold($manager);
$this->assertInternalType('callable', $readScaffold['resolve']);
$this->assertIsCallable($readScaffold['resolve']);
$readScaffold['resolve'](null, ['Versioning' => true], ['currentUser' => new Member()], new ResolveInfo([]));
}
}
6 changes: 3 additions & 3 deletions tests/php/GraphQL/Legacy/Extensions/ReadOneExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ReadOneExtensionTest extends SapphireTest
Fake::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (class_exists(Schema::class)) {
Expand All @@ -44,7 +44,7 @@ public function testReadOneExtensionAppliesFilters()
$manager->addType(new ObjectType(['name' => StaticSchema::inst()->typeNameForDataObject(Fake::class)]));
$read = new ReadOne(Fake::class);
$readScaffold = $read->scaffold($manager);
$this->assertInternalType('callable', $readScaffold['resolve']);
$this->assertIsCallable($readScaffold['resolve']);
$doResolve = function ($mode, $ID, $version = null) use ($readScaffold) {
$args = [
'ID' => $ID,
Expand Down Expand Up @@ -94,7 +94,7 @@ public function testReadOneExtensionAppliesFilters()
$this->assertEquals($record->ID, $result->ID);
$this->assertEquals('First', $result->Name);

$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$doResolve('version', $record->ID, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SchemaScaffolderExtensionTest extends SapphireTest
Fake::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (class_exists(Schema::class)) {
Expand Down
6 changes: 3 additions & 3 deletions tests/php/GraphQL/Legacy/Operations/CopyToStageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CopyToStageTest extends SapphireTest
Fake::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (class_exists(Schema::class)) {
Expand All @@ -48,7 +48,7 @@ public function testCopyToStage()
$manager->addType(new ObjectType(['name' => $typeName]));
$copyToStage = new CopyToStage(Fake::class);
$scaffold = $copyToStage->scaffold($manager);
$this->assertInternalType('callable', $scaffold['resolve']);
$this->assertIsCallable($scaffold['resolve']);

/* @var Fake|Versioned $record */
$record = new Fake();
Expand Down Expand Up @@ -100,7 +100,7 @@ public function testCopyToStage()
$this->assertEquals('Second', $recordLive->Title);

// Test error
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$scaffold['resolve'](
null,
[
Expand Down
6 changes: 3 additions & 3 deletions tests/php/GraphQL/Legacy/Operations/PublishTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PublishTest extends SapphireTest
Fake::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (class_exists(Schema::class)) {
Expand All @@ -45,7 +45,7 @@ public function testPublish()

$publish = new Publish(Fake::class);
$scaffold = $publish->scaffold($manager);
$this->assertInternalType('callable', $scaffold['resolve']);
$this->assertIsCallable($scaffold['resolve']);

$record = new Fake();
$record->Name = 'First';
Expand Down Expand Up @@ -73,7 +73,7 @@ public function testPublish()
$this->assertEquals('First', $result->Name);

$this->expectException(Exception::class);
$this->expectExceptionMessageRegExp('/^Not allowed/');
$this->expectExceptionMessageMatches('/^Not allowed/');
$scaffold['resolve'](
null,
[
Expand Down
12 changes: 6 additions & 6 deletions tests/php/GraphQL/Legacy/Operations/ReadVersionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ReadVersionsTest extends SapphireTest
Fake::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (class_exists(Schema::class)) {
Expand All @@ -50,10 +50,10 @@ public function testItThrowsIfAppliedToAnUnversionedObject()
$readVersions = new ReadVersions(UnversionedWithField::class, 'Test');
$readVersions->setUsePagination(false);
$scaffold = $readVersions->scaffold($manager);
$this->assertInternalType('callable', $scaffold['resolve']);
$this->assertIsCallable($scaffold['resolve']);

$this->expectException(Exception::class);
$this->expectExceptionMessageRegExp('/must have the Versioned extension/');
$this->expectExceptionMessageMatches('/must have the Versioned extension/');
$scaffold['resolve'](
new UnversionedWithField(),
[],
Expand All @@ -71,10 +71,10 @@ public function testItThrowsIfYouCantReadStages()
$readVersions = new ReadVersions(Fake::class, 'Test');
$readVersions->setUsePagination(false);
$scaffold = $readVersions->scaffold($manager);
$this->assertInternalType('callable', $scaffold['resolve']);
$this->assertIsCallable($scaffold['resolve']);

$this->expectException(Exception::class);
$this->expectExceptionMessageRegExp('/Cannot view versions/');
$this->expectExceptionMessageMatches('/Cannot view versions/');
$scaffold['resolve'](
new Fake(),
[],
Expand All @@ -92,7 +92,7 @@ public function testItReadsVersions()
$readVersions = new ReadVersions(Fake::class, 'Test');
$readVersions->setUsePagination(false);
$scaffold = $readVersions->scaffold($manager);
$this->assertInternalType('callable', $scaffold['resolve']);
$this->assertIsCallable($scaffold['resolve']);
$this->logInWithPermission('ADMIN');
$member = Security::getCurrentUser();

Expand Down
10 changes: 4 additions & 6 deletions tests/php/GraphQL/Legacy/Operations/RollbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,18 @@ class RollbackTest extends SapphireTest
FakeDataObjectStub::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (class_exists(Schema::class)) {
$this->markTestSkipped('Skipped GraphQL 3 test ' . __CLASS__);
}
}

/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Current user does not have permission to roll back this resource
*/
public function testRollbackCannotBePerformedWithoutEditPermission()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Current user does not have permission to roll back this resource');
// Create a fake version of our stub
$stub = FakeDataObjectStub::create();
$stub->Name = 'First';
Expand Down Expand Up @@ -76,7 +74,7 @@ protected function doMutation(DataObject $stub, $toVersion = 1, $member = null)

$mutation = new Rollback($stubClass);
$scaffold = $mutation->scaffold($manager);
$this->assertInternalType('callable', $scaffold['resolve'], 'Resolve function is scaffolded correctly');
$this->assertIsCallable($scaffold['resolve'], 'Resolve function is scaffolded correctly');

$args = [
'ID' => $stub->ID,
Expand Down
6 changes: 3 additions & 3 deletions tests/php/GraphQL/Legacy/Operations/UnpublishTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class UnpublishTest extends SapphireTest
Fake::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (class_exists(Schema::class)) {
Expand All @@ -46,7 +46,7 @@ public function testPublish()

$publish = new Unpublish(Fake::class);
$scaffold = $publish->scaffold($manager);
$this->assertInternalType('callable', $scaffold['resolve']);
$this->assertIsCallable($scaffold['resolve']);

$record = new Fake();
$record->Name = 'First';
Expand Down Expand Up @@ -76,7 +76,7 @@ public function testPublish()

$record->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$this->expectException(Exception::class);
$this->expectExceptionMessageRegExp('/^Not allowed/');
$this->expectExceptionMessageMatches('/^Not allowed/');
$scaffold['resolve'](
null,
[
Expand Down
Loading

0 comments on commit 775371a

Please sign in to comment.