Пример #1
0
 public function testProvide()
 {
     $imp = new Impersonator();
     $instanceA = new ExampleA();
     $imp->provide($instanceA);
     /** @var ExampleB $instanceB */
     $instanceB = $imp->make(ExampleB::class);
     $this->assertEquals($instanceA, $instanceB->getExampleA());
 }
Пример #2
0
 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);
 }
Пример #5
0
 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());
 }
Пример #6
0
 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]);
 }