Skip to content

Silverstripe 6 compatibility #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions src/Extensions/CacheKeyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/Extensions/FluentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions src/Extensions/StagingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Models/CacheKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/RelationshipGraph/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/Services/CacheProcessingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 4 additions & 7 deletions tests/Extensions/CacheKeyExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -472,7 +469,7 @@ public function testIgnoreList(): void
);
}

public function readingModes(): array
public static function readingModes(): array
{
return [
[Versioned::DRAFT],
Expand Down
45 changes: 13 additions & 32 deletions tests/Scenarios/CaresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -372,15 +353,15 @@ function () use ($page, $model, $readingMode, $saveMethod, $expectKeyChange): vo
);
}

public function readingModes(): array
public static function readingModes(): array
{
return [
[Versioned::DRAFT],
[Versioned::LIVE],
];
}

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
Expand Down
19 changes: 6 additions & 13 deletions tests/Scenarios/DotNotationCaresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -242,7 +235,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
Expand Down
Loading
Loading