From 6dbdb04a7f3645cd795fe25d7f37a1b5280afff8 Mon Sep 17 00:00:00 2001 From: Tibor Kotosz Date: Sun, 15 Nov 2015 15:03:02 +0100 Subject: [PATCH 1/6] Amend the process factory to be able to set parameters for the secondary behat --- src/Services/ProcessFactory.php | 5 +++-- src/TestRunnerContext.php | 37 +++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/Services/ProcessFactory.php b/src/Services/ProcessFactory.php index e01c601..0968704 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', BEHAT_BIN_PATH, $parameters), $workingDirectory ); } diff --git a/src/TestRunnerContext.php b/src/TestRunnerContext.php index 8364b58..9fecc47 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); } /** @@ -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)) { From bf11a0920d5ac0f4e1532d4099daf1d63896f4b7 Mon Sep 17 00:00:00 2001 From: Tibor Kotosz Date: Sun, 15 Nov 2015 15:11:49 +0100 Subject: [PATCH 2/6] Fix tests, fix gitignore, fix scrutinizer yml --- .gitignore | 2 +- .scrutinizer.yml | 55 +++++++++++++++++++ .../Behat/Context/TestRunnerContextSpec.php | 5 +- 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 .scrutinizer.yml 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..bd5c8d0 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,7 +117,7 @@ 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(); From 17ecb5fefb837654cc96c028c7f271ee4f153ba2 Mon Sep 17 00:00:00 2001 From: Tibor Kotosz Date: Sun, 15 Nov 2015 15:17:07 +0100 Subject: [PATCH 3/6] Apply scrutinizer's suggested fix --- src/TestRunnerContext.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TestRunnerContext.php b/src/TestRunnerContext.php index 9fecc47..33c4465 100644 --- a/src/TestRunnerContext.php +++ b/src/TestRunnerContext.php @@ -233,7 +233,7 @@ public function iHaveAWebServerRunningOnAddressAndPort($hostname, $port) */ public function iShouldSeeAFailingTest() { - if ($this->behatProcess->getExitCode() == 0) { + if ($this->behatProcess->getExitCode() === 0) { throw new RuntimeException('Behat did not find any failing scenario.'); } } @@ -243,7 +243,7 @@ public function iShouldSeeAFailingTest() */ public function iShouldNotSeeAFailingTest() { - if ($this->behatProcess->getExitCode() != 0) { + if ($this->behatProcess->getExitCode() !== 0) { throw new RuntimeException('Behat found a failing scenario.'); } } From eb7e99715ba3de79ae6944b0b76ac68adb5ac2b9 Mon Sep 17 00:00:00 2001 From: Tibor Kotosz Date: Sun, 15 Nov 2015 16:43:21 +0100 Subject: [PATCH 4/6] Fix behat process factory method --- src/Services/ProcessFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/ProcessFactory.php b/src/Services/ProcessFactory.php index 0968704..10ee0f6 100644 --- a/src/Services/ProcessFactory.php +++ b/src/Services/ProcessFactory.php @@ -32,7 +32,7 @@ public function __construct(PhpExecutableFinder $phpFinder = null) public function createBehatProcess($workingDirectory, $parameters = '') { return new Process( - sprintf('%s %s', BEHAT_BIN_PATH, $parameters), + sprintf('%s %s --no-colors %s', $this->phpBin, escapeshellarg(BEHAT_BIN_PATH), $parameters), $workingDirectory ); } From ed00f0c8478358a9c63d60c53abcde0b916e1a52 Mon Sep 17 00:00:00 2001 From: Tibor Kotosz Date: Mon, 16 Nov 2015 08:58:40 +0100 Subject: [PATCH 5/6] Fix reported issues --- src/Services/ProcessFactory.php | 2 +- src/TestRunnerContext.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Services/ProcessFactory.php b/src/Services/ProcessFactory.php index 10ee0f6..96cdb16 100644 --- a/src/Services/ProcessFactory.php +++ b/src/Services/ProcessFactory.php @@ -32,7 +32,7 @@ public function __construct(PhpExecutableFinder $phpFinder = null) public function createBehatProcess($workingDirectory, $parameters = '') { return new Process( - sprintf('%s %s --no-colors %s', $this->phpBin, escapeshellarg(BEHAT_BIN_PATH), $parameters), + sprintf('%s %s %s', $this->phpBin, escapeshellarg(BEHAT_BIN_PATH), $parameters), $workingDirectory ); } diff --git a/src/TestRunnerContext.php b/src/TestRunnerContext.php index 33c4465..fdbe4a6 100644 --- a/src/TestRunnerContext.php +++ b/src/TestRunnerContext.php @@ -233,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.'); } } @@ -243,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.'); } } From c8003fb55318bdb929761d21df08ef3fe786b67b Mon Sep 17 00:00:00 2001 From: Tibor Kotosz Date: Mon, 16 Nov 2015 09:05:08 +0100 Subject: [PATCH 6/6] Fix failing phpspec tests --- spec/Bex/Behat/Context/TestRunnerContextSpec.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/Bex/Behat/Context/TestRunnerContextSpec.php b/spec/Bex/Behat/Context/TestRunnerContextSpec.php index bd5c8d0..1600191 100644 --- a/spec/Bex/Behat/Context/TestRunnerContextSpec.php +++ b/spec/Bex/Behat/Context/TestRunnerContextSpec.php @@ -121,12 +121,12 @@ function it_can_detect_when_there_was_no_failing_tests_but_expected( $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(); }