Skip to content

Commit

Permalink
Merge pull request #1 from kilip/wip
Browse files Browse the repository at this point in the history
core feature improvements
  • Loading branch information
kilip committed Jun 10, 2019
2 parents d0f25b8 + f3c0636 commit 63fe78e
Show file tree
Hide file tree
Showing 26 changed files with 189 additions and 454 deletions.
12 changes: 12 additions & 0 deletions .gitattributes
@@ -0,0 +1,12 @@
.editor-config export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.php_cs.dist export-ignore
.travis.yml export-ignore
*.dist export-ignore
*.yml export-ignore
composer.lock export-ignore
RoboFile.php export-ignore
features export-ignore
spec export-ignore
tests export-ignore
2 changes: 1 addition & 1 deletion .php_cs.dist
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);

$header = <<<'HEADER'
This file is part of the DoyoLabs Behat Common project.
This file is part of the doyo/behat-contexts project.
(c) Anthonius Munthi <me@itstoni.com>
Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Expand Up @@ -29,15 +29,14 @@ cache:
- &run-test |
robo test
- &run-test-coverage
robo test --coverage
robo coverage

jobs:
include:
- php: '7.0'
- php: '7.1'
- php: '7.2'
- php: '7.3'
- php: '7.2'
env: COVERAGE=yes
before_cache:
- *install-php-coveralls
Expand Down
138 changes: 85 additions & 53 deletions RoboFile.php
@@ -1,7 +1,7 @@
<?php

/*
* This file is part of the DoyoLabs Behat Common project.
* This file is part of the doyo/behat-coverage-extension project.
*
* (c) Anthonius Munthi <me@itstoni.com>
*
Expand All @@ -11,6 +11,15 @@

declare(strict_types=1);

/*
* This file is part of the doyo/behat-code-coverage project.
*
* (c) Anthonius Munthi <me@itstoni.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Lurker\Event\FilesystemEvent;
use Robo\Tasks;

Expand All @@ -25,7 +34,10 @@ class RoboFile extends Tasks

private $watch = false;

public function watch($options = ['coverage'=>false])
/**
* @param array $options
*/
public function watch($options = ['coverage' => false])
{
$this->watch = true;

Expand All @@ -35,6 +47,7 @@ public function watch($options = ['coverage'=>false])
'spec',
'features',
];

$this->taskWatch()
->monitor(
$paths,
Expand All @@ -44,105 +57,124 @@ function (FilesystemEvent $event) use ($options) {
false !== strpos($resource, 'build')
|| false !== strpos($resource, 'var')
) {
return 0;
return;
}
return $this->test($options);
$this->test($options);
},
FilesystemEvent::ALL
)
->run();

return $this->watch;
}

public function test($options=['coverage' => false])
public function test()
{
$this->stopOnFail(false);
$this->taskExec('clear')->run();

$this->coverage = $options['coverage'];
if ($this->coverage) {
$this->taskFilesystemStack()
->mkdir(__DIR__.'/build', 0775)
->mkdir(__DIR__.'/build/cov', 0775)
->run();
}

/** @var \Robo\Result[] $results */
$results = [];
$results[] = $this->configurePhpSpec()->run();
$results[] = $this->configurePhpUnit()->run();

if($this->watch){
$this->taskExec('clear')->run();
if (!$this->watch) {
$results[] = $this->configureBehat()->run();
}

$phpspec = $this->configurePhpSpec();
$behat = $this->configureBehat();
$phpunit = $this->configurePhpUnit();

$tasks = [$phpspec, $phpunit, $behat];
$failed = false;
$errorTask = null;
$messages = [];

/* @var \Robo\Task\BaseTask $task */
foreach($tasks as $task){
/* @var \Robo\Result $test */
$test = $task->run();
if($test->getExitCode() !== 0){
$failed = true;
$errorTask = $task;
$hasError = false;
foreach ($results as $result) {
if (0 !== $result->getExitCode()) {
$hasError = true;
}
}

$builder = $this->collectionBuilder();
if ($this->coverage) {
$this->doMergeCoverage($builder);
$builder->run();
$this->mergeCoverage();
}

if(!$failed){
$this->yell('Tests runs successfully');
return;
if (!$this->watch) {
if ($hasError) {
throw new \Robo\Exception\TaskException($this, 'Tests failed');
}
}
}

return \Robo\Result::error($errorTask,'Tests Failed');
public function coverage()
{
$this->coverage = true;
$this->test();
}

private function doMergeCoverage(\Robo\Collection\CollectionBuilder $builder)
public function mergeCoverage()
{
$builder->taskExec('phpdbg -qrr ./vendor/bin/phpcov merge --ansi --clover build/logs/clover.xml build/cov');
$builder->taskExec('phpdbg -qrr ./vendor/bin/phpcov merge --ansi --html build/html build/cov');
$builder->taskExec('phpdbg -qrr ./vendor/bin/phpcov merge --text --ansi build/cov');
$this
->taskExec('phpdbg -qrr ./vendor/bin/phpcov')
->arg('merge')
->option('clover', 'build/logs/clover.xml')
->option('html', 'build/html')
->option('text')
->option('ansi')
->arg('build/cov')
->run();
}

/**
* @return \Robo\Task\Base\Exec|\Robo\Task\Testing\Behat
*/
private function configureBehat()
{
$behat = $this->taskBehat();
$behat->noInteraction()
$task = $this->taskBehat();
$task->noInteraction()
->format('progress')
->colors();

if ($this->coverage) {
$behat->option('coverage');
return $this->taskExec('phpdbg -qrr '.$behat->getCommand());
$task->option('coverage');
$command = $task->getCommand();
$task = $this->taskExec('phpdbg -qrr '.$command);
} else {
$task->option('tags', '~@remote');
}

return $behat;
return $task;
}

/**
* @return \Robo\Task\Base\Exec|\Robo\Task\Testing\Phpspec
*/
private function configurePhpSpec()
{
$spec = $this->taskPhpspec();
$spec->noCodeGeneration()
$task = $this->taskPhpspec();
$task->noCodeGeneration()
->noInteraction()
->format('dot');

if ($this->coverage) {
$spec->option('coverage');
return $this->taskExec('phpdbg -qrr '.$spec->getCommand());
$task->option('coverage');
$task = $this->taskExec('phpdbg -qrr '.$task->getCommand());
}

return $spec;
return $task;
}

/**
* @return \Robo\Task\Base\Exec|\Robo\Task\Testing\PHPUnit
*/
private function configurePhpUnit()
{
$phpunit = $this->taskPhpUnit();
$task = $this->taskPhpUnit();

if ($this->coverage) {
$phpunit->option('coverage-php', 'build/cov/phpunit.cov');
return $this
->taskExec('phpdbg -qrr '.$phpunit->getCommand());
$task = $this->taskExec('phpdbg -qrr '.$task->getCommand());
$task->option('coverage-php', 'build/cov/01-phpunit.cov')
->option('coverage-html', 'build/phpunit');
}

return $phpunit;
return $task;
}
}
22 changes: 7 additions & 15 deletions behat.yaml.dist
Expand Up @@ -11,25 +11,17 @@ default:
Behat\Symfony2Extension:
kernel:
class: Test\Doyo\Behat\Fixtures\Kernel
env: test
debug: true
Behat\MinkExtension:
sessions:
default:
symfony2: ~
Doyo\Behat\Extension:
translator: 'translator'
Doyo\Behat\CodeCoverage\Extension:
drivers:
- local
Doyo\Behat\Coverage\Extension:
filter:
whitelist:
include:
directories:
src: ~
- src
report:
format: php
options:
target: '%paths.base%/build/cov/behat.cov'
#format: php
#options:
# target: '%paths.base%/build/cov/behat.cov'
php: build/cov/behat.cov
html: build/behat
Doyo\Behat\Extension:
translator: 'translator'
27 changes: 16 additions & 11 deletions composer.json
Expand Up @@ -12,7 +12,13 @@
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"preferred-install": "dist"
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
Expand All @@ -25,21 +31,20 @@
}
},
"require": {
"php": ">=7.0",
"leanphp/behat-code-coverage": "^3.3 | ^3.4",
"behat/behat": "^3.5",
"behatch/contexts": "^3.2",
"symfony/expression-language": "^3.4 | ^4.3",
"doyo/phpspec-common": "dev-master"
"symfony/expression-language": "^3.4 | ^4.3"
},
"require-dev": {
"phpspec/phpspec": "^4.3 | ^5.0",
"phpunit/phpunit": "^6.0 | ^7.0",
"symfony/translation": "^3.4 | ^4.3",
"symfony/routing": "^3.4 | ^4.3",
"behat/mink-browserkit-driver": "^1.3",
"behat/symfony2-extension": "^2.1",
"phpunit/php-code-coverage": "^5.0 | ^6.0",
"doyo/behat-coverage-extension": "^1.0@dev",
"doyo/phpspec-common": "dev-master",
"phpspec/phpspec": "^4.3 | ^5.0",
"phpunit/phpcov": "^4.0 | ^5.0",
"behat/mink-browserkit-driver": "^1.3"
"phpunit/phpunit": "^6.0 | 7.0",
"symfony/framework-bundle": "^3.4 | 4.3",
"symfony/routing": "^3.4 | ^4.3",
"symfony/translation": "^3.4 | ^4.3"
}
}
6 changes: 3 additions & 3 deletions features/bootstrap/FeatureContext.php
Expand Up @@ -12,8 +12,8 @@
declare(strict_types=1);

use Behat\Behat\Context\Context;
use Doyo\Behat\ExpressionAwareContextInterface;
use Doyo\Behat\ExpressionLanguage;
use Doyo\Behat\Expression\ExpressionAwareContextInterface;
use Doyo\Behat\Expression\ExpressionLanguage;
use Webmozart\Assert\Assert;

/**
Expand All @@ -26,7 +26,7 @@ class FeatureContext implements Context, ExpressionAwareContextInterface
private $route;

/**
* @var ExpressionLanguage
* @var \Doyo\Behat\Expression\ExpressionLanguage
*/
private $expression;

Expand Down
5 changes: 3 additions & 2 deletions phpspec.yaml.dist
@@ -1,5 +1,6 @@
formatter.name: pretty
suites:
behat:
doyo_behat:
namespace: Doyo\Behat
psr4_prefix: Doyo\Behat

Expand All @@ -11,5 +12,5 @@ extensions:
- php
- html
output:
php: build/cov/phpspec.cov
php: build/cov/03-phpspec.cov
html: build/phpspec

0 comments on commit 63fe78e

Please sign in to comment.