/** * Method to run the application routines. Most likely you will want to instantiate a controller * and execute it, or perform some sort of task directly. * * @return void * * @since 1.0 */ protected function doExecute() { $package = $this->io->getArgument(0); $class = $this->io->getArgument(1); $class = StringNormalise::toClassNamespace($class); if (!class_exists($class)) { $class = 'Windwalker\\' . ucfirst($package) . '\\' . $class; } if (!class_exists($class)) { $this->stop('Class not exists: ' . $class); } $packagePath = WINDWALKER_ROOT . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $package; $classPath = ReflectionHelper::getPath($class); $testPath = $packagePath . DIRECTORY_SEPARATOR . 'Test'; $testClass = $this->io->getArgument(2, ReflectionHelper::getShortName($class) . 'Test'); $testClass = StringNormalise::toClassNamespace($testClass); $testFile = $testPath . DIRECTORY_SEPARATOR . $testClass . '.php'; $realTestClass = 'Windwalker\\' . ucfirst($package) . '\\Test\\' . $testClass; $autoload = WINDWALKER_ROOT . '/vendor/autoload.php'; $command = sprintf('vendor/phpunit/phpunit-skeleton-generator/phpunit-skelgen generate-test --bootstrap="%s" %s %s %s %s', $autoload, $class, $classPath, $realTestClass, $testFile); $command = 'php ' . WINDWALKER_ROOT . '/' . $command; if (!defined('PHP_WINDOWS_VERSION_MAJOR')) { // Replace '\' to '\\' in MAC $command = str_replace('\\', '\\\\', $command); } \Windwalker\Filesystem\Folder::create(dirname($testFile)); $this->exec($command); }
/** * prepareExecute * * @return void */ protected function prepareExecute() { $element = $this->getArgument(1); $client = strtolower($this->getOption('c')); $class = $this->getOption('class'); if ($element) { list($type, $name, $group) = array_values(ExtensionHelper::extractElement($element)); if ($client == 'admin') { $client = 'administrator'; } if ($type == 'plugin') { $client = 'site'; } elseif ($type == 'component') { $client = 'administrator'; } } $path = JPATH_ROOT . '/resources/seeders'; $classPath = $path . '/' . $class . '.php'; if (!file_exists($classPath) && $element) { $path = PathHelper::get($element, $client); $classPath = $path . '/src/' . ucfirst($name) . '/Seed/' . $class . '.php'; } if (file_exists($classPath)) { include_once $classPath; } $className = $class; if (!class_exists($className)) { $className = sprintf('%s\\Seed\\%s', ucfirst($name), ucfirst($class)); } if (!class_exists($className)) { throw new \UnexpectedValueException('Class: ' . $class . ' not found.'); } // Auto include classes $path = dirname(ReflectionHelper::getPath($className)); $files = \JFolder::files($path, '.', false, true); /** @var \SplFileInfo $file */ foreach ($files as $file) { $file = new \SplFileInfo($file); \JLoader::register($file->getBasename('.php'), $file->getPathname()); } $this->app->set('seed.class', $className); }