Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/Illuminate/Cache/Console/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Console\Command;
use Illuminate\Cache\CacheManager;
use Symfony\Component\Console\Input\InputArgument;

class ClearCommand extends Command {

Expand Down Expand Up @@ -46,13 +47,27 @@ public function __construct(CacheManager $cache)
*/
public function fire()
{
$this->laravel['events']->fire('cache:clearing');
$storeName = $this->argument('store');

$this->cache->flush();
$this->laravel['events']->fire('cache:clearing', [$storeName]);

$this->laravel['events']->fire('cache:cleared');
$this->cache->store($storeName)->flush();

$this->laravel['events']->fire('cache:cleared', [$storeName]);

$this->info('Application cache cleared!');
}

/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return [
['store', InputArgument::OPTIONAL, 'The name of the store you would like to clear.'],
];
}

}
84 changes: 84 additions & 0 deletions tests/Cache/ClearCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

use Mockery as m;
use Illuminate\Foundation\Application;
use Illuminate\Cache\Console\ClearCommand;

class ClearCommandTest extends PHPUnit_Framework_TestCase {

public function tearDown()
{
m::close();
}


public function testClearWithNoStoreOption()
{
$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('flush')->once();

$this->runCommand($command);
}


public function testClearWithStoreOption()
{
$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('foo')->andReturn($cacheRepository);
$cacheRepository->shouldReceive('flush')->once();

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


public function testClearWithInvalidStoreOption()
{
$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('bar')->andThrow('\InvalidArgumentException');
$cacheRepository->shouldReceive('flush')->never();
$this->setExpectedException('InvalidArgumentException');

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


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

}

class ClearCommandTestStub extends ClearCommand {

public function call($command, array $arguments = array())
{
//
}

}