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 13, 2021
1 parent 42ee290 commit 2f0837c
Show file tree
Hide file tree
Showing 36 changed files with 138 additions and 155 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
"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: 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
4 changes: 1 addition & 3 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
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
4 changes: 2 additions & 2 deletions tests/php/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FileTest extends SapphireTest
MyCustomFile::class
];

public function setUp()
protected function setUp(): void
{
parent::setUp();
$this->logInWithPermission('ADMIN');
Expand Down Expand Up @@ -70,7 +70,7 @@ public function setUp()
}
}

public function tearDown()
protected function tearDown(): void
{
TestAssetStore::reset();
parent::tearDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FileIDHelperResolutionStrategyTest extends SapphireTest
/** @var Filesystem */
private $fs;

public function setUp()
protected function setUp(): void
{
parent::setUp();
Sha1FileHashingService::flush();
Expand All @@ -49,7 +49,7 @@ public function setUp()
Injector::inst()->registerService($this->fs, Filesystem::class . '.public');
}

public function tearDown()
protected function tearDown(): void
{
TestAssetStore::reset();

Expand Down
4 changes: 1 addition & 3 deletions tests/php/FilenameParsing/HashFileIDHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,9 @@ public function variantIn()
];
}

/**
* @expectedException InvalidArgumentException
*/
public function testHashlessBuildFileID()
{
$this->expectException(\InvalidArgumentException::class);
$this->getHelper()->buildFileID('Filename.txt', '');
}
}
10 changes: 5 additions & 5 deletions tests/php/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FilesystemTest extends SapphireTest
*/
protected $root;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->root = vfsStream::setup(
Expand Down Expand Up @@ -74,7 +74,7 @@ public function testRemoveFolderWithFiles()

Filesystem::removeFolder($folderPath);
$this->assertDirectoryNotExists($folderPath);
$this->assertFileNotExists($filePath);
$this->assertFileDoesNotExist($filePath);
}

public function testRemoveFolderWithSubFolder()
Expand All @@ -90,7 +90,7 @@ public function testRemoveFolderWithSubFolder()
Filesystem::removeFolder($folderPath);
$this->assertDirectoryNotExists($folderPath);
$this->assertDirectoryNotExists($emptySubfolder);
$this->assertFileNotExists($filePath);
$this->assertFileDoesNotExist($filePath);
}

public function testRemoveFolderWithFalsyFile()
Expand All @@ -102,7 +102,7 @@ public function testRemoveFolderWithFalsyFile()

Filesystem::removeFolder($folderPath);
$this->assertDirectoryNotExists($folderPath);
$this->assertFileNotExists($filePath);
$this->assertFileDoesNotExist($filePath);
}

public function testRemovedFolderContentsOnly()
Expand All @@ -121,6 +121,6 @@ public function testRemovedFolderContentsOnly()
$this->assertDirectoryExists($folderPath);
$this->assertDirectoryNotExists($emptySubfolder);
$this->assertDirectoryNotExists($notEmptySubfolder);
$this->assertFileNotExists($filePath);
$this->assertFileDoesNotExist($filePath);
}
}

0 comments on commit 2f0837c

Please sign in to comment.