diff --git a/composer.json b/composer.json index 8b6faad2..62e89e4a 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/tests/php/AssetControlExtensionTest.php b/tests/php/AssetControlExtensionTest.php index cc12f376..9608f509 100644 --- a/tests/php/AssetControlExtensionTest.php +++ b/tests/php/AssetControlExtensionTest.php @@ -25,7 +25,7 @@ class AssetControlExtensionTest extends SapphireTest TestObject::class ]; - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -55,7 +55,7 @@ public function setUp() $object3->publishSingle(); } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); @@ -224,7 +224,7 @@ public function testReplaceFile() $this->assertEquals(AssetStore::VISIBILITY_PUBLIC, $object3->Header->getVisibility()); } - + public function testReplaceWithVariant() { $store = $this->getAssetStore(); @@ -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(); diff --git a/tests/php/Dev/Tasks/FileMigrationHelperTest.php b/tests/php/Dev/Tasks/FileMigrationHelperTest.php index 2ea42fb8..e7f13120 100644 --- a/tests/php/Dev/Tasks/FileMigrationHelperTest.php +++ b/tests/php/Dev/Tasks/FileMigrationHelperTest.php @@ -50,7 +50,7 @@ protected function getBasePath() } - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -164,7 +164,7 @@ function ($args) { )->execute(); } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); Filesystem::removeFolder($this->getBasePath()); @@ -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 diff --git a/tests/php/Dev/Tasks/LegacyThumbnailMigrationHelperTest.php b/tests/php/Dev/Tasks/LegacyThumbnailMigrationHelperTest.php index b03ed5a7..515e9043 100644 --- a/tests/php/Dev/Tasks/LegacyThumbnailMigrationHelperTest.php +++ b/tests/php/Dev/Tasks/LegacyThumbnailMigrationHelperTest.php @@ -41,7 +41,7 @@ protected function getBasePath() } - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -61,7 +61,7 @@ public function setUp() } } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); Filesystem::removeFolder($this->getBasePath()); @@ -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' ); @@ -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' ); @@ -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' ); diff --git a/tests/php/Dev/Tasks/NormaliseAccessMigrationHelperTest.php b/tests/php/Dev/Tasks/NormaliseAccessMigrationHelperTest.php index 093e025c..981e4e6b 100644 --- a/tests/php/Dev/Tasks/NormaliseAccessMigrationHelperTest.php +++ b/tests/php/Dev/Tasks/NormaliseAccessMigrationHelperTest.php @@ -41,7 +41,7 @@ protected function getBasePath() } - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -62,7 +62,7 @@ protected function setUpAssetStore() TestAssetStore::activate('NormaliseAccessMigrationHelperTest/assets'); } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); Filesystem::removeFolder($this->getBasePath()); @@ -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(); @@ -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; diff --git a/tests/php/Dev/Tasks/SS4FileMigrationHelperTest.php b/tests/php/Dev/Tasks/SS4FileMigrationHelperTest.php index 544593d8..fc6a800c 100644 --- a/tests/php/Dev/Tasks/SS4FileMigrationHelperTest.php +++ b/tests/php/Dev/Tasks/SS4FileMigrationHelperTest.php @@ -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); @@ -181,7 +181,7 @@ protected function defineDestinationStrategy() $store->setPublicResolutionStrategy($public); } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); diff --git a/tests/php/Dev/Tasks/SecureAssetsMigrationHelperTest.php b/tests/php/Dev/Tasks/SecureAssetsMigrationHelperTest.php index cbda97e0..f74c1bf6 100644 --- a/tests/php/Dev/Tasks/SecureAssetsMigrationHelperTest.php +++ b/tests/php/Dev/Tasks/SecureAssetsMigrationHelperTest.php @@ -28,7 +28,7 @@ protected function getBasePath() } - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -52,7 +52,7 @@ public function setUp() } } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); Filesystem::removeFolder($this->getBasePath()); diff --git a/tests/php/Dev/Tasks/TagsToShortcodeHelperTest.php b/tests/php/Dev/Tasks/TagsToShortcodeHelperTest.php index 2831765d..3b370571 100644 --- a/tests/php/Dev/Tasks/TagsToShortcodeHelperTest.php +++ b/tests/php/Dev/Tasks/TagsToShortcodeHelperTest.php @@ -44,7 +44,7 @@ protected function getBasePath() return ASSETS_PATH . '/TagsToShortcodeHelperTest'; } - public function setUp() + protected function setUp(): void { parent::setUp(); $this->setupAssetStore(); @@ -67,7 +67,7 @@ private function setupAssetStore() } } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); Filesystem::removeFolder($this->getBasePath()); @@ -84,17 +84,17 @@ public function testRewrite() $documentID = $this->idFromFixture(File::class, 'document'); $imageID = $this->idFromFixture(Image::class, 'image1'); - $this->assertContains( + $this->assertStringContainsString( sprintf('', $documentID), $newPage->Content ); - $this->assertContains( + $this->assertStringContainsString( sprintf('

[image src="/assets/33be1b95cb/myimage.jpg" id="%d"]

', $imageID), $newPage->Content ); - $this->assertContains( + $this->assertStringContainsString( sprintf( '

[image src="/assets/33be1b95cb/myimage.jpg" width="64" height="64" id="%d"]

', $imageID @@ -137,17 +137,17 @@ public function testLivePageRewrite() $documentID = $this->idFromFixture(File::class, 'document'); $imageID = $this->idFromFixture(Image::class, 'image1'); - $this->assertContains( + $this->assertStringContainsString( sprintf('', $documentID), $newPage->Content ); - $this->assertContains( + $this->assertStringContainsString( sprintf('

[image src="/assets/33be1b95cb/myimage.jpg" id="%d"]

', $imageID), $newPage->Content ); - $this->assertContains( + $this->assertStringContainsString( sprintf( '

[image src="/assets/33be1b95cb/myimage.jpg" width="64" height="64" id="%d"]

', $imageID diff --git a/tests/php/FileFinderTest.php b/tests/php/FileFinderTest.php index 03a6b187..d4e0e017 100644 --- a/tests/php/FileFinderTest.php +++ b/tests/php/FileFinderTest.php @@ -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'); } diff --git a/tests/php/FileNameFilterTest.php b/tests/php/FileNameFilterTest.php index e8c38b0e..4c8ebad8 100644 --- a/tests/php/FileNameFilterTest.php +++ b/tests/php/FileNameFilterTest.php @@ -8,7 +8,7 @@ class FileNameFilterTest extends SapphireTest { - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/php/FileTest.php b/tests/php/FileTest.php index dfc3b6fa..33022b2f 100644 --- a/tests/php/FileTest.php +++ b/tests/php/FileTest.php @@ -37,7 +37,7 @@ class FileTest extends SapphireTest MyCustomFile::class ]; - public function setUp() + protected function setUp(): void { parent::setUp(); $this->logInWithPermission('ADMIN'); @@ -70,7 +70,7 @@ public function setUp() } } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); diff --git a/tests/php/FilenameParsing/FileIDHelperResolutionStrategyTest.php b/tests/php/FilenameParsing/FileIDHelperResolutionStrategyTest.php index 4665954b..07c9fc20 100644 --- a/tests/php/FilenameParsing/FileIDHelperResolutionStrategyTest.php +++ b/tests/php/FilenameParsing/FileIDHelperResolutionStrategyTest.php @@ -30,7 +30,7 @@ class FileIDHelperResolutionStrategyTest extends SapphireTest /** @var Filesystem */ private $fs; - public function setUp() + protected function setUp(): void { parent::setUp(); Sha1FileHashingService::flush(); @@ -49,7 +49,7 @@ public function setUp() Injector::inst()->registerService($this->fs, Filesystem::class . '.public'); } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); diff --git a/tests/php/FilenameParsing/HashFileIDHelperTest.php b/tests/php/FilenameParsing/HashFileIDHelperTest.php index f13194b5..616e890f 100644 --- a/tests/php/FilenameParsing/HashFileIDHelperTest.php +++ b/tests/php/FilenameParsing/HashFileIDHelperTest.php @@ -168,11 +168,9 @@ public function variantIn() ]; } - /** - * @expectedException InvalidArgumentException - */ public function testHashlessBuildFileID() { + $this->expectException(\InvalidArgumentException::class); $this->getHelper()->buildFileID('Filename.txt', ''); } } diff --git a/tests/php/FilesystemTest.php b/tests/php/FilesystemTest.php index 62fc2c79..5c436cb0 100644 --- a/tests/php/FilesystemTest.php +++ b/tests/php/FilesystemTest.php @@ -24,7 +24,7 @@ class FilesystemTest extends SapphireTest */ protected $root; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->root = vfsStream::setup( @@ -74,7 +74,7 @@ public function testRemoveFolderWithFiles() Filesystem::removeFolder($folderPath); $this->assertDirectoryNotExists($folderPath); - $this->assertFileNotExists($filePath); + $this->assertFileDoesNotExist($filePath); } public function testRemoveFolderWithSubFolder() @@ -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() @@ -102,7 +102,7 @@ public function testRemoveFolderWithFalsyFile() Filesystem::removeFolder($folderPath); $this->assertDirectoryNotExists($folderPath); - $this->assertFileNotExists($filePath); + $this->assertFileDoesNotExist($filePath); } public function testRemovedFolderContentsOnly() @@ -121,6 +121,6 @@ public function testRemovedFolderContentsOnly() $this->assertDirectoryExists($folderPath); $this->assertDirectoryNotExists($emptySubfolder); $this->assertDirectoryNotExists($notEmptySubfolder); - $this->assertFileNotExists($filePath); + $this->assertFileDoesNotExist($filePath); } } diff --git a/tests/php/Flysystem/AssetAdapterTest.php b/tests/php/Flysystem/AssetAdapterTest.php index 59afc730..117888e5 100644 --- a/tests/php/Flysystem/AssetAdapterTest.php +++ b/tests/php/Flysystem/AssetAdapterTest.php @@ -17,7 +17,7 @@ class AssetAdapterTest extends SapphireTest protected $originalServer = null; - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -38,7 +38,7 @@ public function setUp() $this->originalServer = $_SERVER; } - public function tearDown() + protected function tearDown(): void { if ($this->rootDir) { Filesystem::removeFolder($this->rootDir); @@ -56,19 +56,19 @@ public function testPublicAdapter() $_SERVER['SERVER_SOFTWARE'] = 'Apache/2.2.22 (Win64) PHP/5.3.13'; $adapter = new PublicAssetAdapter($this->rootDir); $this->assertFileExists($this->rootDir . '/.htaccess'); - $this->assertFileNotExists($this->rootDir . '/web.config'); + $this->assertFileDoesNotExist($this->rootDir . '/web.config'); $htaccess = $adapter->read('.htaccess'); $content = $htaccess['contents']; // Allowed extensions set - $this->assertContains('RewriteCond %{REQUEST_URI} !^[^.]*[^\/]*\.(?i:', $content); + $this->assertStringContainsString('RewriteCond %{REQUEST_URI} !^[^.]*[^\/]*\.(?i:', $content); foreach (File::getAllowedExtensions() as $extension) { - $this->assertRegExp('/\b'.preg_quote($extension).'\b/', $content); + $this->assertMatchesRegularExpression('/\b'.preg_quote($extension).'\b/', $content); } // Rewrite rules - $this->assertContains('RewriteRule .* ../index.php [QSA]', $content); - $this->assertContains('RewriteRule error[^\\\\/]*\\.html$ - [L]', $content); + $this->assertStringContainsString('RewriteRule .* ../index.php [QSA]', $content); + $this->assertStringContainsString('RewriteRule error[^\\\\/]*\\.html$ - [L]', $content); // Test flush restores invalid content file_put_contents($this->rootDir . '/.htaccess', '# broken content'); @@ -85,7 +85,7 @@ public function testProtectedAdapter() $_SERVER['SERVER_SOFTWARE'] = 'Apache/2.2.22 (Win64) PHP/5.3.13'; $adapter = new ProtectedAssetAdapter($this->rootDir . '/.protected'); $this->assertFileExists($this->rootDir . '/.protected/.htaccess'); - $this->assertFileNotExists($this->rootDir . '/.protected/web.config'); + $this->assertFileDoesNotExist($this->rootDir . '/.protected/web.config'); // Test url $this->assertEquals('/assets/file.jpg', $adapter->getProtectedUrl('file.jpg')); diff --git a/tests/php/Flysystem/FlysystemAssetStoreTest.php b/tests/php/Flysystem/FlysystemAssetStoreTest.php index 1410a45a..a2f1dc6e 100644 --- a/tests/php/Flysystem/FlysystemAssetStoreTest.php +++ b/tests/php/Flysystem/FlysystemAssetStoreTest.php @@ -41,7 +41,7 @@ class FlysystemAssetStoreTest extends SapphireTest /** @var FileResolutionStrategy */ protected $protectedStrategy; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -136,11 +136,9 @@ public function testPublicFilesystem() $this->assertEquals($this->publicFilesystem, $assetStore->getPublicFilesystem()); } - /** - * @expectedException InvalidArgumentException - */ public function testBadPublicFilesystem() { + $this->expectException(\InvalidArgumentException::class); $assetStore = new FlysystemAssetStore(); $assetStore->setPublicFilesystem($this->protectedFilesystem); } @@ -152,11 +150,9 @@ public function testProtectedFilesystem() $this->assertEquals($this->protectedFilesystem, $assetStore->getProtectedFilesystem()); } - /** - * @expectedException InvalidArgumentException - */ public function testBadProtectedFilesystem() { + $this->expectException(\InvalidArgumentException::class); $assetStore = new FlysystemAssetStore(); $assetStore->setProtectedFilesystem($this->publicFilesystem); } diff --git a/tests/php/Flysystem/FlysystemAssetStoreUpdateResponseTest.php b/tests/php/Flysystem/FlysystemAssetStoreUpdateResponseTest.php index 379a79cf..2827ff95 100644 --- a/tests/php/Flysystem/FlysystemAssetStoreUpdateResponseTest.php +++ b/tests/php/Flysystem/FlysystemAssetStoreUpdateResponseTest.php @@ -26,7 +26,7 @@ class FlysystemAssetStoreUpdateResponseTest extends SapphireTest /** * @skipUpgrade */ - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -59,7 +59,7 @@ public function setUp() $this->hash = substr(sha1('hello'), 0, 10); } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); diff --git a/tests/php/FolderNameFilterTest.php b/tests/php/FolderNameFilterTest.php index 4951d211..66609209 100644 --- a/tests/php/FolderNameFilterTest.php +++ b/tests/php/FolderNameFilterTest.php @@ -8,7 +8,7 @@ class FolderNameFilterTest extends SapphireTest { - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/php/FolderTest.php b/tests/php/FolderTest.php index f3ba7b89..eeb78ace 100644 --- a/tests/php/FolderTest.php +++ b/tests/php/FolderTest.php @@ -24,7 +24,7 @@ class FolderTest extends SapphireTest protected static $fixture_file = 'FileTest.yml'; - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -66,7 +66,7 @@ public function setUp() } } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); @@ -131,7 +131,7 @@ public function testFindOrMake() ); // Folder does not exist until it contains files - $this->assertFileNotExists( + $this->assertFileDoesNotExist( TestAssetStore::getLocalPath($folder), 'Empty folder does not have a filesystem record automatically' ); diff --git a/tests/php/GDImageTest.php b/tests/php/GDImageTest.php index 024921a6..4e57f66c 100644 --- a/tests/php/GDImageTest.php +++ b/tests/php/GDImageTest.php @@ -11,7 +11,7 @@ class GDImageTest extends ImageTest { - public function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/php/ImageManipulationTest.php b/tests/php/ImageManipulationTest.php index 2726388f..5c7bf078 100644 --- a/tests/php/ImageManipulationTest.php +++ b/tests/php/ImageManipulationTest.php @@ -29,7 +29,7 @@ class ImageManipulationTest extends SapphireTest { protected static $fixture_file = 'ImageTest.yml'; - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -53,7 +53,7 @@ public function setUp() ]); } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); diff --git a/tests/php/ImageTest.php b/tests/php/ImageTest.php index 21485e11..68a744b3 100644 --- a/tests/php/ImageTest.php +++ b/tests/php/ImageTest.php @@ -28,7 +28,7 @@ abstract class ImageTest extends SapphireTest { protected static $fixture_file = 'ImageTest.yml'; - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -52,7 +52,7 @@ public function setUp() ]); } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); @@ -315,7 +315,7 @@ public function testImageResizeValidate() */ public function testImageResizeInvalid($width, $height, $error) { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage($error); /** @var Image $image */ $image = $this->objFromFixture(Image::class, 'imageWithoutTitle'); @@ -331,11 +331,9 @@ public function providerTestImageResizeInvalid() ]; } - /** - * @expectedException InvalidArgumentException - */ public function testGenerateImageWithInvalidParameters() { + $this->expectException(\InvalidArgumentException::class); $image = $this->objFromFixture(Image::class, 'imageWithoutTitle'); $image->ScaleHeight('String'); $image->Pad(600, 600, 'XXXXXX'); @@ -348,7 +346,7 @@ public function testCacheFilename() $imageFilename = $imageFirst->getURL(); // Encoding of the arguments is duplicated from cacheFilename $neededPart = 'Pad' . Convert::base64url_encode([200,200,'CCCCCC', 0]); - $this->assertContains($neededPart, $imageFilename, 'Filename for cached image is correctly generated'); + $this->assertStringContainsString($neededPart, $imageFilename, 'Filename for cached image is correctly generated'); } public function testGenerateImageInSameFolderAsOriginal() @@ -404,11 +402,9 @@ public function testVariantParts() ); } - /** - * @expectedException \InvalidArgumentException - */ public function testVariantPartsThrowsOnInvalidName() { + $this->expectException(\InvalidArgumentException::class); /** @var Image $image */ $image = singleton(Image::class); $args = ['foo']; diff --git a/tests/php/ImagickImageTest.php b/tests/php/ImagickImageTest.php index d1194cd5..d9ca5ba3 100644 --- a/tests/php/ImagickImageTest.php +++ b/tests/php/ImagickImageTest.php @@ -11,7 +11,7 @@ class ImagickImageTest extends ImageTest { - public function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/php/ProtectedFileControllerTest.php b/tests/php/ProtectedFileControllerTest.php index 7047e31c..6ec9903d 100644 --- a/tests/php/ProtectedFileControllerTest.php +++ b/tests/php/ProtectedFileControllerTest.php @@ -20,7 +20,7 @@ class ProtectedFileControllerTest extends FunctionalTest { protected static $fixture_file = 'FileTest.yml'; - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -47,7 +47,7 @@ public function setUp() $protectedFile->protectFile(); } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); diff --git a/tests/php/PublicAssetAdapterTest.php b/tests/php/PublicAssetAdapterTest.php index 257c340d..e726b092 100644 --- a/tests/php/PublicAssetAdapterTest.php +++ b/tests/php/PublicAssetAdapterTest.php @@ -8,7 +8,7 @@ class PublicAssetAdapterTest extends SapphireTest { - protected function setUp() + protected function setUp(): void { parent::setUp(); Director::config()->set( diff --git a/tests/php/RedirectFileControllerTest.php b/tests/php/RedirectFileControllerTest.php index fcbf7da3..14ec74e3 100644 --- a/tests/php/RedirectFileControllerTest.php +++ b/tests/php/RedirectFileControllerTest.php @@ -25,7 +25,7 @@ class RedirectFileControllerTest extends FunctionalTest protected $autoFollowRedirection = false; - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -57,7 +57,7 @@ public function setUp() } } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); @@ -216,7 +216,7 @@ public function testRedirectWithDraftFile($fixtureID) public function testRedirectAfterPublishSecondVersion($fixtureID) { $hashHelper = new HashFileIDHelper(); - + /** @var File $file */ $file = $this->objFromFixture(File::class, $fixtureID); $file->publishSingle(); @@ -384,7 +384,7 @@ public function testVariantRedirect($folderFixture, $filename, $ext) $hash = substr($file->getHash(), 0, 10); $ico = $file->ScaleWidth(32); $icoUrl = $ico->getURL(false); - + $suffix = $ico->getVariant(); $response = $this->get($icoUrl); diff --git a/tests/php/RedirectKeepArchiveFileControllerTest.php b/tests/php/RedirectKeepArchiveFileControllerTest.php index 8fb63943..9562e4eb 100644 --- a/tests/php/RedirectKeepArchiveFileControllerTest.php +++ b/tests/php/RedirectKeepArchiveFileControllerTest.php @@ -20,7 +20,7 @@ class RedirectKeepArchiveFileControllerTest extends RedirectFileControllerTest { - public function setUp() + protected function setUp(): void { File::config()->set('keep_archived_assets', true); parent::setUp(); @@ -43,7 +43,7 @@ public function testRedirectAfterUnpublish($fixtureID) ); $file->write(); $v2HashUrl = $file->getURL(false); - + $file->publishSingle(); $v2Url = $file->getURL(false); diff --git a/tests/php/Shortcodes/FileBrokenLinksTest.php b/tests/php/Shortcodes/FileBrokenLinksTest.php index 620664c0..5fefe562 100644 --- a/tests/php/Shortcodes/FileBrokenLinksTest.php +++ b/tests/php/Shortcodes/FileBrokenLinksTest.php @@ -17,7 +17,7 @@ class FileBrokenLinksTest extends SapphireTest EditableObject::class, ]; - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -25,7 +25,7 @@ public function setUp() TestAssetStore::activate('FileBrokenLinksTest'); } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); diff --git a/tests/php/Shortcodes/FileLinkTrackingTest.php b/tests/php/Shortcodes/FileLinkTrackingTest.php index f42950f2..1e8dfaaf 100644 --- a/tests/php/Shortcodes/FileLinkTrackingTest.php +++ b/tests/php/Shortcodes/FileLinkTrackingTest.php @@ -19,7 +19,7 @@ class FileLinkTrackingTest extends SapphireTest protected static $fixture_file = "FileLinkTrackingTest.yml"; - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -59,7 +59,7 @@ public function setUp() $page->write(); } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); @@ -77,11 +77,11 @@ public function testFileRenameUpdatesDraftAndPublishedPages() $page->publishRecursive(); // Live and stage pages both have link to public file - $this->assertContains( + $this->assertStringContainsString( 'dbObject('Content')->forTemplate() ); - $this->assertContains( + $this->assertStringContainsString( '

Working Link

', $page->dbObject('Another')->forTemplate() ); @@ -90,11 +90,11 @@ public function testFileRenameUpdatesDraftAndPublishedPages() Versioned::set_stage(Versioned::LIVE); /** @var EditableObject $pageLive */ $pageLive = EditableObject::get()->byID($page->ID); - $this->assertContains( + $this->assertStringContainsString( 'dbObject('Content')->forTemplate() ); - $this->assertContains( + $this->assertStringContainsString( '

Working Link

', $pageLive->dbObject('Another')->forTemplate() ); @@ -119,14 +119,14 @@ public function testFileRenameUpdatesDraftAndPublishedPages() // Note that the "secure" url doesn't have the "FileLinkTrackingTest" component because // the mocked test location disappears for secure files. $page = EditableObject::get()->byID($page->ID); - $this->assertContains( + $this->assertStringContainsString( 'dbObject('Content')->forTemplate() ); Versioned::withVersionedMode(function () use ($page) { Versioned::set_stage(Versioned::LIVE); $pageLive = EditableObject::get()->byID($page->ID); - $this->assertContains( + $this->assertStringContainsString( 'dbObject('Content')->forTemplate() ); @@ -136,14 +136,14 @@ public function testFileRenameUpdatesDraftAndPublishedPages() // Although the old live page will still point to the old record. $image1->publishRecursive(); $page = EditableObject::get()->byID($page->ID); - $this->assertContains( + $this->assertStringContainsString( 'dbObject('Content')->forTemplate() ); Versioned::withVersionedMode(function () use ($page) { Versioned::set_stage(Versioned::LIVE); $pageLive = EditableObject::get()->byID($page->ID); - $this->assertContains( + $this->assertStringContainsString( 'dbObject('Content')->forTemplate() ); @@ -152,14 +152,14 @@ public function testFileRenameUpdatesDraftAndPublishedPages() // Publishing the page after publishing the asset should retain linking $page->publishRecursive(); $page = EditableObject::get()->byID($page->ID); - $this->assertContains( + $this->assertStringContainsString( 'dbObject('Content')->forTemplate() ); Versioned::withVersionedMode(function () use ($page) { Versioned::set_stage(Versioned::LIVE); $pageLive = EditableObject::get()->byID($page->ID); - $this->assertContains( + $this->assertStringContainsString( 'dbObject('Content')->forTemplate() ); @@ -193,7 +193,7 @@ public function testTwoFileRenamesInARowWork() Versioned::withVersionedMode(function () use ($page) { Versioned::set_stage(Versioned::LIVE); $livePage = EditableObject::get()->byID($page->ID); - $this->assertContains( + $this->assertStringContainsString( 'dbObject('Content')->forTemplate() ); @@ -214,7 +214,7 @@ public function testTwoFileRenamesInARowWork() // Confirm that the correct image is shown in both the draft and live site $page = EditableObject::get()->byID($page->ID); - $this->assertContains( + $this->assertStringContainsString( 'dbObject('Content')->forTemplate() ); @@ -224,7 +224,7 @@ public function testTwoFileRenamesInARowWork() Versioned::withVersionedMode(function () use ($page) { Versioned::set_stage(Versioned::LIVE); $pageLive = EditableObject::get()->byID($page->ID); - $this->assertContains( + $this->assertStringContainsString( 'dbObject('Content')->forTemplate() ); @@ -243,11 +243,11 @@ public function testBrokenCSSClasses() $file = $this->objFromFixture(File::class, 'file1'); $fileID = $file->ID; - $this->assertContains( + $this->assertStringContainsString( '

Working Link

', $page->dbObject('Another')->forTemplate() ); - $this->assertContains( + $this->assertStringContainsString( sprintf('

Working Link

', $fileID), $page->Another ); @@ -255,11 +255,11 @@ public function testBrokenCSSClasses() // Deleting file should trigger css class $file->delete(); $page = EditableObject::get()->byID($page->ID); - $this->assertContains( + $this->assertStringContainsString( '

Working Link

', $page->dbObject('Another')->forTemplate() ); - $this->assertContains( + $this->assertStringContainsString( sprintf('

Working Link

', $fileID), $page->Another ); @@ -269,11 +269,11 @@ public function testBrokenCSSClasses() $fileLive = Versioned::get_by_stage(File::class, Versioned::LIVE)->byID($fileID); $fileLive->doRevertToLive(); $page = EditableObject::get()->byID($page->ID); - $this->assertContains( + $this->assertStringContainsString( sprintf('

Working Link

', $fileID), $page->Another ); - $this->assertContains( + $this->assertStringContainsString( '

Working Link

', $page->dbObject('Another')->forTemplate() ); diff --git a/tests/php/Shortcodes/FileShortcodeProviderTest.php b/tests/php/Shortcodes/FileShortcodeProviderTest.php index 512748f0..05b0ff9e 100644 --- a/tests/php/Shortcodes/FileShortcodeProviderTest.php +++ b/tests/php/Shortcodes/FileShortcodeProviderTest.php @@ -23,7 +23,7 @@ class FileShortcodeProviderTest extends SapphireTest { protected static $fixture_file = '../FileTest.yml'; - public function setUp() + protected function setUp(): void { parent::setUp(); $this->logInWithPermission('ADMIN'); @@ -49,7 +49,7 @@ public function setUp() } } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); diff --git a/tests/php/Shortcodes/ImageShortcodeProviderTest.php b/tests/php/Shortcodes/ImageShortcodeProviderTest.php index 4c16f375..be43739f 100644 --- a/tests/php/Shortcodes/ImageShortcodeProviderTest.php +++ b/tests/php/Shortcodes/ImageShortcodeProviderTest.php @@ -18,7 +18,7 @@ class ImageShortcodeProviderTest extends SapphireTest protected static $fixture_file = '../ImageTest.yml'; - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -34,7 +34,7 @@ public function setUp() } } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); @@ -160,23 +160,23 @@ public function testLazyLoading() // regular shortcode $shortcode = '[image id="' . $id . '" width="300" height="200"]'; - $this->assertContains('loading="lazy"', $parser->parse($shortcode)); + $this->assertStringContainsString('loading="lazy"', $parser->parse($shortcode)); // missing width $shortcode = '[image id="' . $id . '" height="200"]'; - $this->assertNotContains('loading="lazy"', $parser->parse($shortcode)); + $this->assertStringNotContainsString('loading="lazy"', $parser->parse($shortcode)); // missing height $shortcode = '[image id="' . $id . '" width="300"]'; - $this->assertNotContains('loading="lazy"', $parser->parse($shortcode)); + $this->assertStringNotContainsString('loading="lazy"', $parser->parse($shortcode)); // loading="eager" $shortcode = '[image id="' . $id . '" width="300" height="200" loading="eager"]'; - $this->assertNotContains('loading="lazy"', $parser->parse($shortcode)); + $this->assertStringNotContainsString('loading="lazy"', $parser->parse($shortcode)); // loading="nonsense" $shortcode = '[image id="' . $id . '" width="300" height="200" loading="nonsense"]'; - $this->assertContains('loading="lazy"', $parser->parse($shortcode)); + $this->assertStringContainsString('loading="lazy"', $parser->parse($shortcode)); // globally disabled Config::withConfig(function () use ($id, $parser) { @@ -184,7 +184,7 @@ public function testLazyLoading() // clear-provider-cache is so that we don't get a cached result from the 'regular shortcode' // assertion earlier in this function from ImageShortCodeProvider::handle_shortcode() $shortcode = '[image id="' . $id . '" width="300" height="200" clear-provider-cache="1"]'; - $this->assertNotContains('loading="lazy"', $parser->parse($shortcode)); + $this->assertStringNotContainsString('loading="lazy"', $parser->parse($shortcode)); }); } } diff --git a/tests/php/Storage/AssetStoreTest.php b/tests/php/Storage/AssetStoreTest.php index e05cddd5..fac99de2 100644 --- a/tests/php/Storage/AssetStoreTest.php +++ b/tests/php/Storage/AssetStoreTest.php @@ -24,7 +24,7 @@ class AssetStoreTest extends SapphireTest /** * @skipUpgrade */ - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -32,7 +32,7 @@ public function setUp() TestAssetStore::activate('AssetStoreTest'); } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); @@ -604,8 +604,8 @@ public function testProtect() // Test protected file storage $backend->protect($fishTuple['Filename'], $fishTuple['Hash']); - $this->assertFileNotExists(ASSETS_PATH . '/AssetStoreTest/parent/lovely-fish.jpg'); - $this->assertFileNotExists(ASSETS_PATH . '/AssetStoreTest/parent/lovely-fish__copy.jpg'); + $this->assertFileDoesNotExist(ASSETS_PATH . '/AssetStoreTest/parent/lovely-fish.jpg'); + $this->assertFileDoesNotExist(ASSETS_PATH . '/AssetStoreTest/parent/lovely-fish__copy.jpg'); $this->assertFileExists(ASSETS_PATH . '/AssetStoreTest/.protected/parent/a870de278b/lovely-fish.jpg'); $this->assertFileExists(ASSETS_PATH . '/AssetStoreTest/.protected/parent/a870de278b/lovely-fish__copy.jpg'); $this->assertEquals( @@ -633,8 +633,8 @@ public function testProtect() $backend->publish($fishTuple['Filename'], $fishTuple['Hash']); $this->assertFileExists(ASSETS_PATH . '/AssetStoreTest/parent/lovely-fish.jpg'); $this->assertFileExists(ASSETS_PATH . '/AssetStoreTest/parent/lovely-fish__copy.jpg'); - $this->assertFileNotExists(ASSETS_PATH . '/AssetStoreTest/.protected/parent/a870de278b/lovely-fish.jpg'); - $this->assertFileNotExists(ASSETS_PATH . '/AssetStoreTest/.protected/parent/a870de278b/lovely-fish__copy.jpg'); + $this->assertFileDoesNotExist(ASSETS_PATH . '/AssetStoreTest/.protected/parent/a870de278b/lovely-fish.jpg'); + $this->assertFileDoesNotExist(ASSETS_PATH . '/AssetStoreTest/.protected/parent/a870de278b/lovely-fish__copy.jpg'); $this->assertEquals( AssetStore::VISIBILITY_PUBLIC, $backend->getVisibility($fishTuple['Filename'], $fishTuple['Hash']) diff --git a/tests/php/Storage/DBFileTest.php b/tests/php/Storage/DBFileTest.php index 21c3fee9..9108a0c2 100644 --- a/tests/php/Storage/DBFileTest.php +++ b/tests/php/Storage/DBFileTest.php @@ -21,7 +21,7 @@ class DBFileTest extends SapphireTest protected $usesDatabase = true; - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -30,7 +30,7 @@ public function setUp() Director::config()->update('alternate_base_url', '/mysite/'); } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); @@ -54,7 +54,7 @@ public function testRender() // Test download tag $obj->MyFile->setFromString('puppies', 'subdir/puppy-document.txt'); - $this->assertContains( + $this->assertStringContainsString( '', trim($obj->MyFile->forTemplate()) ); diff --git a/tests/php/Storage/Sha1FileHashingServiceTest.php b/tests/php/Storage/Sha1FileHashingServiceTest.php index bda3f3e7..8a4f2871 100644 --- a/tests/php/Storage/Sha1FileHashingServiceTest.php +++ b/tests/php/Storage/Sha1FileHashingServiceTest.php @@ -40,7 +40,7 @@ class Sha1FileHashingServiceTest extends SapphireTest private $fileID = 'Sha1FileHashingServiceTest/Pangram.txt'; - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -59,7 +59,7 @@ public function setUp() Sha1FileHashingService::flush(); } - public function tearDown() + protected function tearDown(): void { parent::tearDown(); $this->publicFs->deleteDir('Sha1FileHashingServiceTest'); @@ -110,7 +110,7 @@ public function testComputeMissingFile() public function testComputeBadFilesystem() { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $service = new Sha1FileHashingService(); $service->computeFromFile($this->fileID, AssetStore::CONFLICT_OVERWRITE); } @@ -174,7 +174,7 @@ public function testCompare() public function testCompareWithEmptyFirstHash() { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $service = new Sha1FileHashingService(); $this->assertTrue($service->compare('', $this->protectedHash)); @@ -182,7 +182,7 @@ public function testCompareWithEmptyFirstHash() public function testCompareWithEmptySecondHash() { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $service = new Sha1FileHashingService(); $this->assertTrue($service->compare($this->protectedHash, '')); @@ -266,8 +266,8 @@ public function testInvalidCharacterCacheKey() ['Mit_Teamgeist_zum_großen_Paddelerlebnis.pdf', 'file-system'] ); - $this->assertNotContains('/', $cacheKey); + $this->assertStringNotContainsString('/', $cacheKey); // Ensure we get a string back after validating the key and it is therefore valid - $this->assertInternalType('string', CacheItem::validateKey($cacheKey)); + $this->assertIsString(CacheItem::validateKey($cacheKey)); } } diff --git a/tests/php/UploadTest.php b/tests/php/UploadTest.php index 2925b728..9891eae7 100644 --- a/tests/php/UploadTest.php +++ b/tests/php/UploadTest.php @@ -35,7 +35,7 @@ class UploadTest extends SapphireTest /** * {@inheritDoc} */ - public function setUp() + protected function setUp(): void { parent::setUp(); Versioned::set_stage(Versioned::DRAFT); @@ -48,7 +48,7 @@ public function setUp() /** * {@inheritDoc} */ - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); parent::tearDown(); @@ -482,8 +482,8 @@ public function testUploadIntoFileStoresProtectedFilesInsideProtectedFolderWhenC // Ensure that the file has been written to a protected folder $filePath = TestAssetStore::getLocalPath($file); $this->assertFileExists($filePath, 'Test file should be uploaded'); - $this->assertContains('.protected', $filePath, 'Test file path should be protected'); - $this->assertContains('my-secret-folder', $filePath, 'Test file should be stored under secret folder'); + $this->assertStringContainsString('.protected', $filePath, 'Test file path should be protected'); + $this->assertStringContainsString('my-secret-folder', $filePath, 'Test file should be stored under secret folder'); $this->assertSame( AssetStore::VISIBILITY_PROTECTED, $file->getVisibility(), @@ -519,8 +519,8 @@ public function testUploadIntoFileStoresPublicFilesInsidePublicFolderWhenCanView // Ensure that the file has been written to a protected folder $filePath = TestAssetStore::getLocalPath($file); $this->assertFileExists($filePath, 'Test file should be uploaded'); - $this->assertNotContains('.protected', $filePath, 'Test file path should be public'); - $this->assertContains('my-public-folder', $filePath, 'Test file should be stored under public folder'); + $this->assertStringNotContainsString('.protected', $filePath, 'Test file path should be public'); + $this->assertStringContainsString('my-public-folder', $filePath, 'Test file should be stored under public folder'); $this->assertSame( AssetStore::VISIBILITY_PUBLIC, $file->getVisibility(), @@ -556,8 +556,8 @@ public function testUploadIntoFileStoresProtectedFilesInsidePublicFolderWhenCanV // Ensure that the file has been written to a protected folder $filePath = TestAssetStore::getLocalPath($file); $this->assertFileExists($filePath, 'Test file should be uploaded'); - $this->assertContains('.protected', $filePath, 'Test file path should be protected'); - $this->assertContains('my-public-folder', $filePath, 'Test file should be stored under public folder'); + $this->assertStringContainsString('.protected', $filePath, 'Test file path should be protected'); + $this->assertStringContainsString('my-public-folder', $filePath, 'Test file should be stored under public folder'); $this->assertSame( AssetStore::VISIBILITY_PROTECTED, $file->getVisibility(), @@ -593,8 +593,8 @@ public function testUploadIntoFileStoresPublicFilesInsideProtectedFolderWhenCanV // Ensure that the file has been written to a protected folder $filePath = TestAssetStore::getLocalPath($file); $this->assertFileExists($filePath, 'Test file should be uploaded'); - $this->assertNotContains('.protected', $filePath, 'Test file path should be public'); - $this->assertContains('my-protected-folder', $filePath, 'Test file should be stored under protected folder'); + $this->assertStringNotContainsString('.protected', $filePath, 'Test file path should be public'); + $this->assertStringContainsString('my-protected-folder', $filePath, 'Test file should be stored under protected folder'); $this->assertSame( AssetStore::VISIBILITY_PUBLIC, $file->getVisibility(), diff --git a/tests/php/VersionedFilesMigratorTest.php b/tests/php/VersionedFilesMigratorTest.php index a2b00788..64e3411d 100644 --- a/tests/php/VersionedFilesMigratorTest.php +++ b/tests/php/VersionedFilesMigratorTest.php @@ -31,7 +31,7 @@ protected function getBasePath() } - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -45,7 +45,7 @@ public function setUp() } } - public function tearDown() + protected function tearDown(): void { TestAssetStore::reset(); Filesystem::removeFolder($this->getBasePath());