From 72b319f6638b52055abcc19fae4537ddb3e92f0c Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 19 Oct 2021 14:04:48 +1300 Subject: [PATCH] API phpunit9 support --- composer.json | 2 +- phpunit.xml.dist | 8 +++++--- tests/ErrorPageFileExtensionTest.php | 4 ++-- tests/ErrorPageTest.php | 16 ++++++++-------- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index dd59489..d23f731 100755 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "silverstripe/vendor-plugin": "^1.0" }, "require-dev": { - "sminnee/phpunit": "^5.7", + "phpunit/phpunit": "^9", "squizlabs/php_codesniffer": "^3" }, "scripts": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b543ea6..ab41986 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,9 @@ - - tests/ - + + + tests/ + + src/ diff --git a/tests/ErrorPageFileExtensionTest.php b/tests/ErrorPageFileExtensionTest.php index aaa1c71..4480ed1 100644 --- a/tests/ErrorPageFileExtensionTest.php +++ b/tests/ErrorPageFileExtensionTest.php @@ -19,7 +19,7 @@ class ErrorPageFileExtensionTest extends SapphireTest protected $versionedMode = null; - public function setUp() + protected function setUp(): void { parent::setUp(); $this->versionedMode = Versioned::get_reading_mode(); @@ -34,7 +34,7 @@ public function setUp() $file->write(); } - public function tearDown() + protected function tearDown(): void { Versioned::set_reading_mode($this->versionedMode); TestAssetStore::reset(); diff --git a/tests/ErrorPageTest.php b/tests/ErrorPageTest.php index 27f8dcf..8dfff69 100644 --- a/tests/ErrorPageTest.php +++ b/tests/ErrorPageTest.php @@ -34,7 +34,7 @@ class ErrorPageTest extends FunctionalTest */ protected $tmpAssetsPath = ''; - public function setUp() + protected function setUp(): void { parent::setUp(); // Set temporary asset backend store @@ -43,7 +43,7 @@ public function setUp() $this->logInWithPermission('ADMIN'); } - public function tearDown() + protected function tearDown(): void { DB::quiet(true); TestAssetStore::reset(); @@ -121,7 +121,7 @@ public function testSecurityError() $response = $this->get('Security/nosuchaction'); $this->assertEquals($response->getStatusCode(), '404'); $this->assertNotNull($response->getBody()); - $this->assertContains('text/html', $response->getHeader('Content-Type')); + $this->assertStringContainsString('text/html', $response->getHeader('Content-Type')); } public function testStaticCaching() @@ -130,7 +130,7 @@ public function testStaticCaching() $error = ErrorPage::get_content_for_errorcode('401'); $this->assertEmpty($error); $expectedErrorPagePath = TestAssetStore::base_path() . '/error-401.html'; - $this->assertFileNotExists($expectedErrorPagePath, 'Error page is not automatically cached'); + $this->assertFileDoesNotExist($expectedErrorPagePath, 'Error page is not automatically cached'); // Write new 401 page $page = new ErrorPage(); @@ -178,7 +178,7 @@ public function testGeneratedFile() // Static content is not available $this->assertEmpty(ErrorPage::get_content_for_errorcode('405')); $expectedErrorPagePath = TestAssetStore::base_path() . '/error-405.html'; - $this->assertFileNotExists($expectedErrorPagePath, 'Error page is not cached in static location'); + $this->assertFileDoesNotExist($expectedErrorPagePath, 'Error page is not cached in static location'); } public function testGetByLink() @@ -217,7 +217,7 @@ public function testWriteStaticPageWithDisableStaticFile() 'writeStaticPage should return false when enable_static_file is true' ); $expectedErrorPagePath = TestAssetStore::base_path() . '/error-404.html'; - $this->assertFileNotExists($expectedErrorPagePath, 'Error page should not be cached.'); + $this->assertFileDoesNotExist($expectedErrorPagePath, 'Error page should not be cached.'); } /** @@ -236,9 +236,9 @@ public function testErrorMessageAppended($env, $shouldShowInDev) $response = ErrorPage::response_for(404, 'Really bad error'); $this->assertNotEmpty($response->getBody()); if ($env === 'dev' && $shouldShowInDev) { - $this->assertContains('Really bad error', $response->getBody()); + $this->assertStringContainsString('Really bad error', $response->getBody()); } else { - $this->assertNotContains('Really bad error', $response->getBody()); + $this->assertStringNotContainsString('Really bad error', $response->getBody()); } $kernel->setEnvironment($originalEnv);