Skip to content

Commit

Permalink
DEP PHP Support in CMS5
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabina Talipova committed Dec 20, 2022
1 parent 08e663d commit 9d81439
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"silverstripe/framework": "^4.10",
"silverstripe/reports": "^4.4",
"symbiote/silverstripe-queuedjobs": "^4.1",
"guzzlehttp/guzzle": "^6.3 || ^7.0"
"php": "^8.1",
"silverstripe/framework": "^5",
"silverstripe/reports": "^5",
"symbiote/silverstripe-queuedjobs": "^5"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3",
"symfony/thanks": "^1.0"
"symfony/thanks": "^1.2"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 3 additions & 1 deletion src/Util/ApiLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function getClientOptions()
*/
protected function getFromCache()
{
$cacheKey = $this->getCacheKey();
$cacheKey = $this->getCacheKey() ?? '';
$result = $this->getCache()->get($cacheKey, false);
if ($result === false) {
return false;
Expand All @@ -155,6 +155,8 @@ protected function getFromCache()
*/
protected function setToCache($cacheKey, $value, $ttl = null)
{
$cacheKey = $cacheKey ?? '';

// Seralize as JSON to ensure array etc can be stored
$value = json_encode($value);

Expand Down
24 changes: 14 additions & 10 deletions tests/Util/ApiLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use SilverStripe\Dev\SapphireTest;
use Symfony\Component\Cache\Simple\NullCache;
use Psr\SimpleCache\CacheInterface;

class ApiLoaderTest extends SapphireTest
{
Expand Down Expand Up @@ -88,9 +88,7 @@ public function testCacheControlSettingsAreRespected()
{
$fakeAddons = ['foo/bar', 'bin/baz'];

$cacheMock = $this->getMockBuilder(NullCache::class)
->setMethods(['get', 'set'])
->getMock();
$cacheMock = $this->getMockCacheInterface();

$cacheMock->expects($this->once())->method('get')->will($this->returnValue(false));
$cacheMock->expects($this->once())
Expand All @@ -114,9 +112,7 @@ public function testCachedAddonsAreUsedWhenAvailable()
{
$fakeAddons = ['foo/bar', 'bin/baz'];

$cacheMock = $this->getMockBuilder(NullCache::class)
->setMethods(['get', 'set'])
->getMock();
$cacheMock = $this->getMockCacheInterface();

$cacheMock->expects($this->once())->method('get')->will($this->returnValue(json_encode($fakeAddons)));
$loader = $this->getLoader($cacheMock);
Expand Down Expand Up @@ -153,9 +149,7 @@ protected function getMockClient(Response $withResponse)
protected function getLoader($cacheMock = false)
{
if (!$cacheMock) {
$cacheMock = $this->getMockBuilder(NullCache::class)
->setMethods(['get', 'set'])
->getMock();
$cacheMock = $this->getMockCacheInterface();

$cacheMock->expects($this->any())->method('get')->will($this->returnValue(false));
$cacheMock->expects($this->any())->method('set')->will($this->returnValue(true));
Expand All @@ -168,4 +162,14 @@ protected function getLoader($cacheMock = false)

return $loader;
}

protected function getMockCacheInterface()
{
$methods = ['get', 'set', 'has', 'delete', 'getMultiple', 'setMultiple', 'clear', 'deleteMultiple'];
$mock = $this->getMockBuilder(CacheInterface::class)
->setMethods($methods)
->getMock();

return $mock;
}
}

0 comments on commit 9d81439

Please sign in to comment.