-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Library is updated to use PHPUnit 10
- Loading branch information
Showing
7 changed files
with
152 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/vendor/ | ||
/composer.lock | ||
/.phpunit.result.cache | ||
/.phpunit.cache/ |
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 |
---|---|---|
@@ -1,32 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html --> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" | ||
colors="true" | ||
bootstrap="vendor/autoload.php" | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" | ||
colors="true" | ||
bootstrap="vendor/autoload.php" | ||
cacheDirectory=".phpunit.cache" | ||
> | ||
<php> | ||
<ini name="display_errors" value="1" /> | ||
<ini name="error_reporting" value="-1" /> | ||
<ini name="display_errors" value="1"/> | ||
<ini name="error_reporting" value="-1"/> | ||
</php> | ||
|
||
<testsuites> | ||
<testsuite name="Tests"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<coverage processUncoveredFiles="true"> | ||
<coverage/> | ||
<source> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
<directory>src</directory> | ||
</include> | ||
<exclude> | ||
<directory suffix=".php">src/PHPUnit</directory> | ||
<directory>src/PHPUnit</directory> | ||
</exclude> | ||
</coverage> | ||
|
||
<listeners> | ||
<listener class="Flying\Date\PHPUnit\Listener\AdjustableDateListener"/> | ||
</listeners> | ||
</source> | ||
<extensions> | ||
<bootstrap class="Flying\Date\PHPUnit\Extension\DateExtension"/> | ||
</extensions> | ||
</phpunit> |
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,23 @@ | ||
<?php /** @noinspection DevelopmentDependenciesUsageInspection */ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flying\Date\PHPUnit\Extension; | ||
|
||
use Flying\Date\PHPUnit\Extension\Subscriber\ReleaseDateAdjustment; | ||
use Flying\Date\PHPUnit\Extension\Subscriber\SetupDateAdjustment; | ||
use PHPUnit\Runner\Extension\Extension; | ||
use PHPUnit\Runner\Extension\Facade; | ||
use PHPUnit\Runner\Extension\ParameterCollection; | ||
use PHPUnit\TextUI\Configuration\Configuration; | ||
|
||
class DateExtension implements Extension | ||
{ | ||
public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void | ||
{ | ||
$facade->registerSubscribers( | ||
new SetupDateAdjustment(), | ||
new ReleaseDateAdjustment(), | ||
); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/PHPUnit/Extension/Subscriber/ReleaseDateAdjustment.php
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,40 @@ | ||
<?php /** @noinspection DevelopmentDependenciesUsageInspection */ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flying\Date\PHPUnit\Extension\Subscriber; | ||
|
||
use Flying\Date\Date; | ||
use PHPUnit\Event\Test\Errored; | ||
use PHPUnit\Event\Test\ErroredSubscriber; | ||
use PHPUnit\Event\Test\Failed; | ||
use PHPUnit\Event\Test\FailedSubscriber; | ||
use PHPUnit\Event\Test\MarkedIncomplete; | ||
use PHPUnit\Event\Test\MarkedIncompleteSubscriber; | ||
use PHPUnit\Event\Test\Passed; | ||
use PHPUnit\Event\Test\PassedSubscriber; | ||
use PHPUnit\Event\Test\PreparationFailed; | ||
use PHPUnit\Event\Test\PreparationFailedSubscriber; | ||
use PHPUnit\Event\Test\Skipped; | ||
use PHPUnit\Event\Test\SkippedSubscriber; | ||
|
||
class ReleaseDateAdjustment implements | ||
PassedSubscriber, | ||
MarkedIncompleteSubscriber, | ||
SkippedSubscriber, | ||
PreparationFailedSubscriber, | ||
FailedSubscriber, | ||
ErroredSubscriber | ||
{ | ||
public function notify(Passed|MarkedIncomplete|Skipped|PreparationFailed|Failed|Errored $event): void | ||
{ | ||
$this->release(); | ||
} | ||
|
||
private function release(): void | ||
{ | ||
Date::allowAdjustment(false); | ||
Date::setTimezone(); | ||
Date::adjust(); | ||
} | ||
} |
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 /** @noinspection DevelopmentDependenciesUsageInspection */ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flying\Date\PHPUnit\Extension\Subscriber; | ||
|
||
use Flying\Date\Date; | ||
use Flying\Date\PHPUnit\Attribute\AdjustableDate; | ||
use PHPUnit\Event\Code\TestMethod; | ||
use PHPUnit\Event\Test\Prepared; | ||
use PHPUnit\Event\Test\PreparedSubscriber; | ||
|
||
class SetupDateAdjustment implements PreparedSubscriber | ||
{ | ||
/** @var AdjustableDate[] */ | ||
private array $cache = []; | ||
|
||
/** | ||
* @throws \ReflectionException | ||
*/ | ||
public function notify(Prepared $event): void | ||
{ | ||
$test = $event->test(); | ||
if (!$test instanceof TestMethod) { | ||
return; | ||
} | ||
$reflection = null; | ||
$className = $test->className(); | ||
if (!array_key_exists($className, $this->cache)) { | ||
$reflection ??= new \ReflectionClass($className); | ||
$ar = $reflection->getAttributes(AdjustableDate::class)[0] ?? null; | ||
$this->cache[$className] = $ar?->newInstance(); | ||
} | ||
$method = $test->methodName(); | ||
$methodKey = $className . '::' . $method; | ||
if (!array_key_exists($methodKey, $this->cache)) { | ||
$reflection ??= new \ReflectionClass($className); | ||
$ar = null; | ||
if ($reflection->hasMethod($method)) { | ||
$ar = $reflection->getMethod($method)->getAttributes(AdjustableDate::class)[0] ?? null; | ||
} | ||
$this->cache[$methodKey] = $ar?->newInstance(); | ||
} | ||
Date::allowAdjustment($this->cache[$methodKey]?->isEnabled() ?? $this->cache[$className]?->isEnabled() ?? false); | ||
Date::setTimezone($this->cache[$methodKey]?->getTimezone() ?? $this->cache[$className]?->getTimezone() ?? null); | ||
Date::adjust(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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