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 testPush()
 {
     $imp = new Impersonator();
     $job = 'Omg\\Doge\\LaunchCommand';
     $data = ['omg' => 'whyyoudothis.jpg'];
     $queueName = 'rainbows';
     $queue = m::mock(Queue::class);
     $queue->shouldReceive('push')->with($job, $data, $queueName)->once();
     $imp->mock(QueueManager::class, function (MockInterface $mock) use($queue) {
         $mock->shouldReceive('connection')->with('dogemq')->once()->andReturn($queue);
     });
     $pusher = $imp->make(QueuePusher::class);
     $pusher->push($job, $data, 'dogemq', $queueName);
 }
 public function testMake()
 {
     $imp = new Impersonator();
     $this->assertTrue($imp->make(ExampleB::class) instanceof ExampleB);
     /** @var ExampleC $result */
     $result = $imp->make(ExampleC::class);
     $this->assertFalse($result->getOne() === $result->getTwo());
     $imp->provide(new ExampleA());
     /** @var ExampleC $result */
     $result = $imp->make(ExampleC::class);
     $this->assertTrue($result->getOne() === $result->getTwo());
     $imp->provide(new ExampleA());
     $imp->provide(m::mock(ExampleAInterface::class));
     /** @var ExampleC $result */
     $result = $imp->make(ExampleC::class);
     $this->assertTrue($result->getOne() !== $result->getTwo());
     $imp->mock(ExampleA::class, function (MockInterface $mock) {
         $mock->shouldReceive('sayHello')->andReturn('Goodbye')->once();
     });
     /** @var ExampleC $result */
     $result = $imp->make(ExampleC::class);
     $this->assertTrue($result->getOne() === $result->getTwo());
     $this->assertEquals('Goodbye', $result->getTwo()->sayHello());
 }
 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);
 }
 public function testPushCopy()
 {
     $impersonator = new Impersonator();
     $job = new Job();
     $job->task = 'test.test';
     $job->state = JobState::CANCELLED;
     $tomorrow = Carbon::tomorrow();
     $nextWeek = Carbon::today()->addDays(7);
     $impersonator->mock(JobFactoryInterface::class, function (MockInterface $mock) use($job) {
         $mock->shouldReceive('duplicate')->once()->with($job)->andReturn($job);
     });
     /** @var JobScheduler $scheduler */
     $scheduler = $impersonator->make(JobScheduler::class);
     $result = $scheduler->pushCopy($job, $tomorrow, $nextWeek);
     $this->assertInstanceOf(Job::class, $result);
     $this->assertEquals(JobState::SCHEDULED, $result->state);
     $this->assertEquals($tomorrow, $result->run_at);
     $this->assertEquals($nextWeek, $result->expires_at);
 }
 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]);
 }