/** * Creates a prepared {@link phpucConsoleArgs} instance and the required * /projects directory. * * @return void */ protected function setUp() { parent::setUp(); chdir(dirname(__FILE__)); $this->prepareArgv(array('example', '--project-name', 'phpUnderControl', PHPUC_TEST_DIR)); $input = new phpucConsoleInput(); $input->parse(); $this->args = $input->args; $this->createTestDirectories(array('/projects', '/apache-ant-1.7.0')); $this->createTestFile('/config.xml', '<cruisecontrol />'); }
/** * Tests the console args object without options. It also checks that only * the defined arguments are present. * * @return void */ public function testConsoleInstallCommandWithoutOptions() { $this->prepareArgv(array('install', '/opt/cruisecontrol', 'dummy-argument')); $input = new phpucConsoleInput(); $input->parse(); $args = $input->args; $this->assertTrue($args->hasArgument('cc-install-dir')); $this->assertEquals('/opt/cruisecontrol', $args->getArgument('cc-install-dir')); $this->assertEquals(1, count($args->arguments)); // Every other argument request must result in an OutOfRangeException try { $args->getArgument('phpUnderControl'); $this->fail('OutOfRangeException expected.'); } catch (OutOfRangeException $e) { } }
/** * Tests that the cc task fails for an invalid root directory. * * @return void */ public function testValidateWithInvalidCCInstallDirFail() { $this->prepareArgv(array('install', PHPUC_TEST_DIR . '/foobar')); $input = new phpucConsoleInput(); $input->parse(); $ccTask = new phpucCruiseControlTask(); $ccTask->setConsoleArgs($input->args); $this->setExpectedException('phpucValidateException'); $ccTask->validate(); }
/** * Executes the {@link phpucCheckoutTask} and tests the generated contents. * * @param string $type The version control system. * * @return void */ protected function doTestCheckout($type, $file) { $directory = PHPUC_TEST_DIR . "/projects/{$this->projectName}/source"; $input = new phpucConsoleInput(); $input->parse(); $this->assertFileNotExists("{$directory}/{$file}"); $checkout = new phpucCheckoutTask(); $checkout->setConsoleArgs($input->args); $checkout->execute(); $this->assertFileExists("{$directory}/{$file}"); $config = new DOMDocument(); $config->load(PHPUC_TEST_DIR . '/config.xml'); $xpath = new DOMXPath($config); $result = $xpath->query("//{$type}bootstrapper[@localWorkingCopy='{$directory}']"); $this->assertEquals(1, $result->length); $result = $xpath->query("//modificationset/{$type}[@localWorkingCopy='{$directory}']"); $this->assertEquals(1, $result->length); $build = new DOMDocument(); $build->load(PHPUC_TEST_DIR . "/projects/{$this->projectName}/build.xml"); $xpath = new DOMXPath($build); $result = $xpath->query('//target[@name="checkout"]/exec[@dir="${basedir}/source"]'); $this->assertEquals(1, $result->length); }
/** * Performs a single cli request. * * @return void */ public function run() { try { if ($this->input->parse()) { phpucConsoleOutput::set(new phpucConsoleOutput()); $command = phpucAbstractCommand::createCommand($this->input->args->command); $command->setConsoleArgs($this->input->args); $command->validate(); $command->execute(); } exit(0); } catch (phpucConsoleException $e) { echo $e->getMessage(), PHP_EOL; exit(1); } catch (phpucExecuteException $e) { echo $e->getMessage(), PHP_EOL; exit(2); } catch (phpucValidateException $e) { echo $e->getMessage(), PHP_EOL; exit(3); } catch (phpucRuntimeException $e) { echo $e->getMessage(), PHP_EOL; exit(5); } catch (Exception $e) { echo $e->getMessage(), PHP_EOL; exit(4); } }
/** * This test checks whether --without-php-documentor option has been set properly * * @covers phpucPhpDocumentorTask::registerCommandExtension * * @return void */ public function testPhpDocumentorTaskIsIgnored() { $this->prepareArgv(array('example', PHPUC_TEST_DIR, '--without-php-documentor')); $input = new phpucConsoleInput(); $input->parse(); $command = phpucAbstractCommand::createCommand($input->args->command); $command->setConsoleArgs($input->args); $cmdTasks = $command->createTasks(); $this->assertPhpucTaskNotOnTheList($cmdTasks, 'phpucPhpDocumentorTask'); }
/** * Initializes a clean console args object and creates a project dummy. * * @return void */ protected function setUp() { parent::setUp(); $this->projectDir = PHPUC_TEST_DIR . '/projects/php-under-control'; $options = array('example', '--pear-executables-dir', PHPUC_TEST_DIR . '/bin', '--project-name', $this->projectName); foreach ($this->options as $option) { $options[] = $option; } $options[] = PHPUC_TEST_DIR; $this->prepareArgv($options); $input = new phpucConsoleInput(); $input->parse(); $this->args = $input->args; $this->createTestDirectories(array('projects', "projects/{$this->projectName}")); $buildFile = new phpucBuildFile($this->projectDir . '/build.xml', $this->projectName); $buildFile->store(); }
/** * @covers phpucInstallCcScriptTask::execute * @dataProvider executeDataProvider */ public function testExecute($opts) { $this->createCruiseControlDummy(); $this->createInitScriptsDirectory(); $ccInstallDir = vfsStream::url('opt/cruisecontrol'); $initDir = PHPUC_TEST_DIR . '/init.d'; $javaHome = '/usr'; $ccBin = 'cruisecontrol.sh'; $ccUser = '******'; $args = array(); $args[] = 'setup-cc'; if (isset($opts['cc-bin'])) { $ccBin = $opts['cc-bin']; $args[] = '--cc-bin'; $args[] = $ccBin; } if (isset($opts['cc-user'])) { $ccUser = $opts['cc-user']; $args[] = '--cc-user'; $args[] = $ccUser; } if (isset($opts['java-home'])) { $javaHome = $opts['java-home']; $args[] = '--java-home'; $args[] = $javaHome; } $args[] = $ccInstallDir; $args[] = $initDir; $this->prepareArgv($args); $input = new phpucConsoleInput(); $input->parse(); $this->args = $input->args; $task = new phpucInstallCcScriptTask(); $task->setConsoleArgs($this->args); $task->execute(); $this->assertTrue(file_exists("{$initDir}/cruisecontrol")); $startScript = file_get_contents("{$initDir}/cruisecontrol"); $matches = array(); preg_match('/CC_INSTALL_DIR=(.*)/', $startScript, $matches); $this->assertEquals($ccInstallDir, $matches[1]); preg_match('/CC_BIN=(.*)/', $startScript, $matches); $this->assertEquals($ccBin, $matches[1]); preg_match('/JAVA_HOME=(.*)/', $startScript, $matches); $this->assertEquals($javaHome, $matches[1]); preg_match('/RUNASUSER=(.*)/', $startScript, $matches); $this->assertEquals($ccUser, $matches[1]); }
/** * Tests the execute method against a java server page that has placeholders * which were replaced in this test. * * @return void */ public function testExecuteWithCustomizedJavaServerPage() { // Create test directory $this->createTestDirectories(array('webapps/cruisecontrol')); $this->assertFileNotExists(PHPUC_TEST_DIR . '/webapps/cruisecontrol/main.jsp'); $custom1 = '<%-- begin phpUnderControl 3 --%> Hello <%-- end phpUnderControl 3 --%>'; $custom2 = '<%-- begin phpUnderControl 5 --%> World <%-- end phpUnderControl 5 --%>'; $custom3 = '<%-- begin phpUnderControl 6 --%> Baby <%-- end phpUnderControl 6 --%>'; // Create test files. $this->createTestFile('webapps/cruisecontrol/main.jsp', "\n {$custom1}\n {$custom2}\n {$custom3}\n "); $this->assertFileExists(PHPUC_TEST_DIR . '/webapps/cruisecontrol/main.jsp'); // Prepare args $this->prepareArgv(array('install', PHPUC_TEST_DIR)); $input = new phpucConsoleInput(); $input->parse(); $task = new phpucModifyFileTask(); $task->setConsoleArgs($input->args); $task->setFiles(array('/webapps/cruisecontrol/main.jsp')); $task->execute(); $content = file_get_contents(PHPUC_TEST_DIR . '/webapps/cruisecontrol/main.jsp'); $this->assertContains($custom1, $content); $this->assertContains($custom2, $content); $this->assertContains($custom3, $content); }
/** * Prepares the cli <b>$argv</b> array and create a {@link phpucConsoleArgs} * instance. * * @param array $argv A new argument array. * * @return phpucConsoleArgs */ protected function prepareConsoleArgs(array $argv = null) { $this->prepareArgv($argv); $input = new phpucConsoleInput(); $input->parse(); return $input->args; }
/** * Returns the console output of {@link phpucConsoleInput} for the given * <b>$option</b> * * @param string $option The option to use. * * @return string */ protected function fetchConsoleInputOutput($option) { $this->prepareArgv(array($option)); $input = new phpucConsoleInput(); ob_start(); $input->parse(); $content = ob_get_contents(); ob_end_clean(); return trim($content); }