Skip to content

Commit 803602a

Browse files
committed
support ClockMock and DnsMock with PHPUnit 10+
1 parent fddd33e commit 803602a

8 files changed

+226
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Extension;
13+
14+
use PHPUnit\Runner\Extension\Extension;
15+
use PHPUnit\Runner\Extension\Facade;
16+
use PHPUnit\Runner\Extension\ParameterCollection;
17+
use PHPUnit\TextUI\Configuration\Configuration;
18+
19+
class ClockMockExtension implements Extension
20+
{
21+
public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void
22+
{
23+
$facade->registerSubscriber(new RegisterClockMockSubscriber());
24+
$facade->registerSubscriber(new UnregisterClockMockSubscriber());
25+
}
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Extension;
13+
14+
use PHPUnit\Runner\Extension\Extension;
15+
use PHPUnit\Runner\Extension\Facade;
16+
use PHPUnit\Runner\Extension\ParameterCollection;
17+
use PHPUnit\TextUI\Configuration\Configuration;
18+
19+
class DebugClassLoaderExtension implements Extension
20+
{
21+
public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void
22+
{
23+
$facade->registerSubscriber(new DebugClassLoaderSubscriber());
24+
}
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Extension;
13+
14+
use PHPUnit\Event\Application\Started;
15+
use PHPUnit\Event\Application\StartedSubscriber;
16+
use Symfony\Component\ErrorHandler\DebugClassLoader;
17+
18+
class DebugClassLoaderSubscriber implements StartedSubscriber
19+
{
20+
public function notify(Started $event): void
21+
{
22+
DebugClassLoader::enable();
23+
}
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Extension;
13+
14+
use PHPUnit\Runner\Extension\Extension;
15+
use PHPUnit\Runner\Extension\Facade;
16+
use PHPUnit\Runner\Extension\ParameterCollection;
17+
use PHPUnit\TextUI\Configuration\Configuration;
18+
19+
class DnsMockExtension implements Extension
20+
{
21+
public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void
22+
{
23+
$facade->registerSubscriber(new RegisterDnsMockSubscriber());
24+
$facade->registerSubscriber(new UnregisterDnsMockSubscriber());
25+
}
26+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Extension;
13+
14+
use PHPUnit\Event\Test\PreparationStarted;
15+
use PHPUnit\Event\Test\PreparationStartedSubscriber;
16+
use PHPUnit\Metadata\Group;
17+
use Symfony\Bridge\PhpUnit\ClockMock;
18+
19+
class RegisterClockMockSubscriber implements PreparationStartedSubscriber
20+
{
21+
public function notify(PreparationStarted $event): void
22+
{
23+
$test = $event->test();
24+
25+
foreach ($test->metadata() as $metadata) {
26+
if ($metadata instanceof Group && 'time-sensitive' === $metadata->groupName()) {
27+
ClockMock::register($test->className());
28+
ClockMock::withClockMock(true);
29+
}
30+
}
31+
}
32+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Extension;
13+
14+
use PHPUnit\Event\Test\PreparationStarted;
15+
use PHPUnit\Event\Test\PreparationStartedSubscriber;
16+
use PHPUnit\Metadata\Group;
17+
use Symfony\Bridge\PhpUnit\DnsMock;
18+
19+
class RegisterDnsMockSubscriber implements PreparationStartedSubscriber
20+
{
21+
public function notify(PreparationStarted $event): void
22+
{
23+
$test = $event->test();
24+
25+
foreach ($test->metadata() as $metadata) {
26+
if ($metadata instanceof Group && 'dns-sensitive' === $metadata->groupName()) {
27+
DnsMock::register($test->className());
28+
}
29+
}
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Extension;
13+
14+
use PHPUnit\Event\Test\Finished;
15+
use PHPUnit\Event\Test\FinishedSubscriber;
16+
use PHPUnit\Metadata\Group;
17+
use Symfony\Bridge\PhpUnit\ClockMock;
18+
19+
class UnregisterClockMockSubscriber implements FinishedSubscriber
20+
{
21+
public function notify(Finished $event): void
22+
{
23+
$test = $event->test();
24+
25+
foreach ($test->metadata() as $metadata) {
26+
if ($metadata instanceof Group && 'time-sensitive' === $metadata->groupName()) {
27+
ClockMock::withClockMock(false);
28+
}
29+
}
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Extension;
13+
14+
use PHPUnit\Event\Test\Finished;
15+
use PHPUnit\Event\Test\FinishedSubscriber;
16+
use PHPUnit\Metadata\Group;
17+
use Symfony\Bridge\PhpUnit\DnsMock;
18+
19+
class UnregisterDnsMockSubscriber implements FinishedSubscriber
20+
{
21+
public function notify(Finished $event): void
22+
{
23+
$test = $event->test();
24+
25+
foreach ($test->metadata() as $metadata) {
26+
if ($metadata instanceof Group && 'dns-sensitive' === $metadata->groupName()) {
27+
DnsMock::withMockedHosts([]);
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)
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