8000 [VarDumper][PhpUnitBridge] VarDumperServerListener by ogizanagi · Pull Request #26696 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[VarDumper][PhpUnitBridge] VarDumperServerListener #26696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[VarDumper][PhpUnitBridge] VarDumperServerListener
  • Loading branch information
ogizanagi committed Apr 16, 2018
commit 360bde68a06d494f6dd5dcce42bdd3a3165a291c
39 changes: 39 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Legacy/VarDumperServerListenerForV5.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\PhpUnit\Legacy;

use Symfony\Component\VarDumper\Dumper\ContextProvider\ContextProviderInterface;

/**
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*
* @internal
*/
class VarDumperServerListenerForV5 extends \PHPUnit_Framework_BaseTestListener implements ContextProviderInterface
{
private $trait;

public function __construct(string $host = null)
{
$this->trait = new VarDumperServerListenerTrait($host);
}

public function startTest(\PHPUnit_Framework_Test $test)
{
$this->trait->startTest($test);
}

public function getContext(): ?array
{
$this->trait->getContext();
}
}
41 changes: 41 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Legacy/VarDumperServerListenerForV6.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\PhpUnit\Legacy;

use PHPUnit\Framework\BaseTestListener;
use PHPUnit\Framework\Test;
use Symfony\Component\VarDumper\Dumper\ContextProvider\ContextProviderInterface;

/**
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*
* @internal
*/
class VarDumperServerListenerForV6 extends BaseTestListener implements ContextProviderInterface
{
private $trait;

public function __construct(string $host = null)
{
$this->trait = new VarDumperServerListenerTrait($host);
}

public function startTest(Test $test)
{
$this->trait->startTest($test);
}

public function getContext(): ?array
{
$this->trait->getContext();
}
}
44 changes: 44 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Legacy/VarDumperServerListenerForV7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\PhpUnit\Legacy;

use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestListenerDefaultImplementation;
use PHPUnit\Framework\TestSuite;
use Symfony\Component\VarDumper\Dumper\ContextProvider\ContextProviderInterface;

/**
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*
* @internal
*/
class VarDumperServerListenerForV7 implements TestListener, ContextProviderInterface
{
use TestListenerDefaultImplementation;

private $trait;

public function __construct(string $host = null)
{
$this->trait = new VarDumperServerListenerTrait($host);
}

public function startTestSuite(TestSuite $suite): void
{
$this->trait->startTest($suite);
}

public function getContext(): ?array
{
$this->trait->getContext();
}
}
60 changes: 60 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Legacy/VarDumperServerListenerTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\PhpUnit\Legacy;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\VarDumperServerListener;
use Symfony\Component\VarDumper\Dumper\ServerDumper;

/**
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*
* @internal
*/
class VarDumperServerListenerTrait
{
/** @var TestCase|null */
private $currentTestCase;

public function __construct(string $host = null)
{
if (!class_exists(ServerDumper::class)) {
throw new \LogicException(sprintf('The "%s" class is required for using the "%s" listener. Install "symfony/var-dumper" version 4.1 or above.', ServerDumper::class, VarDumperServerListener::class));
}

ServerDumper::register($host, true, array('phpunit' => $this));
}

public function startTest($test)
{
if (!$test instanceof TestCase) {
$this->currentTestCase = null;

return;
}

$this->currentTestCase = $test;
}

public function getContext(): ?array
{
if (!$this->currentTestCase) {
return null;
}

return array(
'identifier' => spl_object_hash($this->currentTestCase),
'test_class' => \get_class($this->currentTestCase),
'test_case' => $this->currentTestCase->getName(),
);
}
}
26 changes: 26 additions & 0 deletions src/Symfony/Bridge/PhpUnit/VarDumperServerListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\PhpUnit;

if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
class_alias('Symfony\Bridge\PhpUnit\Legacy\VarDumperServerListenerForV5', 'Symfony\Bridge\PhpUnit\VarDumperServerListener');
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '7.0.0', '<')) {
class_alias('Symfony\Bridge\PhpUnit\Legacy\VarDumperServerListenerForV6', 'Symfony\Bridge\PhpUnit\VarDumperServerListener');
67E6 } else {
class_alias('Symfony\Bridge\PhpUnit\Legacy\VarDumperServerListenerForV7', 'Symfony\Bridge\PhpUnit\VarDumperServerListener');
}

if (false) {
class VarDumperServerListener
{
}
}
1 change: 1 addition & 0 deletions src/Symfony/Bridge/PhpUnit/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"suggest": {
"symfony/debug": "For tracking deprecated interfaces usages at runtime with DebugClassLoader",
"symfony/var-dumper": "To use the VarDumperServerListener",
"ext-zip": "Zip support is required when using bin/simple-phpunit"
},
"conflict": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public function describe(OutputInterface $output, Data $data, array $context, in
$this->lastIdentifier = $clientId;

$section = "Received from client #$clientId";
if (isset($context['request'])) {
if (isset($context['phpunit'])) {
$phpunit = $context['phpunit'];
$this->lastIdentifier = $phpunit['identifier'];
$section = sprintf('%s::%s', $phpunit['test_class'], $phpunit['test_case']);
} elseif (isset($context['request'])) {
$request = $context['request'];
$this->lastIdentifier = $request['identifier'];
$section = sprintf('%s %s', $request['method'], $request['uri']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public function describe(OutputInterface $output, Data $data, array $context, in
}

$title = '-';
if (isset($context['request'])) {
if (isset($context['phpunit'])) {
$phpunit = $context['phpunit'];
$title = '<code>PhpUnit</code>'.sprintf('%s::%s', $phpunit['test_class'], $phpunit['test_case']);
$dedupIdentifier = $phpunit['identifier'];
} elseif (isset($context['request'])) {
$request = $context['request'];
$title = sprintf('<code>%s</code> <a href="%s">%s</a>', $request['method'], $uri = $request['uri'], $uri);
$dedupIdentifier = $request['identifier'];
Expand Down
0