public static function setUpBeforeClass() { self::$testDir = dirname(dirname(__DIR__)) . DS . 'tmp'; self::cleanTempDir(); $shellClassFile = new File(self::$testDir . DS . 'Console' . DS . 'Command' . DS . 'JobClassOneShell.php', true, 0755); $shellClassFile->append('<?php class JobClassOneShell { public function funcOne() {} public function funcTwo() {} public function perform() {} }'); $pluginShellClassFile = new File(self::$testDir . DS . 'Plugin' . DS . 'MyPlugin' . DS . 'Console' . DS . 'Command' . DS . 'PluginJobClassOneShell.php', true, 0755); $pluginShellClassFile->append('<?php class PluginJobClassOneShell { public function funcOne() {} public function funcTwo() {} public function perform() {} }'); $invalidShellClassFile = new File(self::$testDir . DS . 'Console' . DS . 'Command' . DS . 'InvalidJobClassShell.php', true, 0755); $invalidShellClassFile->append('<?php class NotTheSameClassShell { public function funcOne() {} public function funcTwo() {} public function perform() {} }'); $shellClassFile = new File(self::$testDir . DS . 'Console' . DS . 'Command' . DS . 'NotAJobShellClass.php', true, 0755); $shellClassFile->append('<?php class NotAJobShellClass { public function funcOne() {} }'); Resque_Job_Creator::$rootFolder = self::$testDir . DS; parent::setUpBeforeClass(); }
/** * Create and return a job instance * * @param string $className className of the job to instanciate * @return object $args a job instance * @throws Resque_Exception when the class is not found, or does not follow the job file convention */ public static function createJob($className, $args) { list($plugin, $model) = pluginSplit($className); if (self::$rootFolder === null) { self::$rootFolder = dirname(dirname(dirname(__DIR__))) . DS; } $classpath = self::$rootFolder . (empty($plugin) ? '' : 'Plugin' . DS . $plugin . DS) . 'Console' . DS . 'Command' . DS . $model . '.php'; if (file_exists($classpath)) { require_once $classpath; } else { throw new Resque_Exception('Could not find job class ' . $className . '.'); } if (!class_exists($model)) { throw new Resque_Exception('Could not find job class ' . $className . '.'); } if (!method_exists($model, 'perform')) { throw new Resque_Exception('Job class ' . $className . ' does not contain a perform method.'); } if (!isset($args[0]) || !method_exists($model, $args[0])) { throw new Resque_Exception('Job class ' . $className . ' does not contain ' . $args[0] . ' method.'); } return new $model(); }