/** * @return void * @covers ::run */ public function testRunExecuteJob() { $table = $this->getModel('\\DelayedJobs\\Model\\Table\\DelayedJobsTable', ['get'], 'DelayedJobs', 'delayed_jobs'); TableRegistry::set('DelayedJobs.DelayedJobs', $table); $job_data = Fabricate::attributes_for('DelayedJobs.DelayedJobs')[0]; $job = $this->getMock('\\DelayedJobs\\Model\\Entity\\DelayedJob', ['execute'], [$job_data]); $job_output = 'Test completed'; $table->expects($this->once())->method('get')->willReturn($job); $job->expects($this->once())->method('execute')->willReturn($job_output); $this->get('/delayed_jobs/run/' . $job->id); $this->assertSession('Job Completed: ' . $job_output, 'Flash.flash.message'); $this->assertResponseSuccess(); $this->assertRedirect(['action' => 'index']); }
/** * @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); }
protected function _buildJobMock() { $job_data = Fabricate::attributes_for('DelayedJobs.DelayedJobs', 1, function () { return ['status' => DelayedJobsTable::STATUS_BUSY]; })[0]; $job = $this->getMock('\\DelayedJobs\\Model\\Entity\\DelayedJob', ['execute'], [$job_data]); $this->Shell->DelayedJobs = $this->getMockForModel('DelayedJobs.DelayedJobs', ['failed', 'completed', 'get'], ['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('get')->with($job->id)->willReturn($job); return $job; }
public function testContextHasFakerFactory() { $results = Fabricate::attributes_for('User', function ($data, $world) { return ['user' => $world->faker()->name]; }); $this->assertNotEmpty($results[0]['user']); }
} while ($root !== $lastRoot); throw new Exception('Cannot find the root of the application, unable to run tests'); }; $root = $findRoot(__FILE__); unset($findRoot); chdir($root); require_once 'vendor/cakephp/cakephp/src/basics.php'; require_once 'vendor/autoload.php'; require_once 'config/bootstrap.php'; define('ROOT', $root . DS . 'tests' . DS . 'test_app' . DS); define('APP', ROOT . 'App' . DS); define('CONFIG', $root . DS . 'config' . DS); define('TMP', sys_get_temp_dir() . DS); Configure::write('debug', true); Configure::write('App', ['namespace' => 'App', 'paths' => ['plugins' => [ROOT . 'Plugin' . DS], 'templates' => [ROOT . 'App' . DS . 'Template' . DS]]]); Cake\Cache\Cache::config(['_cake_core_' => ['engine' => 'File', 'prefix' => 'cake_core_', 'serialize' => true, 'path' => '/tmp'], '_cake_model_' => ['engine' => 'File', 'prefix' => 'cake_model_', 'serialize' => true, 'path' => '/tmp']]); if (!getenv('db_dsn')) { putenv('db_dsn=sqlite:///:memory:?quoteIdentifiers=1'); } if (!getenv('DB')) { putenv('DB=sqlite'); } ConnectionManager::config('test', ['url' => getenv('db_dsn')]); Plugin::load('DelayedJobs', ['path' => dirname(dirname(__FILE__)) . DS]); Plugin::load('Crud', ['path' => dirname(dirname(__FILE__)) . DS . 'vendor' . DS . 'friendsofcake' . DS . 'crud' . DS]); DispatcherFactory::add('Asset'); DispatcherFactory::add('Routing'); DispatcherFactory::add('ControllerFactory'); Fabricate::config(function ($config) { $config->adaptor = new CakeFabricateAdaptor(); });
/** * Apply traits * * @param array $record data * @param FabricateContext $world context * @return array record applied traits */ private function applyTraits($record, $world) { foreach ($world->flashTraits() as $use) { $traits = Fabricate::traits(); if (array_key_exists($use, $traits)) { $record = array_merge($record, $traits[$use]->run($record, $world)); } } return $record; }