Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ node_modules
/vendor/
.DS_Store
.idea
.phpunit.result.cache
app/
composer.lock
public/
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
],
"require": {
"php": "^8.1",
"silverstripe/framework": "^5"
"silverstripe/framework": "^6"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"tractorcow/silverstripe-fluent": "^7",
"slevomat/coding-standard": "~8.8.0"
"phpunit/phpunit": "^11.5",
"tractorcow/silverstripe-fluent": "^8",
"slevomat/coding-standard": "~8.8.0",
"silverstripe/cms": "^6"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 0 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>

<file>src</file>
<file>tests</file>
Copy link
Copy Markdown
Collaborator

@satrun77 satrun77 Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the best option, but PHPCS is failing to understand #[DataProvider('readingModes')].

Unable to find a solution for it. This can be rewritten without the PHP Attributes or exclude tests from PHPCS until it supports it!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be fine with tests being excluded from PHPCS

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 🙏 Who can merge and tag a release?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone in the Terraformers team, or me next month once I'm (slightly) freed from my current deadlines.

@thats4shaw @mfendeksilverstripe if anyone has someone available to test/review/etc.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@satrun77 @chrispenny I've got some time blocked out next week to get this sorted out.

Apologies for the delay here, the team was been slammed.


<!-- Show progress and output sniff names on violation, and add colours -->
<arg value="p" />
Expand Down
28 changes: 13 additions & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="Default">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
</whitelist>
</filter>
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd">
<testsuite name="Default">
<directory>tests/</directory>
</testsuite>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
</source>
</phpunit>
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