Skip to content

Commit

Permalink
Improved test coverage for cache system verbose output tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aik099 committed Jul 24, 2024
1 parent 64710d2 commit 7708632
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions tests/SVNBuddy/Cache/CacheManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function testSetWithoutDuration()
/**
* @medium
*/
public function testSetWithDuration()
public function testSetWithExpiration()
{
$this->cacheManager->setCache('namespace:name_int', 'value_int', null, 1);
$this->assertEquals('value_int', $this->cacheManager->getCache('namespace:name_int', null, 1));
Expand Down Expand Up @@ -138,25 +138,33 @@ public function testVerboseCacheMiss()
$io = $this->prophesize('ConsoleHelpers\ConsoleKit\ConsoleIO');
$io->isVerbose()->willReturn(true)->shouldBeCalled();

// For the 1st "getCache" call.
$this->expectVerboseOutput($io, '#^<debug>\[cache\]: .*/\.svn-buddy/namespace_.*\.cache \(miss \#1\)</debug>$#');

$cache_manager = new CacheManager($this->getWorkingDirectory(), $this->sizeHelper->reveal(), $io->reveal());
$this->assertNull($cache_manager->getCache('namespace:name'));

// For the 2nd "getCache" call.
$this->expectVerboseOutput($io, '#^<debug>\[cache\]: .*/\.svn-buddy/namespace_.*\.cache \(miss \#2\)</debug>$#');
$this->assertNull($cache_manager->getCache('namespace:name'));
// First miss on persistent cache.
$this->expectVerboseOutput($io, '#^<debug>\[cache\]: .*/\.svn-buddy/namespace_.*\.cache \(miss:absent \#1\)</debug>$#');
$this->assertNull($cache_manager->getCache('namespace:name1'), 'First miss on persistent cache.');

// Second miss on persistent cache.
$this->expectVerboseOutput($io, '#^<debug>\[cache\]: .*/\.svn-buddy/namespace_.*\.cache \(miss:absent \#2\)</debug>$#');
$this->assertNull($cache_manager->getCache('namespace:name1'), 'Second miss on persistent cache.');

// Miss on expired cache.
$cache_manager->setCache('namespace:name2', 'value1', null, 1);
sleep(2);
$this->expectVerboseOutput($io, '#^<debug>\[cache\]: .*/\.svn-buddy/namespace_.*\.cache \(miss:expired \#1\)</debug>$#');
$this->assertNull($cache_manager->getCache('namespace:name2', null, 1), 'Miss on expired cache.');

// Miss on invalidated cache.
$cache_manager->setCache('namespace:name3', 'value1', 'invalidator1');
$this->expectVerboseOutput($io, '#^<debug>\[cache\]: .*/\.svn-buddy/namespace_.*\.cache \(miss:invalidated \#1\)</debug>$#');
$this->assertNull($cache_manager->getCache('namespace:name3', 'invalidator2'), 'Miss on invalidated cache.');
}

public function testVerboseCacheHit()
{
$io = $this->prophesize('ConsoleHelpers\ConsoleKit\ConsoleIO');
$io->isVerbose()->willReturn(true)->shouldBeCalled();

// For "setCache" call.
$this->expectVerboseOutput($io, '#^<debug>\[cache\]: .*/\.svn-buddy/namespace_.*\.cache \(miss \#1\)</debug>$#');

// For the 1st "getCache" call.
$this->expectVerboseOutput($io, '#^<debug>\[cache\]: .*/\.svn-buddy/namespace_.*\.cache \(hit \#1: .*\)</debug>$#');

Expand Down

0 comments on commit 7708632

Please sign in to comment.