Skip to content

Commit

Permalink
API phpunit 9 support
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Oct 18, 2021
1 parent 42ee290 commit 8457f99
Show file tree
Hide file tree
Showing 37 changed files with 171 additions and 190 deletions.
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
}
],
"require": {
"silverstripe/framework": "^4.5",
"silverstripe/framework": "^4.10",
"silverstripe/vendor-plugin": "^1.0",
"symfony/filesystem": "^3.4|^4.0|^5.0",
"intervention/image": "^2.3",
"league/flysystem": "^1.0.70"
},
"require-dev": {
"silverstripe/recipe-testing": "dev-two",
"silverstripe/versioned": "^1@dev",
"sminnee/phpunit-mock-objects": "^3.4.5",
"sminnee/phpunit": "^5.7.29",
"squizlabs/php_codesniffer": "^3",
"mikey179/vfsstream": "^1.6"
},
Expand Down
8 changes: 5 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ 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
8 changes: 4 additions & 4 deletions tests/php/AssetControlExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AssetControlExtensionTest extends SapphireTest
TestObject::class
];

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

Expand Down Expand Up @@ -55,7 +55,7 @@ public function setUp()
$object3->publishSingle();
}

public function tearDown()
protected function tearDown(): void
{
TestAssetStore::reset();
parent::tearDown();
Expand Down Expand Up @@ -224,7 +224,7 @@ public function testReplaceFile()
$this->assertEquals(AssetStore::VISIBILITY_PUBLIC, $object3->Header->getVisibility());
}


public function testReplaceWithVariant()
{
$store = $this->getAssetStore();
Expand All @@ -250,7 +250,7 @@ public function testReplaceWithVariant()
$store->exists($v1->getFilename(), $v1->getHash(), 'boom'),
sprintf('A variant of %s has been created', $v1->getFilename())
);

// Let's replace the content of the main file and publish it
$download->setFromString($v2Content, $v2->getFilename());
$object1->write();
Expand Down
6 changes: 3 additions & 3 deletions tests/php/Dev/Tasks/FileMigrationHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function getBasePath()
}


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

Expand Down Expand Up @@ -164,7 +164,7 @@ function ($args) {
)->execute();
}

public function tearDown()
protected function tearDown(): void
{
TestAssetStore::reset();
Filesystem::removeFolder($this->getBasePath());
Expand Down Expand Up @@ -283,7 +283,7 @@ private function individualImage(Image $file)
$fullFilename = TestAssetStore::base_path() . '/' . $file->getFilename();
$dir = dirname($fullFilename);
$baseFilename = basename($fullFilename);
$this->assertFileNotExists($dir . '/_resampled');
$this->assertFileDoesNotExist($dir . '/_resampled');
$this->assertFileExists($dir . '/' . $baseFilename);

// Test that SS3.3 variants have been migrated
Expand Down
10 changes: 5 additions & 5 deletions tests/php/Dev/Tasks/LegacyThumbnailMigrationHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function getBasePath()
}


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

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

public function tearDown()
protected function tearDown(): void
{
TestAssetStore::reset();
Filesystem::removeFolder($this->getBasePath());
Expand Down Expand Up @@ -90,7 +90,7 @@ public function testMigratesWithExistingThumbnailInNewLocation($coreVersion)
// Moved contains store relative paths
$base = TestAssetStore::base_path();

$this->assertFileNotExists(
$this->assertFileDoesNotExist(
$this->joinPaths($base, $expectedLegacyPath),
'Legacy file has been removed'
);
Expand Down Expand Up @@ -131,7 +131,7 @@ public function testMigratesMultipleFilesInSameFolder($coreVersion)
$base = TestAssetStore::base_path();

foreach ($expected as $expectedLegacyPath => $expectedNewPath) {
$this->assertFileNotExists(
$this->assertFileDoesNotExist(
$this->joinPaths($base, $expectedLegacyPath),
'Legacy file has been removed'
);
Expand Down Expand Up @@ -176,7 +176,7 @@ public function testMigrate($fixtureId, $formats, $coreVersion)
$expectedNewPath,
'New file is mapped as expected'
);
$this->assertFileNotExists(
$this->assertFileDoesNotExist(
$this->joinPaths($base, $expectedLegacyPath),
'Legacy file has been removed'
);
Expand Down
12 changes: 4 additions & 8 deletions tests/php/Dev/Tasks/NormaliseAccessMigrationHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function getBasePath()
}


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

Expand All @@ -62,7 +62,7 @@ protected function setUpAssetStore()
TestAssetStore::activate('NormaliseAccessMigrationHelperTest/assets');
}

public function tearDown()
protected function tearDown(): void
{
TestAssetStore::reset();
Filesystem::removeFolder($this->getBasePath());
Expand Down Expand Up @@ -112,11 +112,9 @@ private function getHelper()
return new Helper('/assets/NormaliseAccessMigrationHelperTest/');
}

/**
* @expectedException InvalidArgumentException
*/
public function testNeedToMoveWithFolder()
{
$this->expectException(\InvalidArgumentException::class);
/** @var File $file */
$folder = Folder::find('Uploads');
$helper = $this->getHelper();
Expand Down Expand Up @@ -630,11 +628,9 @@ public function testFindBadFilesWithMultiPublishedVersions()
);
}

/**
* @expectedException LogicException
*/
public function testNeedToMoveNonExistentFile()
{
$this->expectException(\LogicException::class);
/** @var File $file */
$file = $this->objFromFixture(File::class, 'file1');
$file->CanViewType = InheritedPermissions::LOGGED_IN_USERS;
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Dev/Tasks/SS4FileMigrationHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SS4FileMigrationHelperTest extends SapphireTest
]
];

public function setUp()
protected function setUp(): void
{
Config::nest(); // additional nesting here necessary
Config::modify()->merge(File::class, 'migrate_legacy_file', false);
Expand Down Expand Up @@ -181,7 +181,7 @@ protected function defineDestinationStrategy()
$store->setPublicResolutionStrategy($public);
}

public function tearDown()
protected function tearDown(): void
{
TestAssetStore::reset();
parent::tearDown();
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Dev/Tasks/SecureAssetsMigrationHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function getBasePath()
}


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

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

public function tearDown()
protected function tearDown(): void
{
TestAssetStore::reset();
Filesystem::removeFolder($this->getBasePath());
Expand Down
16 changes: 8 additions & 8 deletions tests/php/Dev/Tasks/TagsToShortcodeHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function getBasePath()
return ASSETS_PATH . '/TagsToShortcodeHelperTest';
}

public function setUp()
protected function setUp(): void
{
parent::setUp();
$this->setupAssetStore();
Expand All @@ -67,7 +67,7 @@ private function setupAssetStore()
}
}

public function tearDown()
protected function tearDown(): void
{
TestAssetStore::reset();
Filesystem::removeFolder($this->getBasePath());
Expand All @@ -84,17 +84,17 @@ public function testRewrite()
$documentID = $this->idFromFixture(File::class, 'document');
$imageID = $this->idFromFixture(Image::class, 'image1');

$this->assertContains(
$this->assertStringContainsString(
sprintf('<p id="filelink">file link <a href="[file_link,id=%d]">link to file</a></p>', $documentID),
$newPage->Content
);

$this->assertContains(
$this->assertStringContainsString(
sprintf('<p id="image">[image src="/assets/33be1b95cb/myimage.jpg" id="%d"]</p>', $imageID),
$newPage->Content
);

$this->assertContains(
$this->assertStringContainsString(
sprintf(
'<p id="variant">[image src="/assets/33be1b95cb/myimage.jpg" width="64" height="64" id="%d"]</p>',
$imageID
Expand Down Expand Up @@ -137,17 +137,17 @@ public function testLivePageRewrite()
$documentID = $this->idFromFixture(File::class, 'document');
$imageID = $this->idFromFixture(Image::class, 'image1');

$this->assertContains(
$this->assertStringContainsString(
sprintf('<p id="filelink">file link <a href="[file_link,id=%d]">link to file</a></p>', $documentID),
$newPage->Content
);

$this->assertContains(
$this->assertStringContainsString(
sprintf('<p id="image">[image src="/assets/33be1b95cb/myimage.jpg" id="%d"]</p>', $imageID),
$newPage->Content
);

$this->assertContains(
$this->assertStringContainsString(
sprintf(
'<p id="variant">[image src="/assets/33be1b95cb/myimage.jpg" width="64" height="64" id="%d"]</p>',
$imageID
Expand Down
6 changes: 2 additions & 4 deletions tests/php/FileFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ public function testBasicOperation()
);
}

/**
* @expectedException InvalidArgumentException
*/
public function testInvalidOptionThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$finder = new FileFinder();
$finder->setOption('this_doesnt_exist', 'ok');
}
Expand Down Expand Up @@ -120,7 +118,7 @@ public function testMaxDepth()
);
}

public function assertFinderFinds(FileFinder $finder, $expect, $message = null)
public function assertFinderFinds(FileFinder $finder, $expect, $message = '')
{
$found = $finder->find($this->base);

Expand Down
2 changes: 1 addition & 1 deletion tests/php/FileNameFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

Expand Down

0 comments on commit 8457f99

Please sign in to comment.