diff --git a/composer.json b/composer.json index 3c487c6..9be166b 100644 --- a/composer.json +++ b/composer.json @@ -16,22 +16,19 @@ }, { "name": "Chris Penny", - "email": "cpenny@silverstripe.com" + "email": "chris.penny@gmail.com" } ], "support": { "issues": "http://github.com/ichaber/silverstripe-swiftype/issues" }, "require": { - "php": "^7.4 || ^8.0", - "silverstripe/vendor-plugin": "^1.6", - "silverstripe/framework": "^4", - "silverstripe/cms": "^4", - "guzzlehttp/guzzle": "^7", - "guzzlehttp/psr7": "^2" + "php": "^8.1", + "silverstripe/cms": "^5", + "guzzlehttp/guzzle": "^7.5" }, "require-dev": { - "silverstripe/recipe-testing": "^2" + "silverstripe/recipe-testing": "^3" }, "autoload": { "psr-4": { diff --git a/src/Extensions/SwiftypeSiteConfigFieldsExtension.php b/src/Extensions/SwiftypeSiteConfigFieldsExtension.php index f655041..82f1521 100644 --- a/src/Extensions/SwiftypeSiteConfigFieldsExtension.php +++ b/src/Extensions/SwiftypeSiteConfigFieldsExtension.php @@ -20,10 +20,7 @@ */ class SwiftypeSiteConfigFieldsExtension extends DataExtension { - /** - * @var array $db - */ - private static $db = [ + private static array $db = [ 'SwiftypeEnabled' => 'Boolean', 'SwiftypeAccessKey' => 'Varchar(255)', 'SwiftypeAPIKey' => 'Varchar(255)', diff --git a/src/Extensions/SwiftypeSiteTreeCrawlerExtension.php b/src/Extensions/SwiftypeSiteTreeCrawlerExtension.php index 222b1c0..d8fa60b 100644 --- a/src/Extensions/SwiftypeSiteTreeCrawlerExtension.php +++ b/src/Extensions/SwiftypeSiteTreeCrawlerExtension.php @@ -18,10 +18,8 @@ class SwiftypeSiteTreeCrawlerExtension extends SiteTreeExtension * Urls to crawl * * array keyed by getOwnerKey - * - * @var array */ - private $urlsToCrawl = []; + private array $urlsToCrawl = []; public function setUrlsToCrawl(array $urls) { diff --git a/src/MetaTags/SwiftypeMetaTag.php b/src/MetaTags/SwiftypeMetaTag.php index ff1a250..a7d6814 100644 --- a/src/MetaTags/SwiftypeMetaTag.php +++ b/src/MetaTags/SwiftypeMetaTag.php @@ -15,20 +15,11 @@ abstract class SwiftypeMetaTag implements SwiftypeMetaTagInterface { use Configurable; - /** - * @var string|null - */ - protected $name; + protected ?string $name; - /** - * @var string|null - */ - protected $fieldName; + protected ?string $fieldName; - /** - * @var string|null - */ - protected $fieldType; + protected ?string $fieldType; public function getMetaTagString(DataObject $dataObject): ?string { diff --git a/src/MetaTags/SwiftypeMetaTagDescription.php b/src/MetaTags/SwiftypeMetaTagDescription.php index 59f5b86..4d855ae 100644 --- a/src/MetaTags/SwiftypeMetaTagDescription.php +++ b/src/MetaTags/SwiftypeMetaTagDescription.php @@ -4,18 +4,9 @@ class SwiftypeMetaTagDescription extends SwiftypeMetaTag { - /** - * @var string - */ - protected $name = 'description'; + protected ?string $name = 'description'; - /** - * @var string - */ - protected $fieldName = 'MetaDescription'; + protected ?string $fieldName = 'MetaDescription'; - /** - * @var string - */ - protected $fieldType = 'text'; + protected ?string $fieldType = 'text'; } diff --git a/src/MetaTags/SwiftypeMetaTagPublishedAt.php b/src/MetaTags/SwiftypeMetaTagPublishedAt.php index 204e3ff..c5f5b62 100644 --- a/src/MetaTags/SwiftypeMetaTagPublishedAt.php +++ b/src/MetaTags/SwiftypeMetaTagPublishedAt.php @@ -4,18 +4,9 @@ class SwiftypeMetaTagPublishedAt extends SwiftypeMetaTag { - /** - * @var string - */ - protected $name = 'published_at'; + protected ?string $name = 'published_at'; - /** - * @var string - */ - protected $fieldName = 'LastEdited'; + protected ?string $fieldName = 'LastEdited'; - /** - * @var string - */ - protected $fieldType = 'date'; + protected ?string $fieldType = 'date'; } diff --git a/src/MetaTags/SwiftypeMetaTagTitle.php b/src/MetaTags/SwiftypeMetaTagTitle.php index f456190..7bf5c75 100644 --- a/src/MetaTags/SwiftypeMetaTagTitle.php +++ b/src/MetaTags/SwiftypeMetaTagTitle.php @@ -4,18 +4,9 @@ class SwiftypeMetaTagTitle extends SwiftypeMetaTag { - /** - * @var string - */ - protected $name = 'title'; + protected ?string $name = 'title'; - /** - * @var string - */ - protected $fieldName = 'Title'; + protected ?string $fieldName = 'Title'; - /** - * @var string - */ - protected $fieldType = 'string'; + protected ?string $fieldType = 'string'; } diff --git a/src/MetaTags/SwiftypeMetaTagURL.php b/src/MetaTags/SwiftypeMetaTagURL.php index 6a8e0bb..c28a7a6 100644 --- a/src/MetaTags/SwiftypeMetaTagURL.php +++ b/src/MetaTags/SwiftypeMetaTagURL.php @@ -4,18 +4,9 @@ class SwiftypeMetaTagURL extends SwiftypeMetaTag { - /** - * @var string - */ - protected $name = 'url'; + protected ?string $name = 'url'; - /** - * @var string|null - */ - protected $fieldName = 'Link'; + protected ?string $fieldName = 'Link'; - /** - * @var string - */ - protected $fieldType = 'enum'; + protected ?string $fieldType = 'enum'; } diff --git a/tests/php/Extensions/SwiftypeMetaTagContentExtensionTest.php b/tests/Extensions/SwiftypeMetaTagContentExtensionTest.php similarity index 91% rename from tests/php/Extensions/SwiftypeMetaTagContentExtensionTest.php rename to tests/Extensions/SwiftypeMetaTagContentExtensionTest.php index 9210def..63fd602 100644 --- a/tests/php/Extensions/SwiftypeMetaTagContentExtensionTest.php +++ b/tests/Extensions/SwiftypeMetaTagContentExtensionTest.php @@ -14,11 +14,6 @@ use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\FieldType\DBHTMLText; -/** - * Class SwiftypeMetaTagContentExtensionTest - * - * @package Ichaber\SSSwiftype\Tests\Extensions - */ class SwiftypeMetaTagContentExtensionTest extends SapphireTest { /** @@ -41,7 +36,7 @@ public function setUp(): void */ public function testMetaTagOutput(): void { - Config::inst()->update( + Config::modify()->set( SwiftypeSiteTree::class, 'swiftype_meta_tag_classes', [ @@ -60,7 +55,7 @@ public function testMetaTagOutput(): void $mock = file_get_contents(__DIR__ . '/../Mock/TagsOutput.html'); $mock = trim(preg_replace("/\s+/S", '', $mock)); - // Remove formatting from output output + // Remove formatting from output $output = trim(preg_replace("/\s+/S", '', $page->getSwiftypeMetaTags()->getValue())); $this->assertEquals($mock, $output); @@ -84,7 +79,7 @@ public function testMetaTagsReturnsConfiguredTags(): void { $page = new SwiftypeSiteTree(); $page->MetaDescription = 'My description'; - $page->config()->update('swiftype_meta_tag_classes', [ + $page->config()->set('swiftype_meta_tag_classes', [ SwiftypeMetaTagDescription::class ]); diff --git a/tests/php/Extensions/SwiftypeMetaTagContentExtensionTest.yml b/tests/Extensions/SwiftypeMetaTagContentExtensionTest.yml similarity index 100% rename from tests/php/Extensions/SwiftypeMetaTagContentExtensionTest.yml rename to tests/Extensions/SwiftypeMetaTagContentExtensionTest.yml diff --git a/tests/php/Extensions/SwiftypeSiteTreeCrawlerExtensionTest.php b/tests/Extensions/SwiftypeSiteTreeCrawlerExtensionTest.php similarity index 94% rename from tests/php/Extensions/SwiftypeSiteTreeCrawlerExtensionTest.php rename to tests/Extensions/SwiftypeSiteTreeCrawlerExtensionTest.php index 0662cbf..9a77b64 100644 --- a/tests/php/Extensions/SwiftypeSiteTreeCrawlerExtensionTest.php +++ b/tests/Extensions/SwiftypeSiteTreeCrawlerExtensionTest.php @@ -9,11 +9,6 @@ use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\SapphireTest; -/** - * Class SwiftypeMetaTagContentExtensionTest - * - * @package Ichaber\SSSwiftype\Tests\Extensions - */ class SwiftypeSiteTreeCrawlerExtensionTest extends SapphireTest { /** @@ -37,7 +32,7 @@ public function setUp(): void public function testUrlsToCrawlPublished(): void { // Set our config to not clear caches after un/publish, so that we can easily fetch the Urls for our test - Config::inst()->update( + Config::modify()->set( SwiftypeSiteTreeCrawlerExtension::class, 'clear_cache_disabled', true @@ -51,7 +46,7 @@ public function testUrlsToCrawlPublished(): void $key = str_replace('\\', '', $page->ClassName . $page->ID); $expectedUrls = [ - 'localhost/page1/', + 'localhost/page1', ]; $urls = []; @@ -81,7 +76,7 @@ public function testUrlsToCrawlPublished(): void public function testUrlsToCrawlUnpublished(): void { // Set our config to not clear caches after un/publish, so that we can easily fetch the Urls for our test - Config::inst()->update( + Config::modify()->set( SwiftypeSiteTreeCrawlerExtension::class, 'clear_cache_disabled', true @@ -100,7 +95,7 @@ public function testUrlsToCrawlUnpublished(): void $page->doUnpublish(); $expectedUrls = [ - 'localhost/page2/', + 'localhost/page2', ]; $urls = []; @@ -130,7 +125,7 @@ public function testUrlsToCrawlUnpublished(): void public function testUrlsToCrawlSegmentChanged(): void { // Set our config to not clear caches after un/publish, so that we can easily fetch the Urls for our test - Config::inst()->update( + Config::modify()->set( SwiftypeSiteTreeCrawlerExtension::class, 'clear_cache_disabled', true @@ -153,8 +148,8 @@ public function testUrlsToCrawlSegmentChanged(): void // We expect two Urls now. One from before the segment change, and one from after it $expectedUrls = [ - 'localhost/page3/', - 'localhost/page3changed/', + 'localhost/page3', + 'localhost/page3changed', ]; $urls = []; diff --git a/tests/php/Extensions/SwiftypeSiteTreeCrawlerExtensionTest.yml b/tests/Extensions/SwiftypeSiteTreeCrawlerExtensionTest.yml similarity index 100% rename from tests/php/Extensions/SwiftypeSiteTreeCrawlerExtensionTest.yml rename to tests/Extensions/SwiftypeSiteTreeCrawlerExtensionTest.yml diff --git a/tests/php/Fake/SwiftypeSiteTree.php b/tests/Fake/SwiftypeSiteTree.php similarity index 92% rename from tests/php/Fake/SwiftypeSiteTree.php rename to tests/Fake/SwiftypeSiteTree.php index e974e59..f3b9f05 100644 --- a/tests/php/Fake/SwiftypeSiteTree.php +++ b/tests/Fake/SwiftypeSiteTree.php @@ -9,9 +9,6 @@ use SilverStripe\Dev\TestOnly; /** - * Class SwiftypeSiteTree - * - * @package Ichaber\SSSwiftype\Tests\Fake * @mixin SwiftypeMetaTagContentExtension * @mixin SwiftypeSiteTreeCrawlerExtension */ diff --git a/tests/php/MetaTags/SwiftypeMetaTagPublishedAtTest.php b/tests/MetaTags/SwiftypeMetaTagPublishedAtTest.php similarity index 79% rename from tests/php/MetaTags/SwiftypeMetaTagPublishedAtTest.php rename to tests/MetaTags/SwiftypeMetaTagPublishedAtTest.php index 1443003..8a13d1a 100644 --- a/tests/php/MetaTags/SwiftypeMetaTagPublishedAtTest.php +++ b/tests/MetaTags/SwiftypeMetaTagPublishedAtTest.php @@ -9,11 +9,6 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\FieldType\DBDatetime; -/** - * Class SwiftypeMetaTagPublishedAtTest - * - * @package Ichaber\SSSwiftype\Tests\MetaTags - */ class SwiftypeMetaTagPublishedAtTest extends SapphireTest { /** @@ -36,8 +31,8 @@ public function setUp(): void */ public function testMetaTagOutput(): void { - Config::inst()->update(SwiftypeSiteTree::class, 'swiftype_meta_tag_classes', [SwiftypeMetaTagPublishedAt::class]); - Config::inst()->update(SwiftypeMetaTagPublishedAt::class, 'date_format', 'YYYY-MM-dd'); + Config::modify()->set(SwiftypeSiteTree::class, 'swiftype_meta_tag_classes', [SwiftypeMetaTagPublishedAt::class]); + Config::modify()->set(SwiftypeMetaTagPublishedAt::class, 'date_format', 'YYYY-MM-dd'); /** @var SwiftypeSiteTree $page */ $page = $this->objFromFixture(SwiftypeSiteTree::class, 'page1'); @@ -48,7 +43,7 @@ public function testMetaTagOutput(): void $mock = str_replace('http://', '', $mock); $mock = str_replace('https://', '', $mock); - // Remove formatting from output output + // Remove formatting from output $output = trim(preg_replace("/\s+/S", '', $page->getSwiftypeMetaTags()->getValue())); $output = str_replace('http://', '', $output); $output = str_replace('https://', '', $output); diff --git a/tests/php/MetaTags/SwiftypeMetaTagRobotsTest.php b/tests/MetaTags/SwiftypeMetaTagRobotsTest.php similarity index 84% rename from tests/php/MetaTags/SwiftypeMetaTagRobotsTest.php rename to tests/MetaTags/SwiftypeMetaTagRobotsTest.php index a15c0db..1ca5fae 100644 --- a/tests/php/MetaTags/SwiftypeMetaTagRobotsTest.php +++ b/tests/MetaTags/SwiftypeMetaTagRobotsTest.php @@ -7,11 +7,6 @@ use SilverStripe\Core\Config\Config; use SilverStripe\Dev\SapphireTest; -/** - * Class SwiftypeMetaTagRobotsTest - * - * @package Ichaber\SSSwiftype\Tests\MetaTags - */ class SwiftypeMetaTagRobotsTest extends SapphireTest { /** @@ -21,7 +16,7 @@ class SwiftypeMetaTagRobotsTest extends SapphireTest public function testRobotsTagNoIndex(): void { - Config::inst()->update( + Config::modify()->set( SwiftypeSiteTree::class, 'swiftype_meta_tag_classes', [ @@ -29,13 +24,13 @@ public function testRobotsTagNoIndex(): void ] ); - Config::inst()->update( + Config::modify()->set( SwiftypeMetaTagRobots::class, 'no_index', true ); - Config::inst()->update( + Config::modify()->set( SwiftypeMetaTagRobots::class, 'no_follow', false @@ -48,7 +43,7 @@ public function testRobotsTagNoIndex(): void $mock = ''; $mock = trim(preg_replace("/\s+/S", '', $mock)); - // Remove formatting from output output + // Remove formatting from output $output = trim(preg_replace("/\s+/S", '', $page->getSwiftypeMetaTags()->getValue())); $this->assertEquals($mock, $output); @@ -56,7 +51,7 @@ public function testRobotsTagNoIndex(): void public function testRobotsTagNoFollow(): void { - Config::inst()->update( + Config::modify()->set( SwiftypeSiteTree::class, 'swiftype_meta_tag_classes', [ @@ -64,13 +59,13 @@ public function testRobotsTagNoFollow(): void ] ); - Config::inst()->update( + Config::modify()->set( SwiftypeMetaTagRobots::class, 'no_index', false ); - Config::inst()->update( + Config::modify()->set( SwiftypeMetaTagRobots::class, 'no_follow', true @@ -83,7 +78,7 @@ public function testRobotsTagNoFollow(): void $mock = ''; $mock = trim(preg_replace("/\s+/S", '', $mock)); - // Remove formatting from output output + // Remove formatting from output $output = trim(preg_replace("/\s+/S", '', $page->getSwiftypeMetaTags()->getValue())); $this->assertEquals($mock, $output); @@ -91,7 +86,7 @@ public function testRobotsTagNoFollow(): void public function testRobotsTagBoth(): void { - Config::inst()->update( + Config::modify()->set( SwiftypeSiteTree::class, 'swiftype_meta_tag_classes', [ @@ -99,13 +94,13 @@ public function testRobotsTagBoth(): void ] ); - Config::inst()->update( + Config::modify()->set( SwiftypeMetaTagRobots::class, 'no_index', true ); - Config::inst()->update( + Config::modify()->set( SwiftypeMetaTagRobots::class, 'no_follow', true @@ -118,7 +113,7 @@ public function testRobotsTagBoth(): void $mock = ''; $mock = trim(preg_replace("/\s+/S", '', $mock)); - // Remove formatting from output output + // Remove formatting from output $output = trim(preg_replace("/\s+/S", '', $page->getSwiftypeMetaTags()->getValue())); $this->assertEquals($mock, $output); @@ -126,7 +121,7 @@ public function testRobotsTagBoth(): void public function testRobotsTagNone(): void { - Config::inst()->update( + Config::modify()->set( SwiftypeSiteTree::class, 'swiftype_meta_tag_classes', [ @@ -134,13 +129,13 @@ public function testRobotsTagNone(): void ] ); - Config::inst()->update( + Config::modify()->set( SwiftypeMetaTagRobots::class, 'no_index', false ); - Config::inst()->update( + Config::modify()->set( SwiftypeMetaTagRobots::class, 'no_follow', false @@ -149,7 +144,7 @@ public function testRobotsTagNone(): void /** @var SwiftypeSiteTree $page */ $page = $this->objFromFixture(SwiftypeSiteTree::class, 'page2'); - // Remove formatting from output output + // Remove formatting from output $output = trim(preg_replace("/\s+/S", '', $page->getSwiftypeMetaTags()->getValue())); $this->assertEquals('', $output); diff --git a/tests/php/MetaTags/SwiftypeMetaTagTest.yml b/tests/MetaTags/SwiftypeMetaTagTest.yml similarity index 100% rename from tests/php/MetaTags/SwiftypeMetaTagTest.yml rename to tests/MetaTags/SwiftypeMetaTagTest.yml diff --git a/tests/php/MetaTags/SwiftypeMetaTagURLTest.php b/tests/MetaTags/SwiftypeMetaTagURLTest.php similarity index 81% rename from tests/php/MetaTags/SwiftypeMetaTagURLTest.php rename to tests/MetaTags/SwiftypeMetaTagURLTest.php index ec5acb8..9ca6f32 100644 --- a/tests/php/MetaTags/SwiftypeMetaTagURLTest.php +++ b/tests/MetaTags/SwiftypeMetaTagURLTest.php @@ -9,11 +9,6 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\FieldType\DBDatetime; -/** - * Class SwiftypeMetaTagURLTest - * - * @package Ichaber\SSSwiftype\Tests\MetaTags - */ class SwiftypeMetaTagURLTest extends SapphireTest { /** @@ -36,9 +31,15 @@ public function setUp(): void */ public function testMetaTagOutput(): void { - Config::inst()->update(SwiftypeSiteTree::class, 'swiftype_meta_tag_classes', [SwiftypeMetaTagURL::class]); + Config::modify()->set( + SwiftypeSiteTree::class, + 'swiftype_meta_tag_classes', + [ + SwiftypeMetaTagURL::class, + ] + ); // Let's just change this field name to something completely different - Config::inst()->update(SwiftypeMetaTagURL::class, 'field_name', 'Title'); + Config::modify()->set(SwiftypeMetaTagURL::class, 'field_name', 'Title'); /** @var SwiftypeSiteTree $page */ $page = $this->objFromFixture(SwiftypeSiteTree::class, 'page1'); @@ -49,7 +50,7 @@ public function testMetaTagOutput(): void $mock = str_replace('http://', '', $mock); $mock = str_replace('https://', '', $mock); - // Remove formatting from output output + // Remove formatting from output $output = trim(preg_replace("/\s+/S", '', $page->getSwiftypeMetaTags()->getValue())); $output = str_replace('http://', '', $output); $output = str_replace('https://', '', $output); diff --git a/tests/php/Mock/PublishedAtTagOutput.html b/tests/Mock/PublishedAtTagOutput.html similarity index 100% rename from tests/php/Mock/PublishedAtTagOutput.html rename to tests/Mock/PublishedAtTagOutput.html diff --git a/tests/php/Mock/TagsOutput.html b/tests/Mock/TagsOutput.html similarity index 97% rename from tests/php/Mock/TagsOutput.html rename to tests/Mock/TagsOutput.html index 1a51eda..6b349cd 100644 --- a/tests/php/Mock/TagsOutput.html +++ b/tests/Mock/TagsOutput.html @@ -1,4 +1,4 @@ - + diff --git a/tests/php/Mock/URLTagOutput.html b/tests/Mock/URLTagOutput.html similarity index 100% rename from tests/php/Mock/URLTagOutput.html rename to tests/Mock/URLTagOutput.html diff --git a/tests/php/Service/SwiftypeCrawlerTest.php b/tests/Service/SwiftypeCrawlerTest.php similarity index 97% rename from tests/php/Service/SwiftypeCrawlerTest.php rename to tests/Service/SwiftypeCrawlerTest.php index dd26b4c..084719e 100644 --- a/tests/php/Service/SwiftypeCrawlerTest.php +++ b/tests/Service/SwiftypeCrawlerTest.php @@ -13,11 +13,6 @@ use GuzzleHttp\Psr7\Response; use SilverStripe\SiteConfig\SiteConfig; -/** - * Class SwiftypeCrawlerTest - * - * @package Ichaber\SSSwiftype\Tests\Service - */ class SwiftypeCrawlerTest extends SapphireTest { /** diff --git a/tests/php/Service/SwiftypeCrawlerTest.yml b/tests/Service/SwiftypeCrawlerTest.yml similarity index 100% rename from tests/php/Service/SwiftypeCrawlerTest.yml rename to tests/Service/SwiftypeCrawlerTest.yml diff --git a/tests/php/Service/SwiftypeCredentialsTest.php b/tests/Service/SwiftypeCredentialsTest.php similarity index 97% rename from tests/php/Service/SwiftypeCredentialsTest.php rename to tests/Service/SwiftypeCredentialsTest.php index 7015987..dd975f4 100644 --- a/tests/php/Service/SwiftypeCredentialsTest.php +++ b/tests/Service/SwiftypeCredentialsTest.php @@ -8,11 +8,6 @@ use SilverStripe\ORM\ValidationException; use SilverStripe\SiteConfig\SiteConfig; -/** - * Class SwiftypeCredentialsTest - * - * @package Ichaber\SSSwiftype\Tests\Service - */ class SwiftypeCredentialsTest extends SapphireTest { /**