/** * Build Process instance for each testcase file * * @param string $fileName * @param array $phpunitArgs * @return Process */ protected function buildProcess($fileName, array $phpunitArgs = []) { $processBuilder = new ProcessBuilder(); $dispatcher = $this->command->getDispatcher(); $dispatcher->dispatch(CommandEvents::RUN_TESTS_PROCESS, $processEvent = new RunTestsProcessEvent($this->command, $this->input, $this->output, $processBuilder, $phpunitArgs)); $process = $processBuilder->setEnv('BROWSER_NAME', $this->input->getArgument('browser'))->setEnv('ENV', strtolower($this->input->getArgument('environment')))->setEnv('SERVER_URL', $this->input->getOption('server-url'))->setEnv('PUBLISH_RESULTS', $this->input->getOption('publish-results') ? '1' : '0')->setEnv('FIXTURES_DIR', $this->input->getOption('fixtures-dir'))->setEnv('LOGS_DIR', $this->input->getOption('logs-dir'))->setEnv('DEBUG', $this->output->isDebug() ? '1' : '0')->setPrefix(STEWARD_BASE_DIR . '/vendor/bin/phpunit')->setArguments(array_merge($processEvent->getArgs(), [$fileName]))->setTimeout(3600)->getProcess(); return $process; }
/** * @dataProvider inputProvider * @param string $stringInput * @param string $expectedIdeKey */ public function testShouldGetIdeKeyFromCommandOptionOnCommandInitialization($stringInput, $expectedIdeKey) { $this->mockXdebugExtension($isExtensionLoaded = true, $isRemoteEnabled = true); $command = new RunCommand(new EventDispatcher()); $input = new StringInput($stringInput); $output = new BufferedOutput(); $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); // Trigger event to add the xdebug option to the command and bind the definition to the input $this->listener->onCommandConfigure(new BasicConsoleEvent($command)); $input->bind($command->getDefinition()); // Trigger command initialization event $event = new ExtendedConsoleEvent($command, $input, $output); $this->listener->onCommandRunTestsInit($event); if ($expectedIdeKey !== null) { $this->assertContains('Xdebug remote debugging initialized with IDE key: ' . $expectedIdeKey, $output->fetch()); } else { // no output expected (xdebug not triggered) $this->assertEmpty($output->fetch()); } }
/** * @todo Separate to tests for ExecutionLoop */ public function testShouldExitSuccessfullyIfNoProcessArePreparedOrQueued() { $seleniumAdapterMock = $this->getSeleniumAdapterMock(); $processSetMock = $this->getMockBuilder(ProcessSet::class)->disableOriginalConstructor()->getMock(); $processSetMock->expects($this->any())->method('count')->willReturn(333); $creatorMock = $this->getMockBuilder(ProcessSetCreator::class)->disableOriginalConstructor()->getMock(); $creatorMock->expects($this->once())->method('createFromFiles')->willReturn($processSetMock); $this->command->setSeleniumAdapter($seleniumAdapterMock); $this->command->setProcessSetCreator($creatorMock); $this->tester->execute(['command' => $this->command->getName(), 'environment' => 'staging', 'browser' => 'firefox', '--tests-dir' => __DIR__ . '/Fixtures/DummyTests']); $this->assertContains('No tasks left, exiting the execution loop...', $this->tester->getDisplay()); $this->assertSame(0, $this->tester->getStatusCode()); }
public function testShouldPropagateCustomOptionsIntoProcess() { $this->input = new StringInput('trolling chrome' . ' --' . RunCommand::OPTION_SERVER_URL . '=http://foo.bar:1337' . ' --' . RunCommand::OPTION_FIXTURES_DIR . '=custom-fixtures-dir/' . ' --' . RunCommand::OPTION_LOGS_DIR . '=custom-logs-dir/' . ' --' . RunCommand::OPTION_PUBLISH_RESULTS); $this->input->bind($this->command->getDefinition()); // Redeclare creator so it uses the new input $this->creator = new ProcessSetCreator($this->command, $this->input, $this->bufferedOutput, $this->publisherMock); $files = $this->findDummyTests('DummyTest.php'); // find only one file (we don't need more for the test) $processSet = $this->creator->createFromFiles($files, [], []); /** @var Process $process */ $process = $processSet->get(ProcessSet::PROCESS_STATUS_QUEUED)[self::NAME_DUMMY_TEST]->process; $processEnv = $process->getEnv(); $this->assertArraySubset(['BROWSER_NAME' => 'chrome', 'ENV' => 'trolling', 'SERVER_URL' => 'http://foo.bar:1337', 'PUBLISH_RESULTS' => '1', 'FIXTURES_DIR' => 'custom-fixtures-dir/', 'LOGS_DIR' => 'custom-logs-dir/'], $processEnv); }