/**
  * @return void
  * @covers ::run
  */
 public function testRunCompletedJob()
 {
     $jobs = Fabricate::create('DelayedJobs.DelayedJobs', 1, function () {
         return ['status' => DelayedJobsTable::STATUS_SUCCESS];
     });
     $this->get('/delayed_jobs/run/' . $jobs[0]->id);
     $this->assertSession('Job Already Completed', 'Flash.flash.message');
     $this->assertResponseSuccess();
     $this->assertRedirect(['action' => 'index']);
 }
Exemplo n.º 2
0
 /**
  * @return void
  * @covers ::getRunningByHost
  */
 public function testGetRunningByHost()
 {
     Fabricate::create('DelayedJobs.DelayedJobs', 3, function ($data, $world) {
         return ['id' => $world->sequence('id'), 'status' => DelayedJobsTable::STATUS_BUSY, 'locked_by' => '1'];
     });
     Fabricate::create('DelayedJobs.DelayedJobs', 2, function ($data, $world) {
         return ['id' => $world->sequence('id', 4), 'status' => DelayedJobsTable::STATUS_NEW, 'locked_by' => '1'];
     });
     Fabricate::create('DelayedJobs.DelayedJobs', 3, function ($data, $world) {
         return ['id' => $world->sequence('id', 6), 'status' => DelayedJobsTable::STATUS_BUSY, 'locked_by' => '2'];
     });
     $query = $this->DelayedJobsTable->getRunningByHost(1);
     $results = $query->toArray();
     $this->assertCount(3, $results);
 }
Exemplo n.º 3
0
 /**
  * @param int $job_status Job status to use.
  * @param string $expected_message Expected message to test for.
  * @return void
  * @covers ::main
  * @dataProvider errorDataProvider
  */
 public function testErrorForStatus($job_status, $expected_message)
 {
     $job = Fabricate::create('DelayedJobs.DelayedJobs', 1, function () use($job_status) {
         return ['status' => $job_status];
     })[0];
     $this->Shell->DelayedJobs = $this->getMockForModel('DelayedJobs.DelayedJobs', ['failed'], ['table' => 'delayed_jobs']);
     $this->Shell->Lock->expects($this->once())->method('lock')->with('DelayedJobs.WorkerShell.main.1')->willReturn(true);
     $this->Shell->DelayedJobs->expects($this->once())->method('failed')->with($this->callback(function ($subject) use($job) {
         return $subject instanceof Entity && $subject->id === $job->id;
     }), $this->stringContains($expected_message));
     $this->Shell->args = [$job->id];
     $this->Shell->main();
 }
Exemplo n.º 4
0
 public function testDefineAndAssociationAndTraits()
 {
     Fabricate::define(['trait' => 'published'], ['published' => '1']);
     Fabricate::define(['PublishedPost', 'class' => 'Post'], function ($data, $world) {
         $world->traits('published');
         return ['title' => $world->sequence('title', function ($i) {
             return "Title{$i}";
         })];
     });
     $results = Fabricate::create('User', function ($data, $world) {
         return ['user' => 'taro', 'Post' => Fabricate::association('PublishedPost', 3, ['id' => false, 'author_id' => false])];
     });
     $this->assertEquals('taro', $results['User']['user']);
     $this->assertEquals(['1', '1', '1'], array_map(function ($post) {
         return $post['published'];
     }, $results['User']['Post']));
     $this->assertEquals(['Title1', 'Title2', 'Title3'], array_map(function ($post) {
         return $post['title'];
     }, $results['User']['Post']));
 }