public function testPushWithDefault()
 {
     $imp = new Impersonator();
     $job = 'Omg\\Doge\\LaunchCommand';
     $data = ['omg' => 'whyyoudothis.jpg'];
     $queue = m::mock(QueueManager::class);
     $queue->shouldReceive('push')->with($job, $data, 'no no i stay')->once();
     $imp->provide($queue);
     $pusher = $imp->make(QueuePusher::class);
     $pusher->push($job, $data, null, 'no no i stay');
 }
 public function testGetResolvedMap()
 {
     $imp = new Impersonator();
     $imp->mock(Batch::class, function (MockInterface $mock) {
         $mock->shouldReceive('getMigrations')->once()->andReturn(['omgdoge', 'goobypls']);
         $mock->shouldReceive('resolve')->with('omgdoge')->once()->andReturn('wowwow');
         $mock->shouldReceive('resolve')->with('goobypls')->once()->andReturn('dolanpls');
     });
     /** @var StructuredStatus $status */
     $status = $imp->make(StructuredStatus::class);
     $result = $status->getResolvedMap();
     $this->assertEquals(['omgdoge' => 'wowwow', 'goobypls' => 'dolanpls'], $result);
 }
 public function testFireWithCustomQueue()
 {
     $job = new Job();
     $job->state = JobState::SCHEDULED;
     $job->run_at = Carbon::now()->subMinute();
     $job->queue_connection = 'dogemq';
     $job->queue_name = 'food';
     $job->task = 'sometask';
     $job->save();
     $impersonator = new Impersonator();
     $impersonator->mock(JobSchedulerInterface::class, function (MockInterface $mock) use($job) {
         $mock->shouldReceive('findReady')->atLeast()->once()->andReturn(new Collection([$job]));
     });
     $impersonator->mock(Repository::class, function (MockInterface $mock) {
         $mock->shouldReceive('get')->with('jobs.queue.connection')->andReturn('nopemq')->once();
         $mock->shouldReceive('get')->with('jobs.queue.id')->andReturn('fakejobs')->once();
     });
     $impersonator->mock(QueuePusherInterface::class, function (MockInterface $mock) {
         $mock->shouldReceive('push')->atLeast()->once()->with(m::type('string'), m::type('array'), 'dogemq', 'food');
     });
     /** @var EnqueueScheduledCommand $command */
     $command = $impersonator->make(EnqueueScheduledCommand::class);
     $input = new StringInput('--take=25');
     $output = new NullOutput();
     $command->setLaravel($this->app);
     $command->run($input, $output);
 }
Example #4
0
 public function testProvideWithString()
 {
     $imp = new Impersonator();
     $this->setExpectedException(LackOfCoffeeException::class);
     $imp->provide(ExampleA::class);
 }
 public function testFireWithEarlyException()
 {
     $laravelJob = m::mock(LaravelJob::class);
     $laravelJob->shouldReceive('delete')->atLeast()->once();
     $impersonator = new Impersonator();
     $impersonator->mock(JobRepositoryInterface::class, function (MockInterface $mock) {
         $mock->shouldReceive('find')->with(1337)->atLeast()->once()->andThrow('Exception');
     });
     /** @var RunTaskCommand $command */
     $command = $impersonator->make(RunTaskCommand::class);
     $command->fire($laravelJob, ['job_id' => 1337]);
 }
 /**
  * Shortcut for constructing an instance of a CallAndThrowExpectation.
  *
  * @param string $methodName
  * @param array $arguments
  * @param string $exceptionClass
  * @param string $exceptionMessage
  * @param int $exceptionCode
  *
  * @return CallAndThrowExpectation
  */
 public function throwOn($methodName, array $arguments, $exceptionClass, $exceptionMessage = '', $exceptionCode = 0)
 {
     return Impersonator::throwOn($methodName, $arguments, $exceptionClass, $exceptionMessage, $exceptionCode);
 }
 public function testFindByTag()
 {
     $impersonator = new Impersonator();
     /** @var JobScheduler $scheduler */
     $scheduler = $impersonator->make(JobScheduler::class);
     $job = new Job();
     $job->task = 'test.test';
     $job->state = JobState::SCHEDULED;
     $job->save();
     $this->assertEquals(0, $scheduler->findByTag('wow')->count());
     $scheduler->tag($job, 'wow');
     $scheduler->tag($job, 'omg');
     $scheduler->tag($job, 'wow');
     $this->assertEquals(1, $scheduler->findByTag('wow')->count());
     $this->assertEquals(1, $scheduler->findByTag('omg')->count());
     $job->state = JobState::CANCELLED;
     $job->save();
     $this->assertEquals(0, $scheduler->findByTag('wow')->count());
     $this->assertEquals(0, $scheduler->findByTag('omg')->count());
     $this->assertEquals(1, $scheduler->findByTag('wow', false)->count());
     $this->assertEquals(1, $scheduler->findByTag('omg', false)->count());
 }