worker = new MockKeyCheckWorker(); } function testItCanInitializeBridgeAPI() { $this->worker->init(); expect($this->worker->bridge instanceof Bridge)->true(); } function testItReturnsTrueOnSuccessfulKeyCheck() { $task = $this->createRunningTask(); $result = $this->worker->processTaskStrategy($task); expect($result)->true(); } function testItReschedulesCheckOnException() { $worker = Stub::make( $this->worker, [ 'checkKey' => function () { throw new \Exception; }, 'reschedule' => Expected::once(), ], $this ); $task = $this->createRunningTask(); $result = $worker->processTaskStrategy($task); expect($result)->false(); } function testItReschedulesCheckOnError() { $worker = Stub::make( $this->worker, [ 'checkKey' => ['code' => Bridge::CHECK_ERROR_UNAVAILABLE], 'reschedule' => Expected::once(), ], $this ); $task = $this->createRunningTask(); $result = $worker->processTaskStrategy($task); expect($result)->false(); } private function createRunningTask() { $task = ScheduledTask::create(); $task->type = MockKeyCheckWorker::TASK_TYPE; $task->status = null; $task->scheduled_at = Carbon::createFromTimestamp(current_time('timestamp')); $task->save(); return $task; } function _after() { \ORM::raw_execute('TRUNCATE ' . Setting::$_table); \ORM::raw_execute('TRUNCATE ' . ScheduledTask::$_table); } }