testing - Laravel Test That Job Is Released -


i want test job has been released onto queue in circumstances.

this job class:

class chargeorder extends job {     use interactswithqueue, serializesmodels;      /**      * order model charged      */     protected $order;      /**      * token or card_id allows take payment      */     protected $source;      /**      * create new job instance.      *      * @param   app\order       $order;      * @param   string          $source;      * @return  array      */     public function __construct($order, $source)     {         $this->order        = $order;         $this->source       = $source;     }      /**      * execute job.      *      * @return void      */     public function handle(charge $charge)     {         $result             = $charge->execute($this->source, $this->order->totalinclvat());         $exception_errors   = config('payment.errors.exception_errors');          //  if have error isn't caused user (anything card error)         //  we're going notify ourselves via slack can investigate.         if (array_key_exists('error', $result) && in_array($result['error']['code'], array_keys(config('payment.errors.other_error'))))         {             $client         = new client(config('services.slack.channels.payment_errors.url'), config('services.slack.channels.payment_errors.settings'));             $client->send(app()->environment() . ": " . $result['error']['code']);         }          //  if error in list of errors throw exception, throw it.         if (array_key_exists('error', $result) && (in_array($result['error']['type'], $exception_errors) || in_array($result['error']['code'], $exception_errors)))         {             $status_code    = config('payment.errors')[$result['error']['type']][$result['error']['code']]['status_code'];             $message        = config('payment.errors')[$result['error']['type']][$result['error']['code']]['message'];              throw new billingerrorexception($status_code, $message);         }          //  if still have error, out of user's control.         //  network error, or error payment system         //  therefore, we're going throw job onto queue can processed later.         if (array_key_exists('error', $result) && in_array($result['error']['code'], array_keys(config('payment.errors.other_error'))))         {             $this->release(60);         }     } } 

i need test "$this->release(60)" called in circumstances.

i'm trying mock job contract so, in tests:

// set $this->job  = mockery::mock('illuminate\contracts\queue\job'); $this->app->instance('illuminate\contracts\queue\job', $this->job); 

and then

// during test $this->job->shouldreceive('release')->once(); 

but isn't working.

anybody have ideas?

try adding following in test before dispatching job:

queue::after(function (jobprocessed $event) {     $this->asserttrue($event->job->isreleased()); }); 

the code above triggered after job done , checks job has been released.

make sure remove calls queue::fake()and $this->expectsjob() since these prevent actual job being executed.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -