Skip to content

[Bridge\PhpUnit] Add extra clock-mocked namespaces in phpunit.xml.dist #16502

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

Merged
merged 1 commit into from
Nov 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 27 additions & 5 deletions src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,26 @@
*/
class SymfonyTestsListener extends \PHPUnit_Framework_BaseTestListener
{
private static $globallyEnabled = false;
private $state = -1;
private $skippedFile = false;
private $wasSkipped = array();
private $isSkipped = array();

public function __construct(array $extraClockMockedNamespaces = array())
{
if ($extraClockMockedNamespaces) {
foreach ($extraClockMockedNamespaces as $ns) {
ClockMock::register($ns.'\DummyClass');
}
}
if (self::$globallyEnabled) {
$this->state = -2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to define these states as constants so others could understand what they mean ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but this is private internal details, and constants are public... and giving a name is hard :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard indeed ;)

} else {
self::$globallyEnabled = true;
}
}

public function __destruct()
{
if (0 < $this->state) {
Expand Down Expand Up @@ -56,9 +71,16 @@ public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
}
}
}
foreach ($suite->tests() as $test) {
if ($test instanceof \PHPUnit_Framework_TestSuite && in_array('time-sensitive', \PHPUnit_Util_Test::getGroups($test->getName()), true)) {
ClockMock::register($test->getName());
$testSuites = array($suite);
for ($i = 0; isset($testSuites[$i]); ++$i) {
foreach ($testSuites[$i]->tests() as $test) {
if ($test instanceof \PHPUnit_Framework_TestSuite) {
if (class_exists($test->getName(), false) && in_array('time-sensitive', \PHPUnit_Util_Test::getGroups($test->getName()), true)) {
ClockMock::register($test->getName());
} else {
$testSuites[] = $test;
}
}
}
}
} elseif (2 === $this->state) {
Expand Down Expand Up @@ -91,7 +113,7 @@ public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $ti

public function startTest(\PHPUnit_Framework_Test $test)
{
if ($test instanceof \PHPUnit_Framework_TestCase) {
if (-2 < $this->state && $test instanceof \PHPUnit_Framework_TestCase) {
$groups = \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName());

if (in_array('time-sensitive', $groups, true)) {
Expand All @@ -103,7 +125,7 @@ public function startTest(\PHPUnit_Framework_Test $test)

public function endTest(\PHPUnit_Framework_Test $test, $time)
{
if ($test instanceof \PHPUnit_Framework_TestCase) {
if (-2 < $this->state && $test instanceof \PHPUnit_Framework_TestCase) {
$groups = \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName());

if (in_array('time-sensitive', $groups, true)) {
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/HttpKernel/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@
</exclude>
</whitelist>
</filter>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
<arguments>
<array>
<element><string>Symfony\Component\HttpFoundation</string></element>
</array>
</arguments>
</listener>
</listeners>
</phpunit>
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy