Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KennedyTedesco committed Jun 9, 2016
1 parent bb0f780 commit c804ba4
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions tests/Cache/ClearCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function tearDown()
m::close();
}

public function testClearWithNoStoreOption()
public function testClearWithNoStoreArgument()
{
$command = new ClearCommandTestStub(
$cacheManager = m::mock('Illuminate\Cache\CacheManager')
Expand All @@ -28,7 +28,7 @@ public function testClearWithNoStoreOption()
$this->runCommand($command);
}

public function testClearWithStoreOption()
public function testClearWithStoreArgument()
{
$command = new ClearCommandTestStub(
$cacheManager = m::mock('Illuminate\Cache\CacheManager')
Expand All @@ -48,7 +48,7 @@ public function testClearWithStoreOption()
/**
* @expectedException InvalidArgumentException
*/
public function testClearWithInvalidStoreOption()
public function testClearWithInvalidStoreArgument()
{
$command = new ClearCommandTestStub(
$cacheManager = m::mock('Illuminate\Cache\CacheManager')
Expand All @@ -65,6 +65,42 @@ public function testClearWithInvalidStoreOption()
$this->runCommand($command, ['store' => 'bar']);
}

public function testClearWithTagsOption()
{
$command = new ClearCommandTestStub(
$cacheManager = m::mock('Illuminate\Cache\CacheManager')
);

$cacheRepository = m::mock('Illuminate\Contracts\Cache\Repository');

$app = new Application();
$command->setLaravel($app);

$cacheManager->shouldReceive('store')->once()->with(null)->andReturn($cacheRepository);
$cacheRepository->shouldReceive('tags')->once()->with(['foo', 'bar'])->andReturn($cacheRepository);
$cacheRepository->shouldReceive('flush')->once();

$this->runCommand($command, ['--tags' => 'foo,bar']);
}

public function testClearWithStoreArgumentAndTagsOption()
{
$command = new ClearCommandTestStub(
$cacheManager = m::mock('Illuminate\Cache\CacheManager')
);

$cacheRepository = m::mock('Illuminate\Contracts\Cache\Repository');

$app = new Application();
$command->setLaravel($app);

$cacheManager->shouldReceive('store')->once()->with('redis')->andReturn($cacheRepository);
$cacheRepository->shouldReceive('tags')->once()->with(['foo'])->andReturn($cacheRepository);
$cacheRepository->shouldReceive('flush')->once();

$this->runCommand($command, ['store' => 'redis', '--tags' => 'foo']);
}

protected function runCommand($command, $input = [])
{
return $command->run(new Symfony\Component\Console\Input\ArrayInput($input), new Symfony\Component\Console\Output\NullOutput);
Expand Down

0 comments on commit c804ba4

Please sign in to comment.