From 43d199ae9d43eec92b04ef2c1f1f684ca9e5202c Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 10 Sep 2024 18:00:17 +1200 Subject: [PATCH] DEP Use PHPUnit 11 --- tests/BaseElementTest.php | 35 ++++------- .../ElementSiteTreeFilterSearchTest.php | 31 +++++----- .../ElementalAreaControllerTest.php | 61 +++++++------------ .../ElementalAreasExtensionTest.php | 7 +-- tests/TopPage/TopPageTest.php | 11 ++-- 5 files changed, 57 insertions(+), 88 deletions(-) diff --git a/tests/BaseElementTest.php b/tests/BaseElementTest.php index 2540a9be..e235e67f 100644 --- a/tests/BaseElementTest.php +++ b/tests/BaseElementTest.php @@ -22,6 +22,7 @@ use SilverStripe\Dev\FunctionalTest; use SilverStripe\Forms\FieldList; use SilverStripe\VersionedAdmin\Forms\HistoryViewerField; +use PHPUnit\Framework\Attributes\DataProvider; class BaseElementTest extends FunctionalTest { @@ -275,7 +276,7 @@ public function testUpdateContentForSearchIndex() ElementContent::remove_extension(TestContentForSearchIndexExtension::class); } - public function getElementAnchorDataProvider(): array + public static function getElementAnchorDataProvider(): array { return [ [ @@ -296,9 +297,7 @@ public function getElementAnchorDataProvider(): array ]; } - /** - * @dataProvider getElementAnchorDataProvider - */ + #[DataProvider('getElementAnchorDataProvider')] public function testGetAnchorsInContent(string $elementClass, string $elementName, array $expectedAnchors): void { $element = $this->objFromFixture($elementClass, $elementName); @@ -307,7 +306,7 @@ public function testGetAnchorsInContent(string $elementClass, string $elementNam $this->assertSame($expectedAnchors, array_values($element->getAnchorsInContent())); } - public function getElementCMSLinkDataProvider() + public static function getElementCMSLinkDataProvider() { return [ // Element in DataObject with $directLink === true @@ -351,9 +350,7 @@ public function getElementCMSLinkDataProvider() ]; } - /** - * @dataProvider getElementCMSLinkDataProvider - */ + #[DataProvider('getElementCMSLinkDataProvider')] public function testGetCMSEditLink(string $class, string $element, ?string $link, bool $directLink = false) { $object = $this->objFromFixture($class, $element); @@ -366,7 +363,7 @@ public function testGetCMSEditLink(string $class, string $element, ?string $link } } - public function canDeleteProvider() + public static function canDeleteProvider() { return [ // Element on Page @@ -384,9 +381,7 @@ public function canDeleteProvider() ]; } - /** - * @dataProvider canDeleteProvider - */ + #[DataProvider('canDeleteProvider')] public function testCanDelete( string $class, string $element, @@ -400,7 +395,7 @@ public function testCanDelete( $this->assertTrue($canDelete); } - public function linksProvider() + public static function linksProvider() { return [ // Element on Page @@ -418,18 +413,14 @@ public function linksProvider() ]; } - /** - * @dataProvider linksProvider - */ + #[DataProvider('linksProvider')] public function testLinkWithDataObject(string $class, string $element, ?string $link) { $object = $this->objFromFixture($class, $element); $this->assertEquals($link, $object->Link()); } - /** - * @dataProvider linksProvider - */ + #[DataProvider('linksProvider')] public function testAbsoluteLink(string $class, string $element, ?string $link) { $link = $link ? Director::absoluteURL($link) : $link; @@ -438,7 +429,7 @@ public function testAbsoluteLink(string $class, string $element, ?string $link) $this->assertEquals($link, $absoluteLink); } - public function previewLinksProvider() + public static function previewLinksProvider() { return [ // Element on Page @@ -474,9 +465,7 @@ public function previewLinksProvider() ]; } - /** - * @dataProvider previewLinksProvider - */ + #[DataProvider('previewLinksProvider')] public function testPreviewLink(string $class, string $elementIdentifier, ?string $link) { /** @var BaseElement $element */ diff --git a/tests/Controllers/ElementSiteTreeFilterSearchTest.php b/tests/Controllers/ElementSiteTreeFilterSearchTest.php index da7ae7f3..8ba8fac5 100644 --- a/tests/Controllers/ElementSiteTreeFilterSearchTest.php +++ b/tests/Controllers/ElementSiteTreeFilterSearchTest.php @@ -13,6 +13,7 @@ use SilverStripe\ORM\DataObjectSchema; use DNADesign\Elemental\Models\ElementContent; use DNADesign\Elemental\Tests\Src\TestElementContentExtension; +use PHPUnit\Framework\Attributes\DataProvider; class ElementSiteTreeFilterSearchTest extends SapphireTest { @@ -34,8 +35,8 @@ class ElementSiteTreeFilterSearchTest extends SapphireTest /** * @param string $searchTerm * @param array $expected - * @dataProvider searchProvider */ + #[DataProvider('searchProvider')] public function testElementalPageDataMatchesInCmsSearch($searchTerm, $expected) { $filter = CMSSiteTreeFilter_Search::create(['Term' => $searchTerm]); @@ -47,7 +48,7 @@ public function testElementalPageDataMatchesInCmsSearch($searchTerm, $expected) /** * @return array[] */ - public function searchProvider() + public static function searchProvider() { return [ 'Nested block data' => ['specifically', [ @@ -63,9 +64,7 @@ public function searchProvider() ]; } - /** - * @dataProvider provideApplyDefaultFilters - */ + #[DataProvider('provideApplyDefaultFilters')] public function testApplyDefaultFilters(bool $renderElements, string $term, array $expected): void { // Set protected method visibility - applyDefaultFilters() is essentially an @@ -78,57 +77,57 @@ public function testApplyDefaultFilters(bool $renderElements, string $term, arra $this->assertSame($expected, $ret->column('Title')); } - public function provideApplyDefaultFilters(): array + public static function provideApplyDefaultFilters(): array { return [ 'render_elements true - text search' => [ - 'render_elements' => true, + 'renderElements' => true, 'term' => 'This content is rendered', 'expected' => ['Content blocks page'] ], 'render_elements true - unrendered search' => [ - 'render_elements' => true, + 'renderElements' => true, 'term' => 'This field is unrendered', 'expected' => [] ], 'render_elements true - extended search' => [ - 'render_elements' => true, + 'renderElements' => true, 'term' => 'This content is from an extension hook', 'expected' => [] ], 'render_elements true - int search' => [ - 'render_elements' => true, + 'renderElements' => true, 'term' => '456', 'expected' => [] ], 'render_elements true - enum search' => [ - 'render_elements' => true, + 'renderElements' => true, 'term' => 'Sunny', 'expected' => [] ], 'render_elements false - text search' => [ - 'render_elements' => false, + 'renderElements' => false, 'term' => 'This content is rendered', 'expected' => ['Content blocks page'] ], 'render_elements false - unrendered search' => [ - 'render_elements' => false, + 'renderElements' => false, 'term' => 'This field is unrendered', 'expected' => ['Content blocks page'] ], 'render_elements false - extended search' => [ - 'render_elements' => false, + 'renderElements' => false, 'term' => 'This content is from an extension hook', 'expected' => ['Content blocks page'] ], 'render_elements false - int search' => [ - 'render_elements' => false, + 'renderElements' => false, 'term' => '456', 'expected' => [] ], 'render_elements false - enum search' => [ - 'render_elements' => false, + 'renderElements' => false, 'term' => 'Sunny', 'expected' => [] ], diff --git a/tests/Controllers/ElementalAreaControllerTest.php b/tests/Controllers/ElementalAreaControllerTest.php index 497dd8ac..7cb43910 100644 --- a/tests/Controllers/ElementalAreaControllerTest.php +++ b/tests/Controllers/ElementalAreaControllerTest.php @@ -7,6 +7,7 @@ use DNADesign\Elemental\Tests\Blocks\TestElementContent; use DNADesign\Elemental\Tests\Blocks\TestElementalArea; use Exception; +use PHPUnit\Framework\Attributes\DataProvider; class ElementalAreaControllerTest extends FunctionalTest { @@ -40,7 +41,7 @@ protected function tearDown(): void } } - public function provideElementFormGetSchema(): array + public static function provideElementFormGetSchema(): array { // There specifically isn't an 'invalid / missing' record test here with $idType, as existing behaviour // is to return a 200 with a basically empty schema response. @@ -57,9 +58,7 @@ public function provideElementFormGetSchema(): array ]; } - /** - * @dataProvider provideElementFormGetSchema - */ + #[DataProvider('provideElementFormGetSchema')] public function testElementFormGetSchema( string $fail, int $expectedCode, @@ -89,7 +88,7 @@ public function testElementFormGetSchema( $this->assertFalse(array_key_exists('errors', $formSchema)); } - public function provideElementFormPost(): array + public static function provideElementFormPost(): array { return [ 'Valid update existing record' => [ @@ -149,9 +148,7 @@ public function provideElementFormPost(): array ]; } - /** - * @dataProvider provideElementFormPost - */ + #[DataProvider('provideElementFormPost')] public function testElementFormPost(string $idType, string $dataType, string $fail, int $expectedCode): void { TestElementContent::$fail = $fail; @@ -232,7 +229,7 @@ public function testElementFormPost(string $idType, string $dataType, string $fa } } - public function provideElementFormReadonly(): array + public static function provideElementFormReadonly(): array { return [ 'Can edit' => [ @@ -246,9 +243,7 @@ public function provideElementFormReadonly(): array ]; } - /** - * @dataProvider provideElementFormReadonly - */ + #[DataProvider('provideElementFormReadonly')] public function testElementFormReadonly(string $fail, bool $expected): void { TestElementContent::$fail = $fail; @@ -262,7 +257,7 @@ public function testElementFormReadonly(string $fail, bool $expected): void $this->assertSame($expected, $actual); } - public function provideApiDelete(): array + public static function provideApiDelete(): array { return [ 'Valid' => [ @@ -303,9 +298,7 @@ public function provideApiDelete(): array ]; } - /** - * @dataProvider provideApiDelete - */ + #[DataProvider('provideApiDelete')] public function testApiDelete( string $idType, string $fail, @@ -330,7 +323,7 @@ public function testApiDelete( } } - public function provideApiCreate(): array + public static function provideApiCreate(): array { return [ 'Valid' => [ @@ -386,9 +379,7 @@ public function provideApiCreate(): array ]; } - /** - * @dataProvider provideApiCreate - */ + #[DataProvider('provideApiCreate')] public function testApiCreate( string $fail, ?int $insertAfterElementID, @@ -449,7 +440,7 @@ public function testApiCreate( $this->assertSame($expected, $map); } - public function provideApiDuplicate(): array + public static function provideApiDuplicate(): array { return [ 'Valid' => [ @@ -500,9 +491,7 @@ public function provideApiDuplicate(): array ]; } - /** - * @dataProvider provideApiDuplicate - */ + #[DataProvider('provideApiDuplicate')] public function testApiDuplicate( string $idType, string $fail, @@ -547,7 +536,7 @@ public function testApiDuplicate( } } - public function provideApiPublish(): array + public static function provideApiPublish(): array { return [ 'Valid' => [ @@ -588,9 +577,7 @@ public function provideApiPublish(): array ]; } - /** - * @dataProvider provideApiPublish - */ + #[DataProvider('provideApiPublish')] public function testApiPublish( string $idType, string $fail, @@ -627,7 +614,7 @@ public function testApiPublish( } } - public function provideApiRead(): array + public static function provideApiRead(): array { return [ 'Valid' => [ @@ -668,9 +655,7 @@ public function provideApiRead(): array ]; } - /** - * @dataProvider provideApiRead - */ + #[DataProvider('provideApiRead')] public function testApiRead( string $idType, string $fail, @@ -762,7 +747,7 @@ public function testApiRead( } } - public function provideApiSort(): array + public static function provideApiSort(): array { return [ 'Valid move from first' => [ @@ -816,9 +801,7 @@ public function provideApiSort(): array ]; } - /** - * @dataProvider provideApiSort - */ + #[DataProvider('provideApiSort')] public function testApiSort( string $idType, string $fail, @@ -866,7 +849,7 @@ public function testApiSort( $this->assertSame($expected, $map); } - public function provideApiUnpublish(): array + public static function provideApiUnpublish(): array { return [ 'Valid' => [ @@ -907,9 +890,7 @@ public function provideApiUnpublish(): array ]; } - /** - * @dataProvider provideApiUnpublish - */ + #[DataProvider('provideApiUnpublish')] public function testApiUnpublish( string $idType, string $fail, diff --git a/tests/Extensions/ElementalAreasExtensionTest.php b/tests/Extensions/ElementalAreasExtensionTest.php index 486875a9..2c83a0d9 100644 --- a/tests/Extensions/ElementalAreasExtensionTest.php +++ b/tests/Extensions/ElementalAreasExtensionTest.php @@ -14,6 +14,7 @@ use DNADesign\Elemental\Tests\Src\TestVersionedDataObject; use DNADesign\Elemental\Extensions\ElementalAreasExtension; use SilverStripe\ORM\DB; +use PHPUnit\Framework\Attributes\DataProvider; class ElementalAreasExtensionTest extends SapphireTest { @@ -83,9 +84,7 @@ private function assertContainsInOrder(array $expected, array $actual) $this->assertSame($expected, $matches); } - /** - * @dataProvider provideContentFieldPreservationSettings - */ + #[DataProvider('provideContentFieldPreservationSettings')] public function testContentFieldsAreRemovedByDefault($keepGlobal, $keepClass, $expectedType) { Config::inst()->set(ElementalAreasExtension::class, 'keep_content_fields', $keepGlobal); @@ -104,7 +103,7 @@ public function testContentFieldsAreRemovedByDefault($keepGlobal, $keepClass, $e * * @return array */ - public function provideContentFieldPreservationSettings() + public static function provideContentFieldPreservationSettings() { // Test both unset (null) and explicitly declined (false) where applicable. return [ diff --git a/tests/TopPage/TopPageTest.php b/tests/TopPage/TopPageTest.php index f898be1a..5558fdfa 100644 --- a/tests/TopPage/TopPageTest.php +++ b/tests/TopPage/TopPageTest.php @@ -11,6 +11,7 @@ use SilverStripe\ORM\DataObject; use DNADesign\Elemental\Extensions\TopPageElementExtension; use DNADesign\Elemental\Extensions\TopPageSiteTreeExtension; +use PHPUnit\Framework\Attributes\DataProvider; class TopPageTest extends SapphireTest { @@ -58,8 +59,8 @@ class TopPageTest extends SapphireTest * @param string $pageClass * @param string $objectIdentifier * @param string $objectClass - * @dataProvider objectsProvider */ + #[DataProvider('objectsProvider')] public function testTestGetTopPage( string $pageIdentifier, string $pageClass, @@ -83,8 +84,8 @@ public function testTestGetTopPage( * @param string $pageClass * @param string $objectIdentifier * @param string $objectClass - * @dataProvider objectsProvider */ + #[DataProvider('objectsProvider')] public function testTestUpdateTopPageEmptyCache( string $pageIdentifier, string $pageClass, @@ -127,8 +128,8 @@ public function testNewPage(): void /** * @param bool $populateTopPage - * @dataProvider populateTopPageProvider */ + #[DataProvider('populateTopPageProvider')] public function testNewBlock(bool $populateTopPage): void { if ($populateTopPage) { @@ -151,7 +152,7 @@ public function testNewBlock(bool $populateTopPage): void $this->assertEquals((int) $page->ID, (int) $content->TopPageID); } - public function objectsProvider(): array + public static function objectsProvider(): array { return [ [ @@ -205,7 +206,7 @@ public function objectsProvider(): array ]; } - public function populateTopPageProvider(): array + public static function populateTopPageProvider(): array { return [ [true],