Skip to content

Commit

Permalink
Merge ab63f3d into 16d10fc
Browse files Browse the repository at this point in the history
  • Loading branch information
kilip committed Jun 13, 2019
2 parents 16d10fc + ab63f3d commit 58e00ed
Show file tree
Hide file tree
Showing 125 changed files with 828 additions and 65 deletions.
2 changes: 1 addition & 1 deletion RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function mergeCoverage()
->option('clover', 'build/logs/clover.xml')
->option('html', 'build/html')
->option('ansi')
->arg('build/cov')
->arg(__DIR__.'/build/cov')
->run();
}

Expand Down
5 changes: 4 additions & 1 deletion behat.yaml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ default:
- src/*/Resources
- src/*/Context
- src/*/Spec
- src/*/vendor
- src/*/build
- file: src/*/RoboFile.php
reports:
html: build/behat
php: build/cov/behat.cov
php: build/cov/behat.cov
6 changes: 5 additions & 1 deletion bin/split
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ BRANCH=$1

function split()
{
SHA1=`./bin/splitsh-lite --prefix=$1`
SHA1=`./bin/splitsh-lite --prefix=$1 -scratch`
git push $2 "$SHA1:refs/heads/$BRANCH" -f
}

Expand All @@ -21,3 +21,7 @@ git pull origin $BRANCH
remote code-coverage-bridge git@github.com:doyolabs/code-coverage-bridge.git
remote behat-code-coverage git@github.com:doyolabs/behat-code-coverage.git
remote phpspec-code-coverage git@github.com:doyolabs/phpspec-code-coverage.git

split 'src/behat' behat-code-coverage
split 'src/bridge' code-coverage-bridge
split 'src/phpspec' phpspec-code-coverage
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
"prefer-stable": true,
"autoload": {
"psr-4": {
"Doyo\\Bridge\\CodeCoverage\\": "src/code-coverage",
"Doyo\\Behat\\CodeCoverage\\": "src/behat-extension",
"Doyo\\PhpSpec\\CodeCoverage\\": "src/phpspec-extension"
"Doyo\\Bridge\\CodeCoverage\\": "src/bridge",
"Doyo\\Behat\\CodeCoverage\\": "src/behat",
"Doyo\\PhpSpec\\CodeCoverage\\": "src/phpspec"
}
},
"autoload-dev": {
"psr-4": {
"Spec\\Doyo\\Bridge\\CodeCoverage\\": "src/code-coverage/Spec",
"Spec\\Doyo\\Behat\\CodeCoverage\\": "src/behat-extension/Spec",
"Spec\\Doyo\\PhpSpec\\CodeCoverage\\": "src/phpspec-extension/Spec"
"Spec\\Doyo\\Bridge\\CodeCoverage\\": "src/bridge/Spec",
"Spec\\Doyo\\Behat\\CodeCoverage\\": "src/behat/Spec",
"Spec\\Doyo\\PhpSpec\\CodeCoverage\\": "src/phpspec/Spec"
}
},
"replace": {
Expand All @@ -48,12 +48,13 @@
"behat/behat": "^3.5"
},
"require-dev": {
"guzzlehttp/guzzle": "^6.3",
"phpspec/phpspec": "^4.3 | ^5.0",
"symfony/http-foundation": "^3.4 | ^4.3",
"symfony/cache": "^3.4",
"phpunit/phpcov": "^4.0 | >=5.0",
"phpunit/phpunit": ">=6.0",
"symfony/cache": "^3.4",
"symfony/console": "^3.4 | ^4.3",
"symfony/http-foundation": "^3.4 | ^4.3",
"symfony/yaml": "^3.4 | ^4.0"
}
}
23 changes: 13 additions & 10 deletions phpspec.yaml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,34 @@ suites:
namespace: Doyo\Bridge\CodeCoverage
psr4_prefix: Doyo\Bridge\CodeCoverage
spec_prefix: Spec
src_path: src/code-coverage
spec_path: src/code-coverage
src_path: src/bridge
spec_path: src/bridge

behat_extension:
namespace: Doyo\Behat\CodeCoverage
psr4_prefix: Doyo\Behat\CodeCoverage
spec_prefix: Spec
src_path: src/behat-extension
spec_path: src/behat-extension
src_path: src/behat
spec_path: src/behat

phpspec_extension:
namespace: Doyo\PhpSpec\CodeCoverage
psr4_prefix: Doyo\PhpSpec\CodeCoverage
spec_prefix: Spec
src_path: src/phpspec-extension
spec_path: src/phpspec-extension
src_path: src/phpspec
spec_path: src/phpspec

extensions:
Doyo\PhpSpec\CodeCoverage\Extension:
filter:
- directory: src
exclude:
- src/*/Spec
- src/*/Resources
- src/*/Context
- src/*/Resources
- src/*/Context
- src/*/Spec
- src/*/vendor
- src/*/build
- file: src/*/RoboFile.php
reports:
php: build/cov/phpspec.cov
html: build/phpspec
html: build/phpspec
16 changes: 0 additions & 16 deletions phpunit.xml.dist

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions src/bridge/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.gitignore export-ignore
*.dist export-ignore
.travis.yml export-ignore
composer.lock export-ignore
Spec export-ignore
RoboFile.php export-ignore
4 changes: 4 additions & 0 deletions src/bridge/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor/
/build/
composer.lock
.php_cs.cache
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,20 @@ private function processFilter(ContainerBuilder $container)

private function filterWhitelist(Definition $definition, $options, $method)
{
$basePath = $options['basePath'];
$suffix = $options['suffix'] ?: '.php';
$prefix = $options['prefix'] ?: '';
$type = $options['directory'] ? 'directory' : 'file';
$directory = $options['directory'];
$file = $options['file'];
$type = !is_null($options['directory']) ? 'directory' : 'file';

if (preg_match('/\/\*(\..+)/', $directory, $matches)) {
if(!is_null($directory) && "" === $directory){
$directory = getcwd();
}

if (
!is_null($directory)
&& preg_match('/\/\*(\..+)/', $directory, $matches)
) {
$suffix = $matches[1];
$directory = str_replace($matches[0], '', $directory);
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions src/bridge/Exception/HttpException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php


namespace Doyo\Bridge\CodeCoverage\Exception;


class HttpException extends \Exception
{

}
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions src/bridge/Http/ClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php


namespace Doyo\Bridge\CodeCoverage\Http;

use Psr\Http\Message\ResponseInterface;

interface ClientInterface
{
public function request($method, $uri, array $options = []): ResponseInterface;
}
File renamed without changes.
21 changes: 21 additions & 0 deletions src/bridge/Listener/AbstractSessionListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php


namespace Doyo\Bridge\CodeCoverage\Listener;


use Doyo\Bridge\CodeCoverage\Session\SessionInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

abstract class AbstractSessionListener implements EventSubscriberInterface
{
protected $session;

public function __construct(
SessionInterface $session
)
{
$this->session = $session;
}

}
50 changes: 50 additions & 0 deletions src/bridge/Listener/LocalListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Doyo\Bridge\CodeCoverage\Listener;

use Doyo\Bridge\CodeCoverage\Event\CoverageEvent;

class LocalListener extends AbstractSessionListener
{
public static function getSubscribedEvents()
{
return [
CoverageEvent::refresh => 'refresh',
CoverageEvent::start => 'start',
CoverageEvent::complete => 'complete'
];
}

public function refresh()
{
$this->session->reset();
}

public function start(CoverageEvent $event)
{
$session = $this->session;
$testCase = $event->getProcessor()->getCurrentTestCase();

$session->setTestCase($testCase);
$session->save();
}

public function complete(CoverageEvent $event)
{
$session = $this->session;
$processor = $event->getProcessor();
$consoleIO = $event->getConsoleIO();

// need to refresh session first
$session->refresh();

$processor->merge($session->getProcessor());

if($session->hasExceptions()){

foreach($session->getExceptions() as $exception){
$consoleIO->coverageInfo($exception->getMessage());
}
}
}
}
115 changes: 115 additions & 0 deletions src/bridge/Listener/RemoteListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php


namespace Doyo\Bridge\CodeCoverage\Listener;


use Doyo\Bridge\CodeCoverage\Event\CoverageEvent;
use Doyo\Bridge\CodeCoverage\Exception\HttpException;
use Doyo\Bridge\CodeCoverage\Http\ClientInterface;
use Doyo\Bridge\CodeCoverage\Session\SessionInterface;

class RemoteListener extends AbstractSessionListener
{
/**
* @var ClientInterface
*/
private $httpClient;

/**
* @var array
*/
private $config;

/**
* @var string
*/
private $coverageUrl;

/**
* @var \Exception[]
*/
private $exceptions;

public function __construct(
SessionInterface $session,
ClientInterface $httpClient,
string $coverageUrl,
array $config
)
{
parent::__construct($session);

$this->httpClient = $httpClient;
$this->coverageUrl = $coverageUrl;
$this->config = $config;
$this->exceptions = [];
}

public static function getSubscribedEvents()
{
return [
CoverageEvent::refresh => 'refresh',
CoverageEvent::complete => 'complete'
];
}

public function refresh()
{
$client = $this->httpClient;
$session = $this->session;
$body = json_encode($this->config);
$coverageUrl = $this->coverageUrl;

$options = [
'body' => $body,
'query' => [
'action' => 'init',
'session' => $session->getName()
]
];

try{
$client->request('POST', $coverageUrl, $options);
}catch (\Exception $exception){
$this->exceptions[] = $exception;
}
}

public function complete(CoverageEvent $event)
{
$coverageUrl = $this->coverageUrl;
$client = $this->httpClient;
$session = $this->session;
$consoleIO = $event->getConsoleIO();

$options = [
'query' => [
'action' => 'read',
'session' => $session->getName()
]
];

try{
/* @var SessionInterface $remoteSession */
$response = $client->request('GET', $coverageUrl, $options);
$remoteSession = $response->getBody()->getContents();
$remoteSession = unserialize($remoteSession);
$event->getProcessor()->merge($remoteSession->getProcessor());
}catch (\Exception $exception){
$this->exceptions[] = $exception;
}

$exceptions = array_merge($this->exceptions, $remoteSession->getExceptions());

$ids = [];
foreach($exceptions as $exception){
$message = $exception->getMessage();
$id = md5($message);
if(!in_array($id,$ids)){
$ids[] = $id;
$consoleIO->coverageInfo($message);
}
}
}
}
File renamed without changes.
File renamed without changes.

0 comments on commit 58e00ed

Please sign in to comment.