Skip to content

Commit

Permalink
formatting and fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 31, 2016
1 parent 022dbb3 commit 5973f6c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 42 deletions.
16 changes: 8 additions & 8 deletions src/Illuminate/Console/Scheduling/CallbackEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
class CallbackEvent extends Event
{
/**
* The callback to call.
* The cache store implementation.
*
* @var string
* @var \Illuminate\Contracts\Cache\Repository
*/
protected $callback;
protected $cache;

/**
* The cache store implementation.
* The callback to call.
*
* @var \Illuminate\Contracts\Cache\Repository
* @var string
*/
protected $cache;
protected $callback;

/**
* The parameters to pass to the method.
Expand All @@ -33,14 +33,14 @@ class CallbackEvent extends Event
/**
* Create a new event instance.
*
* @param string $callback
* @param \Illuminate\Contracts\Cache\Repository $cache
* @param string $callback
* @param array $parameters
* @return void
*
* @throws \InvalidArgumentException
*/
public function __construct($callback, Cache $cache, array $parameters = [])
public function __construct(Cache $cache, $callback, array $parameters = [])
{
if (! is_string($callback) && ! is_callable($callback)) {
throw new InvalidArgumentException(
Expand Down
16 changes: 8 additions & 8 deletions src/Illuminate/Console/Scheduling/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
class Event
{
/**
* The command string.
* The cache store implementation.
*
* @var string
* @var \Illuminate\Contracts\Cache\Repository
*/
public $command;
protected $cache;

/**
* The cache store implementation.
* The command string.
*
* @var \Illuminate\Contracts\Cache\Repository
* @var string
*/
protected $cache;
public $command;

/**
* The cron expression representing the event's frequency.
Expand Down Expand Up @@ -130,11 +130,11 @@ class Event
/**
* Create a new event instance.
*
* @param string $command
* @param \Illuminate\Contracts\Cache\Repository $cache
* @param string $command
* @return void
*/
public function __construct($command, Cache $cache)
public function __construct(Cache $cache, $command)
{
$this->cache = $cache;
$this->command = $command;
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Console/Scheduling/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(Cache $cache)
*/
public function call($callback, array $parameters = [])
{
$this->events[] = $event = new CallbackEvent($callback, $this->cache, $parameters);
$this->events[] = $event = new CallbackEvent($this->cache, $callback, $parameters);

return $event;
}
Expand Down Expand Up @@ -81,7 +81,7 @@ public function exec($command, array $parameters = [])
$command .= ' '.$this->compileParameters($parameters);
}

$this->events[] = $event = new Event($command, $this->cache);
$this->events[] = $event = new Event($this->cache, $command);

return $event;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Foundation/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Console\Application as Artisan;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Cache\Repository as Cache;
use Illuminate\Contracts\Console\Kernel as KernelContract;
use Symfony\Component\Debug\Exception\FatalThrowableError;

Expand Down Expand Up @@ -93,7 +94,7 @@ public function __construct(Application $app, Dispatcher $events)
protected function defineConsoleSchedule()
{
$this->app->instance(
'Illuminate\Console\Scheduling\Schedule', $schedule = new Schedule($this->app['cache.store'])
'Illuminate\Console\Scheduling\Schedule', $schedule = new Schedule($this->app[Cache::class])
);

$this->schedule($schedule);
Expand Down
36 changes: 18 additions & 18 deletions tests/Console/ConsoleScheduledEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testBasicCronCompilation()
$app->shouldReceive('isDownForMaintenance')->andReturn(false);
$app->shouldReceive('environment')->andReturn('production');

$event = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$this->assertEquals('* * * * * *', $event->getExpression());
$this->assertTrue($event->isDue($app));
$this->assertTrue($event->skip(function () {
Expand All @@ -42,49 +42,49 @@ public function testBasicCronCompilation()
return true;
})->filtersPass($app));

$event = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$this->assertEquals('* * * * * *', $event->getExpression());
$this->assertFalse($event->environments('local')->isDue($app));

$event = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$this->assertEquals('* * * * * *', $event->getExpression());
$this->assertFalse($event->when(function () {
return false;
})->filtersPass($app));

$event = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$this->assertEquals('*/5 * * * * *', $event->everyFiveMinutes()->getExpression());

$event = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$this->assertEquals('0 0 * * * *', $event->daily()->getExpression());

$event = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$this->assertEquals('0 3,15 * * * *', $event->twiceDaily(3, 15)->getExpression());

$event = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$this->assertEquals('*/5 * * * 3 *', $event->everyFiveMinutes()->wednesdays()->getExpression());

$event = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$this->assertEquals('0 * * * * *', $event->everyFiveMinutes()->hourly()->getExpression());

$event = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$this->assertEquals('0 15 4 * * *', $event->monthlyOn(4, '15:00')->getExpression());

$event = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$this->assertEquals('0 0 * * 1-5 *', $event->weekdays()->daily()->getExpression());

$event = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$this->assertEquals('0 * * * 1-5 *', $event->weekdays()->hourly()->getExpression());

// chained rules should be commutative
$eventA = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$eventB = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$eventA = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$eventB = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$this->assertEquals(
$eventA->daily()->hourly()->getExpression(),
$eventB->hourly()->daily()->getExpression());

$eventA = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$eventB = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$eventA = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$eventB = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$this->assertEquals(
$eventA->weekdays()->hourly()->getExpression(),
$eventB->hourly()->weekdays()->getExpression());
Expand All @@ -97,11 +97,11 @@ public function testEventIsDueCheck()
$app->shouldReceive('environment')->andReturn('production');
Carbon::setTestNow(Carbon::create(2015, 1, 1, 0, 0, 0));

$event = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$this->assertEquals('* * * * 4 *', $event->thursdays()->getExpression());
$this->assertTrue($event->isDue($app));

$event = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$this->assertEquals('0 19 * * 3 *', $event->wednesdays()->at('19:00')->timezone('EST')->getExpression());
$this->assertTrue($event->isDue($app));
}
Expand All @@ -113,7 +113,7 @@ public function testTimeBetweenChecks()
$app->shouldReceive('environment')->andReturn('production');
Carbon::setTestNow(Carbon::now()->startOfDay()->addHours(9));

$event = new Event('php foo', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php foo');
$this->assertTrue($event->between('8:00', '10:00')->filtersPass($app));
$this->assertTrue($event->between('9:00', '9:00')->filtersPass($app));
$this->assertFalse($event->between('10:00', '11:00')->filtersPass($app));
Expand Down
10 changes: 5 additions & 5 deletions tests/Console/Scheduling/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function testBuildCommand()
{
$quote = (DIRECTORY_SEPARATOR == '\\') ? '"' : "'";

$event = new Event('php -i', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php -i');

$defaultOutput = (DIRECTORY_SEPARATOR == '\\') ? 'NUL' : '/dev/null';
$this->assertSame("php -i > {$quote}{$defaultOutput}{$quote} 2>&1 &", $event->buildCommand());
Expand All @@ -24,12 +24,12 @@ public function testBuildCommandSendOutputTo()
{
$quote = (DIRECTORY_SEPARATOR == '\\') ? '"' : "'";

$event = new Event('php -i', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php -i');

$event->sendOutputTo('/dev/null');
$this->assertSame("php -i > {$quote}/dev/null{$quote} 2>&1 &", $event->buildCommand());

$event = new Event('php -i', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php -i');

$event->sendOutputTo('/my folder/foo.log');
$this->assertSame("php -i > {$quote}/my folder/foo.log{$quote} 2>&1 &", $event->buildCommand());
Expand All @@ -39,7 +39,7 @@ public function testBuildCommandAppendOutput()
{
$quote = (DIRECTORY_SEPARATOR == '\\') ? '"' : "'";

$event = new Event('php -i', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php -i');

$event->appendOutputTo('/dev/null');
$this->assertSame("php -i >> {$quote}/dev/null{$quote} 2>&1 &", $event->buildCommand());
Expand All @@ -50,7 +50,7 @@ public function testBuildCommandAppendOutput()
*/
public function testEmailOutputToThrowsExceptionIfOutputFileWasNotSpecified()
{
$event = new Event('php -i', m::mock('Illuminate\Contracts\Cache\Repository'));
$event = new Event(m::mock('Illuminate\Contracts\Cache\Repository'), 'php -i');
$event->emailOutputTo('foo@example.com');

$event->buildCommand();
Expand Down

0 comments on commit 5973f6c

Please sign in to comment.