Example #1
0
 /**
  *  Tests the Cron run events
  *
  *  @covers \Liebig\Cron\Cron::run
  */
 public function testRunEvents()
 {
     $result = array();
     \Event::listen('cron.afterRun', function ($rundate, $inTime, $runtime, $errors, $crons) use(&$result) {
         array_push($result, array($rundate, $inTime, $runtime, $errors, $crons));
     });
     \Event::listen('cron.collectJobs', function () use(&$result) {
         array_push($result, "Collect");
         Cron::add('test1', "* * * * *", function () use(&$result) {
             array_push($result, 'Job');
             return 'No';
         });
         Cron::add('test2', "* * * * *", function () use(&$result) {
             array_push($result, 'Job');
         });
     });
     \Event::listen('cron.beforeRun', function ($runDate) use(&$result) {
         $now = new \DateTime();
         if (empty($runDate) || !is_int($runDate) || $runDate > $now->getTimestamp()) {
             throw new \Exception('$runDate with value ' . $runDate . ' should not be empty, has to be an integer value and has to be lower then the current timestamp');
         }
         array_push($result, 'Before');
     });
     $successArray = array();
     \Event::Listen('cron.jobSuccess', function ($name, $runtime, $rundate) use(&$successArray) {
         array_push($successArray, $name);
     });
     $errorArray = array();
     \Event::Listen('cron.jobError', function ($name, $runtime, $rundate) use(&$errorArray) {
         array_push($errorArray, $name);
     });
     \Artisan::call('cron:run', array());
     $this->assertEquals(1, \Liebig\Cron\Models\Manager::count());
     $this->assertEquals(1, \Liebig\Cron\Models\Job::count());
     $this->assertEquals('Collect', $result[0]);
     $this->assertEquals('Before', $result[1]);
     $this->assertEquals('Job', $result[2]);
     $this->assertEquals('Job', $result[3]);
     // [0]$rundate, [1]$inTime, [2]$runtime, [3]$errors, [4]$crons
     $this->assertEquals(true, is_array($result[4]));
     // Errors
     $this->assertEquals(1, $result[4][3]);
     // Crons
     $this->assertEquals(2, count($result[4][4]));
     // Crons -> first -> name
     $this->assertEquals('test1', $result[4][4][0]['name']);
     // Crons -> first -> return
     $this->assertEquals('No', $result[4][4][0]['return']);
     $this->assertEquals(1, count($successArray));
     $this->assertEquals('test2', $successArray[0]);
     $this->assertEquals(1, count($errorArray));
     $this->assertEquals('test1', $errorArray[0]);
 }
Example #2
0
<?php

Event::Listen('Larabook.Registration.Events.UserRegistered', function ($event) {
    //	dd('Send a notification email');
});
Route::get('/', ['as' => 'home', 'uses' => 'PagesController@home']);
/**
 * Registration!
 */
Route::get('register', ['as' => 'register_path', 'uses' => 'RegistrationController@create']);
Route::post('register', ['as' => 'register_path', 'uses' => 'RegistrationController@store']);
/**
 * Sessions
 */
Route::get('login', ['as' => 'login_path', 'uses' => 'SessionsController@create']);
Route::post('login', ['as' => 'login_path', 'uses' => 'SessionsController@store']);
Route::get('logout', ['as' => 'logout_path', 'uses' => 'SessionsController@destroy']);
/**
 * Statusses
 */
Route::get('statuses', ['as' => 'statuses_path', 'uses' => 'StatusesController@index']);
Route::post('statuses', ['as' => 'statuses_path', 'uses' => 'StatusesController@store']);
/**
 * Users
 */
Route::get('users', ['as' => 'users_path', 'uses' => 'UsersController@index']);
Route::get('@{username}', ['as' => 'profile_path', 'uses' => 'UsersController@show']);