Skip to content

Commit

Permalink
Merge pull request #10 from Indatus/develop
Browse files Browse the repository at this point in the history
PHP 5.3 support
  • Loading branch information
bkuhl committed Mar 22, 2014
2 parents 89c384d + 15e7097 commit c21f1bb
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 50 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: php

php:
- 5.3
- 5.4
- 5.5

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": ">=5.4.0",
"php": ">=5.3.2",
"jlogsdon/cli": "v0.9.4",
"mtdowling/cron-expression" : "1.0.*"
},
Expand Down
4 changes: 2 additions & 2 deletions src/Indatus/Dispatcher/Commands/Make.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ protected function writeCommand($file, $stub) {
*/
protected function extendStub($stub)
{
$replacements = [
$replacements = array(
'use Illuminate\Console\Command' => "use Indatus\\Dispatcher\\ScheduledCommand;\n".
"use Indatus\\Dispatcher\\Scheduler",
'extends Command {' => 'extends ScheduledCommand {',
'parent::__construct();' => $this->getStub()
];
);

$stub = str_replace(array_keys($replacements), array_values($replacements), $stub);

Expand Down
4 changes: 2 additions & 2 deletions src/Indatus/Dispatcher/Drivers/Cron/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ class Scheduler implements Schedulable
*/
public function getSchedule()
{
return implode(' ', [
return implode(' ', array(
$this->getScheduleMinute(),
$this->getScheduleHour(),
$this->getScheduleDayOfMonth(),
$this->getScheduleMonth(),
$this->getScheduleDayOfWeek()
]);
));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Indatus/Dispatcher/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public function register()
*/
public function provides()
{
return [
return array(
'command.scheduled.summary',
'command.scheduled.make',
'command.scheduled.run'
];
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Indatus/Dispatcher/Services/CommandService.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ public function runnableInEnvironment(ScheduledCommand $command)
*/
public function getRunCommand(ScheduledCommand $scheduledCommand)
{
$commandPieces = [
$commandPieces = array(
'php',
base_path().'/artisan',
$scheduledCommand->getName(),
'&', //run in background
'> /dev/null 2>&1' //don't show output, errors can be viewed in the Laravel log
];
);

//run the command as a different user
if (is_string($scheduledCommand->user())) {
Expand Down
10 changes: 5 additions & 5 deletions src/Indatus/Dispatcher/Services/ScheduleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract public function isDue(ScheduledCommand $command);
*/
public function getScheduledCommands()
{
$scheduledCommands = [];
$scheduledCommands = array();
foreach (Artisan::all() as $command) {
if ($command instanceOf ScheduledCommand) {
$scheduledCommands[] = $command;
Expand All @@ -57,7 +57,7 @@ public function getScheduledCommands()
*/
public function getDueCommands()
{
$commands = [];
$commands = array();
foreach ($this->getScheduledCommands() as $command) {
if ($this->isDue($command)) {
$commands[] = $command;
Expand All @@ -73,15 +73,15 @@ public function getDueCommands()
*/
public function printSummary()
{
$this->table->setHeaders(['Environment(s)', 'Name', 'Minute', 'Hour', 'Day of Month', 'Month', 'Day of Week', 'Run as']);
$this->table->setHeaders(array('Environment(s)', 'Name', 'Minute', 'Hour', 'Day of Month', 'Month', 'Day of Week', 'Run as'));
/** @var $command \Indatus\Dispatcher\ScheduledCommand */
$commands = 0;
$activeCommands = 0;
foreach ($this->getScheduledCommands() as $command) {
/** @var $command \Indatus\Dispatcher\ScheduledCommand */
$scheduler = $command->schedule(App::make('Indatus\Dispatcher\Schedulable'));

$this->table->addRow([
$this->table->addRow(array(
is_array($command->environment()) ? implode(',', $command->environment()) : $command->environment(),
$command->getName(),
$scheduler->getScheduleMinute(),
Expand All @@ -90,7 +90,7 @@ public function printSummary()
$scheduler->getScheduleMonth(),
$scheduler->getScheduleDayOfWeek(),
$command->user()
]);
));
$commands++;
$activeCommands++;
}
Expand Down
4 changes: 2 additions & 2 deletions src/config/config.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php return [
<?php return array(
/**
* The schedule driver to use:
*
Expand All @@ -10,4 +10,4 @@
*
*/
'driver' => 'cron'
];
);
8 changes: 4 additions & 4 deletions tests/Commands/TestMake.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public function testExtendStub()

$stubContents = file_get_contents($this->getStubPath('command.stub'));

$replacements = [
$replacements = array(
'use Illuminate\Console\Command' => "use Indatus\\Dispatcher\\ScheduledCommand;\n".
"use Indatus\\Dispatcher\\Scheduler",
'extends Command {' => 'extends ScheduledCommand {',
'parent::__construct();' => $stubContents
];
);

$delimeter = '*****';
$extendedStub = $method->invoke($this->makeFactory(), implode($delimeter, array_keys($replacements)));
Expand All @@ -77,12 +77,12 @@ public function testExtendStub()

private function getStubPath($filename)
{
return implode(DIRECTORY_SEPARATOR, [
return implode(DIRECTORY_SEPARATOR, array(
$this->getPackagePath(),
'Commands',
'stubs',
$filename
]);
));
}

private function makeFactory()
Expand Down
8 changes: 4 additions & 4 deletions tests/Drivers/Cron/TestScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testMinutes()
$this->assertEquals($this->scheduler->getSchedule(), $minutes.' '.Scheduler::ANY.' '.Scheduler::ANY.' '.Scheduler::ANY.' '.Scheduler::ANY);

//test that we can specify arrays of times
$this->scheduler->minutes([$minutes, $minutes+1]);
$this->scheduler->minutes(array($minutes, $minutes+1));
$this->assertEquals($this->scheduler->getSchedule(), $minutes.','.($minutes+1).' '.Scheduler::ANY.' '.Scheduler::ANY.' '.Scheduler::ANY.' '.Scheduler::ANY);
}

Expand All @@ -97,7 +97,7 @@ public function testHours()
$this->assertEquals($this->scheduler->getSchedule(), Scheduler::ANY.' '.$hours.' '.Scheduler::ANY.' '.Scheduler::ANY.' '.Scheduler::ANY);

//test that we can specify arrays of times
$this->scheduler->hours([$hours, $hours+1]);
$this->scheduler->hours(array($hours, $hours+1));
$this->assertEquals($this->scheduler->getSchedule(), Scheduler::ANY.' '.$hours.','.($hours+1).' '.Scheduler::ANY.' '.Scheduler::ANY.' '.Scheduler::ANY);
}

Expand All @@ -116,7 +116,7 @@ public function testDaysOfTheMonth()
$this->assertEquals($this->scheduler->getSchedule(), Scheduler::ANY.' '.Scheduler::ANY.' '.$daysOfTheMonth.' '.Scheduler::ANY.' '.Scheduler::ANY);

//test that we can specify arrays of times
$this->scheduler->daysOfTheMonth([$daysOfTheMonth, $daysOfTheMonth+1]);
$this->scheduler->daysOfTheMonth(array($daysOfTheMonth, $daysOfTheMonth+1));
$this->assertEquals($this->scheduler->getSchedule(), Scheduler::ANY.' '.Scheduler::ANY.' '.$daysOfTheMonth.','.($daysOfTheMonth+1).' '.Scheduler::ANY.' '.Scheduler::ANY);
}

Expand All @@ -127,7 +127,7 @@ public function testMonths()
$this->assertEquals($this->scheduler->getSchedule(), Scheduler::ANY.' '.Scheduler::ANY.' '.Scheduler::ANY.' '.$months.' '.Scheduler::ANY);

//test that we can specify arrays of times
$this->scheduler->months([$months, $months+1]);
$this->scheduler->months(array($months, $months+1));
$this->assertEquals($this->scheduler->getSchedule(), Scheduler::ANY.' '.Scheduler::ANY.' '.Scheduler::ANY.' '.$months.','.($months+1).' '.Scheduler::ANY);
}

Expand Down
14 changes: 7 additions & 7 deletions tests/Services/TestBackgroundProcessService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public function testRunDue()
$scheduledCommand->shouldReceive('user')->once()->andReturn(false);

$scheduleService = m::mock('Indatus\Dispatcher\Drivers\Cron\ScheduleService');
$scheduleService->shouldReceive('getDueCommands')->once()->andReturn([$scheduledCommand]);
$scheduleService->shouldReceive('getDueCommands')->once()->andReturn(array($scheduledCommand));
$this->app->instance('Indatus\Dispatcher\Services\ScheduleService', $scheduleService);

$commandService = m::mock('Indatus\Dispatcher\Services\CommandService[runnableInEnvironment,run]',
[$scheduleService],
array($scheduleService),
function ($m) {
$m->shouldReceive('runnableInEnvironment')->andReturn(true);
$m->shouldReceive('run')->andReturnNull();
Expand All @@ -70,7 +70,7 @@ public function testRunnableInOneEnvironment()

public function testRunnableInMultipleEnvironments()
{
$scheduledCommand = $this->mockCommand(['local', 'development']);
$scheduledCommand = $this->mockCommand(array('local', 'development'));

App::shouldReceive('environment')->andReturn('local');
$this->assertTrue($this->commandService->runnableInEnvironment($scheduledCommand));
Expand All @@ -82,13 +82,13 @@ public function testGetRunCommand()
$scheduledCommand = $this->mockCommand();
$scheduledCommand->shouldReceive('getName')->andReturn($commandName);
$scheduledCommand->shouldReceive('user')->andReturn(false);
$this->assertEquals($this->commandService->getRunCommand($scheduledCommand), implode(' ', [
$this->assertEquals($this->commandService->getRunCommand($scheduledCommand), implode(' ', array(
'php',
base_path().'/artisan',
$commandName,
'&',
'> /dev/null 2>&1'
]));
)));
}
public function testGetRunCommandAsUser()
{
Expand All @@ -97,14 +97,14 @@ public function testGetRunCommandAsUser()
$scheduledCommand = $this->mockCommand();
$scheduledCommand->shouldReceive('getName')->andReturn($commandName);
$scheduledCommand->shouldReceive('user')->andReturn($user);
$this->assertEquals($this->commandService->getRunCommand($scheduledCommand), implode(' ', [
$this->assertEquals($this->commandService->getRunCommand($scheduledCommand), implode(' ', array(
'sudo -u '.$user,
'php',
base_path().'/artisan',
$commandName,
'&',
'> /dev/null 2>&1'
]));
)));
}

private function mockCommand ($environment = '*')
Expand Down
16 changes: 8 additions & 8 deletions tests/Services/TestCommandService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public function testRunDue()
$scheduledCommand->shouldReceive('user')->once()->andReturn(false);

$scheduleService = m::mock('Indatus\Dispatcher\Drivers\Cron\ScheduleService');
$scheduleService->shouldReceive('getDueCommands')->once()->andReturn([$scheduledCommand]);
$scheduleService->shouldReceive('getDueCommands')->once()->andReturn(array($scheduledCommand));
$this->app->instance('Indatus\Dispatcher\Services\ScheduleService', $scheduleService);

$commandService = m::mock('Indatus\Dispatcher\Services\CommandService[runnableInEnvironment,run]',
[$scheduleService],
array($scheduleService),
function ($m) {
$m->shouldReceive('runnableInEnvironment')->andReturn(true);
$m->shouldReceive('run')->andReturnNull();
Expand All @@ -70,15 +70,15 @@ public function testRunnableInOneEnvironment()

public function testRunnableInMultipleEnvironments()
{
$scheduledCommand = $this->mockCommand(['local', 'development']);
$scheduledCommand = $this->mockCommand(array('local', 'development'));

App::shouldReceive('environment')->andReturn('local');
$this->assertTrue($this->commandService->runnableInEnvironment($scheduledCommand));
}

public function testNotRunnableInEnvironment()
{
$scheduledCommand = $this->mockCommand(['local', 'development']);
$scheduledCommand = $this->mockCommand(array('local', 'development'));

App::shouldReceive('environment')->andReturn('amazonAWS');
$this->assertFalse($this->commandService->runnableInEnvironment($scheduledCommand));
Expand All @@ -90,13 +90,13 @@ public function testGetRunCommand()
$scheduledCommand = $this->mockCommand();
$scheduledCommand->shouldReceive('getName')->andReturn($commandName);
$scheduledCommand->shouldReceive('user')->andReturn(false);
$this->assertEquals($this->commandService->getRunCommand($scheduledCommand), implode(' ', [
$this->assertEquals($this->commandService->getRunCommand($scheduledCommand), implode(' ', array(
'php',
base_path().'/artisan',
$commandName,
'&',
'> /dev/null 2>&1'
]));
)));
}
public function testGetRunCommandAsUser()
{
Expand All @@ -105,14 +105,14 @@ public function testGetRunCommandAsUser()
$scheduledCommand = $this->mockCommand();
$scheduledCommand->shouldReceive('getName')->andReturn($commandName);
$scheduledCommand->shouldReceive('user')->andReturn($user);
$this->assertEquals($this->commandService->getRunCommand($scheduledCommand), implode(' ', [
$this->assertEquals($this->commandService->getRunCommand($scheduledCommand), implode(' ', array(
'sudo -u '.$user,
'php',
base_path().'/artisan',
$commandName,
'&',
'> /dev/null 2>&1'
]));
)));
}

private function mockCommand ($environment = '*')
Expand Down
18 changes: 9 additions & 9 deletions tests/Services/TestScheduleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public function tearDown()

public function testGetScheduledCommands()
{
$scheduledCommands = [$class = m::mock('Indatus\Dispatcher\ScheduledCommand', function ($m) {
$scheduledCommands = array($class = m::mock('Indatus\Dispatcher\ScheduledCommand', function ($m) {
$m->shouldReceive('schedule')->andReturn(m::mock('Indatus\Dispatcher\Schedulable'));
})];
}));

Artisan::shouldReceive('all')->once()->andReturn($scheduledCommands);

Expand Down Expand Up @@ -64,23 +64,23 @@ public function testPrintSummary()
$m->shouldReceive('getScheduleDayOfWeek');
}));
});
$scheduleService = m::mock('Indatus\Dispatcher\Drivers\Cron\ScheduleService[getScheduledCommands]', [
$scheduleService = m::mock('Indatus\Dispatcher\Drivers\Cron\ScheduleService[getScheduledCommands]', array(
$table
], function ($m) use ($scheduledCommand) {
$m->shouldReceive('getScheduledCommands')->once()->andReturn([
), function ($m) use ($scheduledCommand) {
$m->shouldReceive('getScheduledCommands')->once()->andReturn(array(
$scheduledCommand
]);
));
});
$scheduleService->printSummary();
}

public function testGetDueCommands()
{
$scheduleService = m::mock('Indatus\Dispatcher\Drivers\Cron\ScheduleService[getScheduledCommands,isDue]', [
$scheduleService = m::mock('Indatus\Dispatcher\Drivers\Cron\ScheduleService[getScheduledCommands,isDue]', array(
new Table()
], function ($m) {
), function ($m) {
$m->shouldReceive('getScheduledCommands')->once()
->andReturn([m::mock('Indatus\Dispatcher\ScheduledCommand')]);
->andReturn(array(m::mock('Indatus\Dispatcher\ScheduledCommand')));
$m->shouldReceive('isDue')->once()->andReturn(true);

});
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ protected function getPackageProviders()
*/
protected function getPackagePath()
{
return realpath(implode(DIRECTORY_SEPARATOR, [
return realpath(implode(DIRECTORY_SEPARATOR, array(
__DIR__,
'..',
'src',
'Indatus',
'Dispatcher'
]));
)));
}

}

0 comments on commit c21f1bb

Please sign in to comment.