Skip to content

Commit

Permalink
Add unit test, linting
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Apr 13, 2020
1 parent 6ebf06c commit 810f4a6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Services/ReadOnlyCacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
class ReadOnlyCacheService
{

use Injectable;

private $enabled = false;
Expand Down
38 changes: 38 additions & 0 deletions tests/php/Services/ReadOnlyCacheServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use SilverStripe\Assets\Services\ReadOnlyCacheService;
use SilverStripe\Dev\SapphireTest;

class ReadOnlyCacheServiceTest extends SapphireTest
{

public function testGetSetEnabled()
{
$service = ReadOnlyCacheService::singleton();
$this->assertFalse($service->getEnabled());
$service->setEnabled(true);
$this->assertTrue($service->getEnabled());
}

public function testGetSetHasValue()
{
$service = ReadOnlyCacheService::singleton();
$this->assertFalse($service->hasValue(['A', 'B'], ['1', '2']));
$service->setValue(['A', 'B'], ['1', '2'], 'xyz');
$this->assertTrue($service->hasValue(['A', 'B'], ['1', '2']));
$this->assertEquals('xyz', $service->getValue(['A', 'B'], ['1', '2']));
}

public function testReset()
{
$service = ReadOnlyCacheService::singleton();
$service->setValue(['A', 'B'], ['1', '2'], 'xyz');
$service->setValue(['C', 'D'], ['3', '4'], 'wvu');
$this->assertTrue($service->hasValue(['A', 'B'], ['1', '2']));
$service->reset(['A', 'B']);
$this->assertFalse($service->hasValue(['A', 'B'], ['1', '2']));
$this->assertTrue($service->hasValue(['C', 'D'], ['3', '4']));
$service->reset();
$this->assertFalse($service->hasValue(['C', 'D'], ['3', '4']));
}
}

0 comments on commit 810f4a6

Please sign in to comment.