/** * @dataProvider methodProvider */ public function testRunInvalidMethod($method) { $context = \TestHelper::getContext(); $aimeos = \TestHelper::getAimeos(); $name = 'ControllerJobsAdminJobDefaultRun'; $context->getConfig()->set('madmin/job/manager/name', $name); $object = new \Aimeos\Controller\Jobs\Admin\Job\Standard($context, $aimeos); \Aimeos\MAdmin\Job\Manager\Factory::injectManager('\\Aimeos\\MAdmin\\Job\\Manager\\' . $name, $this->jobManagerStub); $this->jobManagerStub->expects($this->atLeastOnce())->method('searchItems')->will($this->onConsecutiveCalls(array($this->jobItemStub), array())); $this->jobManagerStub->expects($this->once())->method('saveItem'); $this->jobItemStub->expects($this->atLeastOnce())->method('getMethod')->will($this->returnValue($method)); $this->jobItemStub->expects($this->once())->method('setStatus')->with($this->equalTo(0)); $object->run(); }
/** * Executes the job. * * @throws \Aimeos\Controller\Jobs\Exception If an error occurs */ public function run() { $context = $this->getContext(); $jobManager = \Aimeos\MAdmin\Job\Manager\Factory::createManager($context); $criteria = $jobManager->createSearch(true); $start = 0; do { $items = $jobManager->searchItems($criteria); foreach ($items as $item) { try { $job = $item->getMethod(); if (preg_match('/^[a-zA-Z0-9\\_]+\\.[a-zA-Z0-9\\_]+$/', $job) !== 1) { throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid characters in job name "%1$s"', $job)); } $parts = explode('.', $job); if (count($parts) !== 2) { throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid job method "%1$s"', $job)); } $method = $parts[1]; $class = str_replace('_', '\\', $parts[0]); $name = '\\Aimeos\\Controller\\ExtJS\\' . $class . '\\Factory'; if (class_exists($name) === false) { throw new \Aimeos\Controller\Jobs\Exception(sprintf('Class "%1$s" not available', $name)); } $name .= '::createController'; if (($controller = call_user_func_array($name, array($context))) === false) { throw new \Aimeos\Controller\Jobs\Exception(sprintf('Unable to call factory method "%1$s"', $name)); } if (method_exists($controller, $method) === false) { throw new \Aimeos\Controller\Jobs\Exception(sprintf('Method "%1$s" not available', $method)); } $result = $controller->{$method}((object) $item->getParameter()); $item->setResult($result); $item->setStatus(-1); } catch (\Exception $e) { $str = 'Error while processing job "%1$s": %2$s'; $context->getLogger()->log(sprintf($str, $item->getMethod(), $e->getMessage())); $item->setStatus(0); } $jobManager->saveItem($item); } $count = count($items); $start += $count; $criteria->setSlice($start); } while ($count > 0); }
/** * Adds the job test data. * * @throws \Aimeos\MW\Setup\Exception If a required ID is not available */ private function addJobTestData() { $adminJobManager = \Aimeos\MAdmin\Job\Manager\Factory::createManager($this->additional, 'Standard'); $ds = DIRECTORY_SEPARATOR; $path = __DIR__ . $ds . 'data' . $ds . 'job.php'; if (($testdata = (include $path)) == false) { throw new \Aimeos\MShop\Exception(sprintf('No file "%1$s" found for job domain', $path)); } $job = $adminJobManager->createItem(); $this->conn->begin(); foreach ($testdata['job'] as $dataset) { $job->setId(null); $job->setLabel($dataset['label']); $job->setMethod($dataset['method']); $job->setParameter($dataset['parameter']); $job->setResult($dataset['result']); $job->setStatus($dataset['status']); $adminJobManager->saveItem($job, false); } $this->conn->commit(); }
public function testCreateManagerNotExisting() { $this->setExpectedException('\\Aimeos\\MShop\\Exception'); \Aimeos\MAdmin\Job\Manager\Factory::createManager(\TestHelperMShop::getContext(), 'unknown'); }