Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from kilip/wip
implemented local session
- Loading branch information
Showing
42 changed files
with
851 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# EditorConfig helps developers define and maintain consistent | ||
# coding styles between different editors and IDEs | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
# Change these settings to your own preference | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
# We recommend you to keep these unchanged | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.feature] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.json] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.neon] | ||
indent_style = tab | ||
indent_size = 4 | ||
|
||
[*.php] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.xml] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.yml] | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = false | ||
|
||
[*.yaml] | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = false | ||
|
||
[.circleci/config.yml] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[.gitmodules] | ||
indent_style = tab | ||
|
||
[.php_cs] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[.styleci.yml] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[.travis.yml] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[appveyor.yml] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[behat.yml{.dist}] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[coverage.yml{,.dist}] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[coverage.yaml{,.dist}] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[composer.json] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[phpstan.neon{,.dist}] | ||
indent_style = tab | ||
indent_size = 4 | ||
|
||
[phpunit.xml{,.dist}] | ||
indent_style = space | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
|
||
namespace Doyo\Bridge\CodeCoverage\Compiler; | ||
|
||
|
||
use Doyo\Bridge\CodeCoverage\Listener\LocalListener; | ||
use Doyo\Bridge\CodeCoverage\Session\LocalSession; | ||
use Doyo\Bridge\CodeCoverage\Session\RemoteSession; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class SessionPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
$sessions = $container->getParameterBag()->get('sessions'); | ||
|
||
foreach($sessions as $name => $config){ | ||
$driver = $config['driver']; | ||
if('local' === $driver){ | ||
$this->createLocalSession($container, $name, $config); | ||
} | ||
} | ||
} | ||
|
||
private function createLocalSession(ContainerBuilder $container, string $name, array $config) | ||
{ | ||
$id = 'sessions.'.$name; | ||
$sessionId = $id.'.session'; | ||
$listenerId = $id.'.listener'; | ||
|
||
$session = new Definition(LocalSession::class); | ||
$session->addArgument($name); | ||
$session->addTag('coverage.session'); | ||
$session->addMethodCall('init',[$container->getParameter('config')]); | ||
$container->setDefinition($sessionId, $session); | ||
|
||
$listener = new Definition(LocalListener::class); | ||
$listener->addArgument(new Reference($sessionId)); | ||
$container->setDefinition($listenerId, $listener); | ||
|
||
$dispatcher = $container->findDefinition('coverage'); | ||
$dispatcher->addMethodCall('addSubscriber',[new Reference($listenerId)]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
|
||
namespace Doyo\Bridge\CodeCoverage\Context; | ||
|
||
|
||
use Behat\Behat\Context\Context; | ||
use Behat\Behat\Hook\Scope\BeforeScenarioScope; | ||
use Behat\Gherkin\Node\PyStringNode; | ||
use Symfony\Component\Config\Resource\DirectoryResource; | ||
use Symfony\Component\Process\ExecutableFinder; | ||
use Symfony\Component\Process\Process; | ||
|
||
class BehatContext implements Context | ||
{ | ||
private $configFile; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $cwd; | ||
|
||
/** | ||
* @var ConsoleContext | ||
*/ | ||
private $consoleContext; | ||
|
||
public function __construct( | ||
$cwd = false | ||
) | ||
{ | ||
$cwd = $cwd ?:getcwd(); | ||
$this->cwd = $cwd; | ||
} | ||
|
||
/** | ||
* @beforeScenario | ||
*/ | ||
public function beforeScenario(BeforeScenarioScope $scope) | ||
{ | ||
$this->consoleContext = $scope->getEnvironment()->getContext(ConsoleContext::class); | ||
|
||
$coverageContext = $scope->getEnvironment()->getContext(CoverageContext::class); | ||
$coverageContext->setWorkingDir($this->cwd); | ||
} | ||
|
||
/** | ||
* @Given I configure behat with: | ||
*/ | ||
public function iConfigureBehat(PyStringNode $node) | ||
{ | ||
$contents = $node->getRaw(); | ||
$id = md5($contents); | ||
$tmp = sys_get_temp_dir().'/doyo/tests/behat/behat-'.$id.'.yaml'; | ||
if(!is_dir($dir = dirname($tmp))){ | ||
mkdir($dir, 0775, true); | ||
} | ||
file_put_contents($tmp, $contents); | ||
|
||
$this->configFile = $tmp; | ||
} | ||
|
||
/** | ||
* @Given I run behat | ||
* | ||
* @param array $options | ||
* @param string $cwd | ||
*/ | ||
public function iRunBehat(array $options = [], $cwd = null) | ||
{ | ||
$finder = new ExecutableFinder(); | ||
$phpdbg = $finder->find('phpdbg'); | ||
$cmd = realpath(__DIR__.'/../Resources/fixtures/bin/behat'); | ||
$configFile = $this->configFile; | ||
$cwd = realpath($this->cwd); | ||
|
||
$phpdbg = [$phpdbg, '-qrr']; | ||
if(extension_loaded('xdebug')){ | ||
$phpdbg = []; | ||
} | ||
|
||
|
||
$commands = array_merge($phpdbg,[ | ||
$cmd, | ||
'--config='.$configFile, | ||
'--coverage' | ||
]); | ||
|
||
$commands = array_merge($commands, $options); | ||
$this->consoleContext->run($commands, $cwd); | ||
} | ||
} |
Oops, something went wrong.