From a6cdf64cb67ad3820d33ff98d83a513ad6a076ae Mon Sep 17 00:00:00 2001 From: Adrian Jimson Date: Wed, 11 Jun 2025 13:52:26 +1200 Subject: [PATCH 1/7] Silverstripe 6 compatibility --- src/Extensions/CacheKeyExtension.php | 4 ++-- src/Extensions/FluentExtension.php | 4 ++-- src/Extensions/StagingExtension.php | 4 ++-- src/Models/CacheKey.php | 2 +- src/RelationshipGraph/Graph.php | 4 ++-- src/Services/CacheProcessingService.php | 2 +- tests/Extensions/CacheKeyExtensionTest.php | 2 +- tests/Scenarios/CaresTest.php | 4 ++-- tests/Scenarios/DotNotationCaresTest.php | 2 +- tests/Scenarios/DotNotationTouchesTest.php | 2 +- tests/Scenarios/ExtendedCaresTest.php | 2 +- tests/Scenarios/ExtendedTouchesTest.php | 2 +- tests/Scenarios/TouchesTest.php | 2 +- 13 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Extensions/CacheKeyExtension.php b/src/Extensions/CacheKeyExtension.php index 832265a..a6f2920 100644 --- a/src/Extensions/CacheKeyExtension.php +++ b/src/Extensions/CacheKeyExtension.php @@ -3,10 +3,10 @@ namespace Terraformers\KeysForCache\Extensions; use SilverStripe\Core\Config\Config; +use SilverStripe\Core\Extension; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridFieldConfig_RecordViewer; -use SilverStripe\ORM\DataExtension; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\HasManyList; use SilverStripe\Versioned\Versioned; @@ -20,7 +20,7 @@ * @property DataObject|Versioned|$this $owner * @method HasManyList|CacheKey CacheKeys() */ -class CacheKeyExtension extends DataExtension +class CacheKeyExtension extends Extension { private static array $has_many = [ // Programmatically we know that we will only ever create one of these CacheKey records per unique DataObject, diff --git a/src/Extensions/FluentExtension.php b/src/Extensions/FluentExtension.php index 43a9d4d..722a00e 100644 --- a/src/Extensions/FluentExtension.php +++ b/src/Extensions/FluentExtension.php @@ -2,11 +2,11 @@ namespace Terraformers\KeysForCache\Extensions; -use SilverStripe\ORM\DataExtension; +use SilverStripe\Core\Extension; use Terraformers\KeysForCache\DataTransferObjects\CacheKeyDto; use TractorCow\Fluent\State\FluentState; -class FluentExtension extends DataExtension +class FluentExtension extends Extension { public function updateCacheKey(CacheKeyDto $cacheKey): void { diff --git a/src/Extensions/StagingExtension.php b/src/Extensions/StagingExtension.php index a35146f..d99ed2e 100644 --- a/src/Extensions/StagingExtension.php +++ b/src/Extensions/StagingExtension.php @@ -3,13 +3,13 @@ namespace Terraformers\KeysForCache\Extensions; use SilverStripe\CMS\Controllers\ContentController; -use SilverStripe\CMS\Model\SiteTreeExtension; +use SilverStripe\Core\Extension; use Terraformers\KeysForCache\State\StagingState; /** * @property ContentController $owner */ -class StagingExtension extends SiteTreeExtension +class StagingExtension extends Extension { public function contentcontrollerInit(ContentController $controller): void { diff --git a/src/Models/CacheKey.php b/src/Models/CacheKey.php index 07db76d..330ba27 100644 --- a/src/Models/CacheKey.php +++ b/src/Models/CacheKey.php @@ -2,8 +2,8 @@ namespace Terraformers\KeysForCache\Models; +use SilverStripe\Core\Validation\ValidationException; use SilverStripe\ORM\DataObject; -use SilverStripe\ORM\ValidationException; use SilverStripe\Versioned\Versioned; use Terraformers\KeysForCache\Extensions\CacheKeyExtension; diff --git a/src/RelationshipGraph/Graph.php b/src/RelationshipGraph/Graph.php index a0a6f1a..152e7e0 100644 --- a/src/RelationshipGraph/Graph.php +++ b/src/RelationshipGraph/Graph.php @@ -10,8 +10,8 @@ use SilverStripe\Core\Flushable; use SilverStripe\Core\Injector\Injectable; use SilverStripe\Core\Injector\Injector; +use SilverStripe\Model\ModelData; use SilverStripe\ORM\DataObject; -use SilverStripe\View\ViewableData; use Terraformers\KeysForCache\Models\CacheKey; class Graph implements Flushable @@ -49,7 +49,7 @@ public function getEdgesFrom(string $from): array // Base classes that show up in every ancestry array $disallowList = [ DataObject::class, - ViewableData::class, + ModelData::class, ]; return array_filter( diff --git a/src/Services/CacheProcessingService.php b/src/Services/CacheProcessingService.php index 25242b8..ec82f13 100644 --- a/src/Services/CacheProcessingService.php +++ b/src/Services/CacheProcessingService.php @@ -4,9 +4,9 @@ use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Injector\Injectable; +use SilverStripe\Model\List\SS_List; use SilverStripe\ORM\DataList; use SilverStripe\ORM\DataObject; -use SilverStripe\ORM\SS_List; use SilverStripe\Versioned\Versioned; use Terraformers\KeysForCache\DataTransferObjects\EdgeUpdateDto; use Terraformers\KeysForCache\Models\CacheKey; diff --git a/tests/Extensions/CacheKeyExtensionTest.php b/tests/Extensions/CacheKeyExtensionTest.php index 26d7db4..92e797d 100644 --- a/tests/Extensions/CacheKeyExtensionTest.php +++ b/tests/Extensions/CacheKeyExtensionTest.php @@ -472,7 +472,7 @@ public function testIgnoreList(): void ); } - public function readingModes(): array + public static function readingModes(): array { return [ [Versioned::DRAFT], diff --git a/tests/Scenarios/CaresTest.php b/tests/Scenarios/CaresTest.php index 49410a9..0cc7099 100644 --- a/tests/Scenarios/CaresTest.php +++ b/tests/Scenarios/CaresTest.php @@ -372,7 +372,7 @@ function () use ($page, $model, $readingMode, $saveMethod, $expectKeyChange): vo ); } - public function readingModes(): array + public static function readingModes(): array { return [ [Versioned::DRAFT], @@ -380,7 +380,7 @@ public function readingModes(): array ]; } - public function readingModesWithSaveMethods(): array + public static function readingModesWithSaveMethods(): array { return [ // If write() is performed on a model then we would expect the CacheKey to be updated in DRAFT only. Since diff --git a/tests/Scenarios/DotNotationCaresTest.php b/tests/Scenarios/DotNotationCaresTest.php index a7acdfe..28059ce 100644 --- a/tests/Scenarios/DotNotationCaresTest.php +++ b/tests/Scenarios/DotNotationCaresTest.php @@ -242,7 +242,7 @@ function () use ($page, $modelOne, $modelTwo, $readingMode, $saveMethod, $expect ); } - public function readingModesWithSaveMethods(): array + public static function readingModesWithSaveMethods(): array { return [ // If write() is performed on a model then we would expect the CacheKey to be updated in DRAFT only. Since diff --git a/tests/Scenarios/DotNotationTouchesTest.php b/tests/Scenarios/DotNotationTouchesTest.php index 7fe4c17..b6b6fc3 100644 --- a/tests/Scenarios/DotNotationTouchesTest.php +++ b/tests/Scenarios/DotNotationTouchesTest.php @@ -247,7 +247,7 @@ function () use ($page, $modelOne, $modelTwo, $readingMode, $saveMethod, $expect ); } - public function readingModesWithSaveMethods(): array + public static function readingModesWithSaveMethods(): array { return [ // If write() is performed on a model then we would expect the CacheKey to be updated in DRAFT only. Since diff --git a/tests/Scenarios/ExtendedCaresTest.php b/tests/Scenarios/ExtendedCaresTest.php index 9ba8fac..4270099 100644 --- a/tests/Scenarios/ExtendedCaresTest.php +++ b/tests/Scenarios/ExtendedCaresTest.php @@ -349,7 +349,7 @@ function () use ($page, $model, $readingMode, $saveMethod, $expectKeyChange): vo ); } - public function readingModesWithSaveMethods(): array + public static function readingModesWithSaveMethods(): array { return [ // If write() is performed on a model then we would expect the CacheKey to be updated in DRAFT only. Since diff --git a/tests/Scenarios/ExtendedTouchesTest.php b/tests/Scenarios/ExtendedTouchesTest.php index fff64ce..559c59f 100644 --- a/tests/Scenarios/ExtendedTouchesTest.php +++ b/tests/Scenarios/ExtendedTouchesTest.php @@ -267,7 +267,7 @@ function () use ($page, $model, $readingMode, $saveMethod, $expectKeyChange): vo ); } - public function readingModesWithSaveMethods(): array + public static function readingModesWithSaveMethods(): array { return [ // If write() is performed on a model then we would expect the CacheKey to be updated in DRAFT only. Since diff --git a/tests/Scenarios/TouchesTest.php b/tests/Scenarios/TouchesTest.php index 43bfbc1..65a4340 100644 --- a/tests/Scenarios/TouchesTest.php +++ b/tests/Scenarios/TouchesTest.php @@ -258,7 +258,7 @@ function () use ($page, $model, $readingMode, $saveMethod, $expectKeyChange): vo ); } - public function readingModesWithSaveMethods(): array + public static function readingModesWithSaveMethods(): array { return [ // If write() is performed on a model then we would expect the CacheKey to be updated in DRAFT only. Since From b90347cc66b31d98eb23abfe6cdc207c6f1d4d6a Mon Sep 17 00:00:00 2001 From: Adrian Jimson Date: Wed, 11 Jun 2025 15:13:36 +1200 Subject: [PATCH 2/7] Update deps to SS6 latest --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 7b6b871..fd7c165 100644 --- a/composer.json +++ b/composer.json @@ -20,11 +20,11 @@ ], "require": { "php": "^8.1", - "silverstripe/framework": "^5" + "silverstripe/framework": "^6" }, "require-dev": { - "phpunit/phpunit": "^9.5", - "tractorcow/silverstripe-fluent": "^7", + "phpunit/phpunit": "^11", + "tractorcow/silverstripe-fluent": "^8", "slevomat/coding-standard": "~8.8.0" }, "autoload": { From 6a01544ed46f36cd19af1b5fe997651f6b9181fe Mon Sep 17 00:00:00 2001 From: Adrian Jimson Date: Thu, 12 Jun 2025 13:35:42 +1200 Subject: [PATCH 3/7] phpunit 11 updates --- tests/Extensions/CacheKeyExtensionTest.php | 9 ++--- tests/Scenarios/CaresTest.php | 41 ++++++-------------- tests/Scenarios/DotNotationCaresTest.php | 17 +++----- tests/Scenarios/DotNotationTouchesTest.php | 17 +++----- tests/Scenarios/ExtendedCaresTest.php | 45 +++++++--------------- tests/Scenarios/ExtendedTouchesTest.php | 33 +++++----------- tests/Scenarios/GlobalCaresTest.php | 7 ++-- tests/Scenarios/TouchesTest.php | 33 +++++----------- 8 files changed, 58 insertions(+), 144 deletions(-) diff --git a/tests/Extensions/CacheKeyExtensionTest.php b/tests/Extensions/CacheKeyExtensionTest.php index 92e797d..f2228d8 100644 --- a/tests/Extensions/CacheKeyExtensionTest.php +++ b/tests/Extensions/CacheKeyExtensionTest.php @@ -3,6 +3,7 @@ namespace Terraformers\KeysForCache\Tests\Extensions; use Page; +use PHPUnit\Framework\Attributes\DataProvider; use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\DataList; use SilverStripe\Versioned\Versioned; @@ -24,9 +25,7 @@ class CacheKeyExtensionTest extends SapphireTest CachePage::class, ]; - /** - * @dataProvider readingModes - */ + #[DataProvider('readingModes')] public function testWriteGeneratesCacheKey(string $readingMode): void { $page = Versioned::withVersionedMode(static function () use ($readingMode): CachePage { @@ -64,9 +63,7 @@ public function testWriteGeneratesCacheKey(string $readingMode): void }); } - /** - * @dataProvider readingModes - */ + #[DataProvider('readingModes')] public function testWriteDoesNotGenerateCacheKey(string $readingMode): void { Versioned::withVersionedMode(function () use ($readingMode): void { diff --git a/tests/Scenarios/CaresTest.php b/tests/Scenarios/CaresTest.php index 0cc7099..32304c4 100644 --- a/tests/Scenarios/CaresTest.php +++ b/tests/Scenarios/CaresTest.php @@ -2,6 +2,7 @@ namespace Terraformers\KeysForCache\Tests\Scenarios; +use PHPUnit\Framework\Attributes\DataProvider; use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\DataObject; @@ -47,9 +48,7 @@ class CaresTest extends SapphireTest PolymorphicCaredHasMany::class, ]; - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testCaresPureHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -69,9 +68,7 @@ public function testCaresPureHasOne(string $readingMode, string $saveMethod, boo $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testCaresBelongsTo(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -91,9 +88,7 @@ public function testCaresBelongsTo(string $readingMode, string $saveMethod, bool $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testCaresHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -113,9 +108,7 @@ public function testCaresHasOne(string $readingMode, string $saveMethod, bool $e $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModes - */ + #[DataProvider('readingModes')] public function testCaresHasOneNonVersioned(string $readingMode): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -157,9 +150,7 @@ public function testCaresHasOneNonVersioned(string $readingMode): void }); } - /** - * @dataProvider readingModes - */ + #[DataProvider('readingModes')] public function testCaresHasOneVersionedNonStaged(string $readingMode): void { $page = $this->objFromFixture(CaresPage::class, 'page1'); @@ -198,9 +189,7 @@ public function testCaresHasOneVersionedNonStaged(string $readingMode): void }); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testPolymorphicCaresHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -220,9 +209,7 @@ public function testPolymorphicCaresHasOne(string $readingMode, string $saveMeth $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testCaresHasMany(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -238,9 +225,7 @@ public function testCaresHasMany(string $readingMode, string $saveMethod, bool $ $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testPolymorphicCaresHasMany(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -256,9 +241,7 @@ public function testPolymorphicCaresHasMany(string $readingMode, string $saveMet $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testManyMany(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -278,9 +261,7 @@ public function testManyMany(string $readingMode, string $saveMethod, bool $expe $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testManyManyThrough(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off diff --git a/tests/Scenarios/DotNotationCaresTest.php b/tests/Scenarios/DotNotationCaresTest.php index 28059ce..c4a20e7 100644 --- a/tests/Scenarios/DotNotationCaresTest.php +++ b/tests/Scenarios/DotNotationCaresTest.php @@ -2,6 +2,7 @@ namespace Terraformers\KeysForCache\Tests\Scenarios; +use PHPUnit\Framework\Attributes\DataProvider; use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\DataObject; @@ -29,9 +30,7 @@ class DotNotationCaresTest extends SapphireTest DotNotationCaredHasOne::class, ]; - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testCaresPureHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -55,9 +54,7 @@ public function testCaresPureHasOne(string $readingMode, string $saveMethod, boo $this->assertCacheKeyChanges($page, $modelOne, $modelTwo, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testCaresBelongsTo(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -122,9 +119,7 @@ function () use ($page, $modelOne, $modelTwo, $readingMode, $saveMethod, $expect ); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testCaresHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -148,9 +143,7 @@ public function testCaresHasOne(string $readingMode, string $saveMethod, bool $e $this->assertCacheKeyChanges($page, $modelOne, $modelTwo, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testCaresHasMany(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off diff --git a/tests/Scenarios/DotNotationTouchesTest.php b/tests/Scenarios/DotNotationTouchesTest.php index b6b6fc3..c8587c6 100644 --- a/tests/Scenarios/DotNotationTouchesTest.php +++ b/tests/Scenarios/DotNotationTouchesTest.php @@ -2,6 +2,7 @@ namespace Terraformers\KeysForCache\Tests\Scenarios; +use PHPUnit\Framework\Attributes\DataProvider; use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\DataObject; @@ -33,9 +34,7 @@ class DotNotationTouchesTest extends SapphireTest DotNotationTouchesBelongsTo::class, ]; - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testTouchesHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -59,9 +58,7 @@ public function testTouchesHasOne(string $readingMode, string $saveMethod, bool $this->assertCacheKeyChanges($page, $modelOne, $modelTwo, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testTouchesPureHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -85,9 +82,7 @@ public function testTouchesPureHasOne(string $readingMode, string $saveMethod, b $this->assertCacheKeyChanges($page, $modelOne, $modelTwo, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testTouchesHasMany(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -111,9 +106,7 @@ public function testTouchesHasMany(string $readingMode, string $saveMethod, bool $this->assertCacheKeyChanges($page, $modelOne, $modelTwo, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testTouchesBelongsTo(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off diff --git a/tests/Scenarios/ExtendedCaresTest.php b/tests/Scenarios/ExtendedCaresTest.php index 4270099..3fc6427 100644 --- a/tests/Scenarios/ExtendedCaresTest.php +++ b/tests/Scenarios/ExtendedCaresTest.php @@ -2,6 +2,7 @@ namespace Terraformers\KeysForCache\Tests\Scenarios; +use PHPUnit\Framework\Attributes\DataProvider; use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\DataObject; @@ -53,9 +54,7 @@ class ExtendedCaresTest extends SapphireTest PolymorphicCaredHasOne::class, ]; - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testCaresPureHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -75,9 +74,7 @@ public function testCaresPureHasOne(string $readingMode, string $saveMethod, boo $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testCaresBelongsTo(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -97,9 +94,7 @@ public function testCaresBelongsTo(string $readingMode, string $saveMethod, bool $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testCaresHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -119,9 +114,7 @@ public function testCaresHasOne(string $readingMode, string $saveMethod, bool $e $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testPolymorphicCaresHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -141,9 +134,7 @@ public function testPolymorphicCaresHasOne(string $readingMode, string $saveMeth $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testExtendedPolymorphicCaresHasOne( string $readingMode, string $saveMethod, @@ -166,9 +157,7 @@ public function testExtendedPolymorphicCaresHasOne( $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testCaresHasMany(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -184,9 +173,7 @@ public function testCaresHasMany(string $readingMode, string $saveMethod, bool $ $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testPolymorphicCaresHasMany(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -202,9 +189,7 @@ public function testPolymorphicCaresHasMany(string $readingMode, string $saveMet $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testExtendedPolymorphicCaresHasMany( string $readingMode, string $saveMethod, @@ -225,9 +210,8 @@ public function testExtendedPolymorphicCaresHasMany( /** * Testing that Base relationships work when the explicit class is used in the relationship - * - * @dataProvider readingModesWithSaveMethods */ + #[DataProvider('readingModesWithSaveMethods')] public function testBaseCaredHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -245,9 +229,8 @@ public function testBaseCaredHasOne(string $readingMode, string $saveMethod, boo /** * Testing that Base relationships work when the explicit class is used in the relationship - * - * @dataProvider readingModesWithSaveMethods */ + #[DataProvider('readingModesWithSaveMethods')] public function testBaseCaredHasMany(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -265,9 +248,8 @@ public function testBaseCaredHasMany(string $readingMode, string $saveMethod, bo /** * Now testing that a relationship to a Base class still works when the related object is an extended class - * - * @dataProvider readingModesWithSaveMethods */ + #[DataProvider('readingModesWithSaveMethods')] public function testExtendedCaredHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off @@ -287,9 +269,8 @@ public function testExtendedCaredHasOne(string $readingMode, string $saveMethod, /** * Now testing that a relationship to a Base class still works when the related object is an extended class - * - * @dataProvider readingModesWithSaveMethods */ + #[DataProvider('readingModesWithSaveMethods')] public function testExtendedCaredHasMany(string $readingMode, string $saveMethod, bool $expectKeyChange): void { // Updates are processed as part of scaffold, so we need to flush before we kick off diff --git a/tests/Scenarios/ExtendedTouchesTest.php b/tests/Scenarios/ExtendedTouchesTest.php index 559c59f..9edb147 100644 --- a/tests/Scenarios/ExtendedTouchesTest.php +++ b/tests/Scenarios/ExtendedTouchesTest.php @@ -2,6 +2,7 @@ namespace Terraformers\KeysForCache\Tests\Scenarios; +use PHPUnit\Framework\Attributes\DataProvider; use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\DataObject; @@ -51,9 +52,7 @@ class ExtendedTouchesTest extends SapphireTest TouchesBelongsTo::class, ]; - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testTouchesHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { $page = $this->objFromFixture(ExtendedTouchesPage::class, 'page1'); @@ -70,9 +69,7 @@ public function testTouchesHasOne(string $readingMode, string $saveMethod, bool $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testTouchesTrueHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { $page = $this->objFromFixture(ExtendedTouchesPage::class, 'page1'); @@ -89,9 +86,7 @@ public function testTouchesTrueHasOne(string $readingMode, string $saveMethod, b $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testPolymorphicTouchesHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { $page = $this->objFromFixture(ExtendedTouchesPage::class, 'page1'); @@ -108,9 +103,7 @@ public function testPolymorphicTouchesHasOne(string $readingMode, string $saveMe $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testExtendedPolymorphicTouchesHasOne( string $readingMode, string $saveMethod, @@ -130,9 +123,7 @@ public function testExtendedPolymorphicTouchesHasOne( $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testTouchesHasMany(string $readingMode, string $saveMethod, bool $expectKeyChange): void { $page = $this->objFromFixture(ExtendedTouchesPage::class, 'page1'); @@ -145,9 +136,7 @@ public function testTouchesHasMany(string $readingMode, string $saveMethod, bool $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testPolymorphicTouchesHasMany(string $readingMode, string $saveMethod, bool $expectKeyChange): void { $page = $this->objFromFixture(ExtendedTouchesPage::class, 'page1'); @@ -160,9 +149,7 @@ public function testPolymorphicTouchesHasMany(string $readingMode, string $saveM $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testExtendedPolymorphicTouchesHasMany( string $readingMode, string $saveMethod, @@ -178,9 +165,7 @@ public function testExtendedPolymorphicTouchesHasMany( $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testTouchesBelongsTo(string $readingMode, string $saveMethod, bool $expectKeyChange): void { $page = $this->objFromFixture(ExtendedTouchedPage::class, 'page1'); diff --git a/tests/Scenarios/GlobalCaresTest.php b/tests/Scenarios/GlobalCaresTest.php index 422ee90..81bd618 100644 --- a/tests/Scenarios/GlobalCaresTest.php +++ b/tests/Scenarios/GlobalCaresTest.php @@ -2,6 +2,7 @@ namespace Terraformers\KeysForCache\Tests\Scenarios; +use PHPUnit\Framework\Attributes\DataProvider; use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\SapphireTest; use SilverStripe\SiteConfig\SiteConfig; @@ -23,9 +24,7 @@ class GlobalCaresTest extends SapphireTest GlobalCaresPage::class, ]; - /** - * @dataProvider readingModes - */ + #[DataProvider('readingModes')] public function testGlobalCares(string $readingMode): void { $siteConfig = SiteConfig::current_site_config(); @@ -67,7 +66,7 @@ public function testGlobalCares(string $readingMode): void }); } - public function readingModes(): array + public static function readingModes(): array { return [ [Versioned::DRAFT], diff --git a/tests/Scenarios/TouchesTest.php b/tests/Scenarios/TouchesTest.php index 65a4340..ec3459d 100644 --- a/tests/Scenarios/TouchesTest.php +++ b/tests/Scenarios/TouchesTest.php @@ -2,6 +2,7 @@ namespace Terraformers\KeysForCache\Tests\Scenarios; +use PHPUnit\Framework\Attributes\DataProvider; use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\DataObject; @@ -43,9 +44,7 @@ class TouchesTest extends SapphireTest TouchesBelongsTo::class, ]; - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testTouchesHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { $page = $this->objFromFixture(TouchesPage::class, 'page1'); @@ -62,9 +61,7 @@ public function testTouchesHasOne(string $readingMode, string $saveMethod, bool $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testTouchesTrueHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { $page = $this->objFromFixture(TouchesPage::class, 'page1'); @@ -81,9 +78,7 @@ public function testTouchesTrueHasOne(string $readingMode, string $saveMethod, b $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testPolymorphicTouchesHasOne(string $readingMode, string $saveMethod, bool $expectKeyChange): void { $page = $this->objFromFixture(TouchesPage::class, 'page1'); @@ -100,9 +95,7 @@ public function testPolymorphicTouchesHasOne(string $readingMode, string $saveMe $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testTouchesHasMany(string $readingMode, string $saveMethod, bool $expectKeyChange): void { $page = $this->objFromFixture(TouchesPage::class, 'page1'); @@ -115,9 +108,7 @@ public function testTouchesHasMany(string $readingMode, string $saveMethod, bool $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testPolymorphicTouchesHasMany(string $readingMode, string $saveMethod, bool $expectKeyChange): void { $page = $this->objFromFixture(TouchesPage::class, 'page1'); @@ -130,9 +121,7 @@ public function testPolymorphicTouchesHasMany(string $readingMode, string $saveM $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testTouchesManyMany(string $readingMode, string $saveMethod, bool $expectKeyChange): void { $page = $this->objFromFixture(TouchesPage::class, 'page1'); @@ -149,9 +138,7 @@ public function testTouchesManyMany(string $readingMode, string $saveMethod, boo $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testTouchesThrough(string $readingMode, string $saveMethod, bool $expectKeyChange): void { $page = $this->objFromFixture(TouchesPage::class, 'page1'); @@ -168,9 +155,7 @@ public function testTouchesThrough(string $readingMode, string $saveMethod, bool $this->assertCacheKeyChanges($page, $model, $readingMode, $saveMethod, $expectKeyChange); } - /** - * @dataProvider readingModesWithSaveMethods - */ + #[DataProvider('readingModesWithSaveMethods')] public function testTouchesBelongsTo(string $readingMode, string $saveMethod, bool $expectKeyChange): void { $page = $this->objFromFixture(TouchedPage::class, 'page1'); From 2c0578356bb8a681b348f4e49dc99042ff0b4de7 Mon Sep 17 00:00:00 2001 From: Mohamed Alsharaf Date: Tue, 1 Jul 2025 12:40:07 +1200 Subject: [PATCH 4/7] MISC: Update .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index f8c142e..65779aa 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ node_modules /vendor/ .DS_Store .idea +.phpunit.result.cache +app/ +composer.lock +public/ From 67fc61e618f803ef384bb13db70c6ba07dd411ed Mon Sep 17 00:00:00 2001 From: Mohamed Alsharaf Date: Tue, 1 Jul 2025 12:42:08 +1200 Subject: [PATCH 5/7] Add CMS as dev dependency for unit tests --- composer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index fd7c165..d7c352d 100644 --- a/composer.json +++ b/composer.json @@ -23,9 +23,10 @@ "silverstripe/framework": "^6" }, "require-dev": { - "phpunit/phpunit": "^11", + "phpunit/phpunit": "^11.5", "tractorcow/silverstripe-fluent": "^8", - "slevomat/coding-standard": "~8.8.0" + "slevomat/coding-standard": "~8.8.0", + "silverstripe/cms": "^6" }, "autoload": { "psr-4": { From 21828c13b73940756762eaf4490439423c85f107 Mon Sep 17 00:00:00 2001 From: Mohamed Alsharaf Date: Tue, 1 Jul 2025 12:42:36 +1200 Subject: [PATCH 6/7] Update phpunit xml file to compatible with v11 --- phpunit.xml.dist | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2dbbe21..a78a9fa 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,16 +1,14 @@ - - - - - tests - - - - - src/ - - tests/ - - - + + + + tests/ + + + + src/ + + + tests/ + + From 3b40994123d53b83430e0ca727c85e9d718407db Mon Sep 17 00:00:00 2001 From: Mohamed Alsharaf Date: Tue, 1 Jul 2025 14:35:36 +1200 Subject: [PATCH 7/7] Remove tests folder from phpcs check PHPCS does not suppot the data provider in tests! --- phpcs.xml.dist | 1 - 1 file changed, 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 06da3fd..35c715a 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -3,7 +3,6 @@ CodeSniffer ruleset for SilverStripe coding conventions. src - tests