diff --git a/.gitignore b/.gitignore index bf9a8f0..eefaa3d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ /vendor # Composer installed package cache -/.composer.lock \ No newline at end of file +/composer.lock \ No newline at end of file diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..d321654 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,55 @@ +checks: + php: true + +tools: + external_code_coverage: false + php_code_coverage: false + php_code_sniffer: + config: { standard: 'Zend' } + php_changetracking: false + php_sim: false + php_cs_fixer: true + php_mess_detector: true + php_pdepend: true + php_analyzer: true + sensiolabs_security_checker: true + +filter: + paths: + - 'src/*' + excluded_paths: + - 'features/bootstrap/*' + - 'dev/*' + - 'var/*' + - 'lib/*' + - 'bin/*' + - 'vendor/*' + +build: + environment: + php: + version: 5.4 + ini: + 'always_populate_raw_post_data': '-1' + + tests: + override: + - bin/phpspec run --no-interaction --format=pretty + after: + - SCRUTINIZER_START_TIME=$(cat /tmp/build-start-time.txt) sh -c 'curl -sS https://gist.githubusercontent.com/tonypiper/fd3cf9a67b71d4e3928c/raw/152f1d873f98ff4256ca8bc3041443eae7c890b4/keenio-logger.php | php' + + dependencies: + before: + - date -u +"%Y-%m-%dT%H:%M:%SZ" > /tmp/build-start-time.txt + + override: + - { command: 'composer update --no-interaction --prefer-source', idle_timeout: 600 } + + cache: + directories: [ vendor/, bin/ ] + +build_failure_conditions: + - 'elements.rating(<= B).new.exists' + - 'issues.label("coding-style").new.exists' + - 'issues.new.exists' + - 'project.metric("scrutinizer.quality", < 9.00)' diff --git a/spec/Bex/Behat/Context/TestRunnerContextSpec.php b/spec/Bex/Behat/Context/TestRunnerContextSpec.php index 6e01ce6..1600191 100644 --- a/spec/Bex/Behat/Context/TestRunnerContextSpec.php +++ b/spec/Bex/Behat/Context/TestRunnerContextSpec.php @@ -83,7 +83,8 @@ function it_saves_files_in_document_root_directory(PyStringNode $content, Filesy function it_runs_behat_in_working_directory(ProcessFactory $processFactory, Process $process) { $processFactory->createBehatProcess( - Argument::containingString(sys_get_temp_dir() .'/behat-test-runner') + Argument::containingString(sys_get_temp_dir() .'/behat-test-runner'), + Argument::any() )->shouldBeCalled()->willReturn($process); $process->run()->shouldBeCalled(); @@ -116,16 +117,16 @@ function it_can_detect_when_there_was_no_failing_tests_but_expected( ProcessFactory $processFactory, Process $process ) { - $processFactory->createBehatProcess(Argument::any())->willReturn($process); + $processFactory->createBehatProcess(Argument::any(), Argument::any())->willReturn($process); $this->createWorkingDirectory(); $this->iRunBehat(); - $process->getExitCode()->willReturn(0); + $process->isSuccessful()->willReturn(true); $this->shouldThrow( new \RuntimeException('Behat did not find any failing scenario.') )->duringIShouldSeeAFailingTest(); - $process->getExitCode()->willReturn(255); + $process->isSuccessful()->willReturn(false); $this->shouldNotThrow('\RuntimeException')->duringIShouldSeeAFailingTest(); } diff --git a/src/Services/ProcessFactory.php b/src/Services/ProcessFactory.php index e01c601..96cdb16 100644 --- a/src/Services/ProcessFactory.php +++ b/src/Services/ProcessFactory.php @@ -25,13 +25,14 @@ public function __construct(PhpExecutableFinder $phpFinder = null) /** * @param string $workingDirectory + * @param string $parameters * * @return Process */ - public function createBehatProcess($workingDirectory) + public function createBehatProcess($workingDirectory, $parameters = '') { return new Process( - sprintf('%s %s --no-colors', $this->phpBin, escapeshellarg(BEHAT_BIN_PATH)), + sprintf('%s %s %s', $this->phpBin, escapeshellarg(BEHAT_BIN_PATH), $parameters), $workingDirectory ); } diff --git a/src/TestRunnerContext.php b/src/TestRunnerContext.php index 8364b58..fdbe4a6 100644 --- a/src/TestRunnerContext.php +++ b/src/TestRunnerContext.php @@ -116,6 +116,9 @@ public function afterRunTests(AfterScenarioScope $scope) $this->destroyProcesses(); } + /** + * @return void + */ public function createWorkingDirectory() { $this->workingDirectory = tempnam(sys_get_temp_dir(), 'behat-test-runner'); @@ -126,11 +129,17 @@ public function createWorkingDirectory() $this->filesystem->mkdir($this->documentRoot, 0770); } + /** + * @return void + */ public function clearWorkingDirectory() { $this->filesystem->remove($this->workingDirectory); } + /** + * @return void + */ public function destroyProcesses() { /** @var Process $process */ @@ -144,6 +153,9 @@ public function destroyProcesses() $this->behatProcess = null; } + /** + * @param AfterScenarioScope $scope + */ public function printTesterOutputOnFailure(AfterScenarioScope $scope) { if (!$scope->getTestResult()->isPassed()) { @@ -177,6 +189,7 @@ public function iHaveTheFeature(PyStringNode $content) $content->getRaw() ); } + /** * @Given I have the context: */ @@ -190,10 +203,12 @@ public function iHaveTheContext(PyStringNode $definition) /** * @When I run Behat + * @When I run Behat with :paramters parameter + * @When I run Behat with :paramters parameters */ - public function iRunBehat() + public function iRunBehat($parameters = '') { - $this->runBehat(); + $this->runBehat($parameters); } /** @@ -218,7 +233,7 @@ public function iHaveAWebServerRunningOnAddressAndPort($hostname, $port) */ public function iShouldSeeAFailingTest() { - if ($this->behatProcess->getExitCode() == 0) { + if ($this->behatProcess->isSuccessful()) { throw new RuntimeException('Behat did not find any failing scenario.'); } } @@ -228,7 +243,7 @@ public function iShouldSeeAFailingTest() */ public function iShouldNotSeeAFailingTest() { - if ($this->behatProcess->getExitCode() != 0) { + if (!$this->behatProcess->isSuccessful()) { throw new RuntimeException('Behat found a failing scenario.'); } } @@ -253,14 +268,25 @@ public function getStandardErrorMessage() return $this->behatProcess->getErrorOutput(); } - private function runBehat() + /** + * @param string $parameters + * + * @return void + */ + private function runBehat($parameters = '') { - $behatProcess = $this->processFactory->createBehatProcess($this->workingDirectory); + $behatProcess = $this->processFactory->createBehatProcess($this->workingDirectory, $parameters); $this->behatProcess = $behatProcess; $this->processes[] = $this->behatProcess; $behatProcess->run(); } + /** + * @param string $hostname + * @param string $port + * + * @return void + */ private function runWebServer($hostname, $port) { $webServerProcess = $this->processFactory->createWebServerProcess($this->documentRoot, $hostname, $port); @@ -268,6 +294,9 @@ private function runWebServer($hostname, $port) $webServerProcess->start(); } + /** + * @return void + */ private function runBrowser() { if (is_null($this->browserCommand)) {