generated from rich-id/bundle-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matthias Devlamynck
committed
Dec 31, 2024
1 parent
8393d4b
commit e4c5871
Showing
12 changed files
with
411 additions
and
1,039 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,4 +1,3 @@ | ||
version: '3.7' | ||
services: | ||
application: | ||
user: '1001:116' |
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 |
---|---|---|
|
@@ -2,161 +2,23 @@ | |
|
||
namespace RichCongress\TestFramework; | ||
|
||
use PHPUnit\Runner\AfterIncompleteTestHook; | ||
use PHPUnit\Runner\AfterRiskyTestHook; | ||
use PHPUnit\Runner\AfterSkippedTestHook; | ||
use PHPUnit\Runner\AfterSuccessfulTestHook; | ||
use PHPUnit\Runner\AfterTestErrorHook; | ||
use PHPUnit\Runner\AfterTestFailureHook; | ||
use PHPUnit\Runner\AfterTestHook; | ||
use PHPUnit\Runner\AfterTestWarningHook; | ||
use PHPUnit\Runner\BeforeFirstTestHook; | ||
use PHPUnit\Runner\AfterLastTestHook; | ||
use PHPUnit\Runner\BeforeTestHook; | ||
use RichCongress\TestFramework\TestHook\TestConfigurationHook; | ||
use RichCongress\TestFramework\TestHook\TestHookInterface; | ||
|
||
/** | ||
* Class PHPUnitExtension | ||
* | ||
* @package RichCongress\TestFramework | ||
* @author Nicolas Guilloux <[email protected]> | ||
* @copyright 2014 - 2020 RichCongress (https://www.richcongress.com) | ||
*/ | ||
class PHPUnitExtension implements | ||
AfterIncompleteTestHook, | ||
AfterLastTestHook, | ||
AfterRiskyTestHook, | ||
AfterSkippedTestHook, | ||
AfterSuccessfulTestHook, | ||
AfterTestErrorHook, | ||
AfterTestFailureHook, | ||
AfterTestHook, | ||
AfterTestWarningHook, | ||
BeforeFirstTestHook, | ||
BeforeTestHook | ||
use PHPUnit\Event\Test\PreparationStarted; | ||
use PHPUnit\Event\Test\PreparationStartedSubscriber; | ||
use PHPUnit\Runner\Extension\Extension; | ||
use PHPUnit\Runner\Extension\Facade; | ||
use PHPUnit\Runner\Extension\ParameterCollection; | ||
use PHPUnit\TextUI\Configuration\Configuration; | ||
use RichCongress\TestFramework\TestConfiguration\TestConfiguration; | ||
|
||
class PHPUnitExtension implements Extension | ||
{ | ||
/** @var array|string[] */ | ||
public static $supportedHooks = [ | ||
TestConfigurationHook::class | ||
]; | ||
|
||
/** @var array */ | ||
protected $hooks = [ | ||
'executeAfterIncompleteTest' => [], | ||
'executeAfterLastTest' => [], | ||
'executeAfterRiskyTest' => [], | ||
'executeAfterSkippedTest' => [], | ||
'executeAfterSuccessfulTest' => [], | ||
'executeAfterTest' => [], | ||
'executeAfterTestError' => [], | ||
'executeAfterTestFailure' => [], | ||
'executeAfterTestWarning' => [], | ||
'executeBeforeFirstTest' => [], | ||
'executeBeforeTest' => [], | ||
]; | ||
|
||
/** | ||
* PHPUnitExtension constructor. | ||
* | ||
* @param string ...$hooksClass | ||
*/ | ||
public function __construct(string ...$hooksClass) | ||
public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void | ||
{ | ||
$supportedHooks = array_merge($hooksClass, static::$supportedHooks); | ||
|
||
foreach ($supportedHooks as $class) { | ||
/** @var TestHookInterface $hook */ | ||
$hook = new $class(); | ||
$priorities = $hook->getExecutionPriorities(); | ||
|
||
foreach (array_keys($this->hooks) as $method) { | ||
$this->hooks[$method][] = [ | ||
'hook' => $hook, | ||
'priority' => $priorities[$method] ?? 0, | ||
]; | ||
$facade->registerSubscriber(new class implements PreparationStartedSubscriber { | ||
public function notify(PreparationStarted $event): void | ||
{ | ||
TestConfiguration::registerTestConfig($event->test()); | ||
} | ||
} | ||
|
||
foreach ($this->hooks as $method => $hooksParams) { | ||
usort( | ||
$hooksParams, | ||
static function (array $a, array $b) { | ||
$aPriority = $a['priority'] ?? 0; | ||
$bPriority = $b['priority'] ?? 0; | ||
|
||
if ($aPriority === $bPriority) { | ||
return 0; | ||
} | ||
|
||
return ($aPriority < $bPriority) ? 1 : -1; | ||
} | ||
); | ||
|
||
$this->hooks[$method] = $hooksParams; | ||
} | ||
} | ||
|
||
public function executeAfterIncompleteTest(string $test, string $message, float $time): void | ||
{ | ||
$this->callHooks(__FUNCTION__, $test, $message, $time); | ||
} | ||
|
||
public function executeAfterLastTest(): void | ||
{ | ||
$this->callHooks(__FUNCTION__); | ||
} | ||
|
||
public function executeAfterRiskyTest(string $test, string $message, float $time): void | ||
{ | ||
$this->callHooks(__FUNCTION__, $test, $message, $time); | ||
} | ||
|
||
public function executeAfterSkippedTest(string $test, string $message, float $time): void | ||
{ | ||
$this->callHooks(__FUNCTION__, $test, $message, $time); | ||
} | ||
|
||
public function executeAfterSuccessfulTest(string $test, float $time): void | ||
{ | ||
$this->callHooks(__FUNCTION__, $test, $time); | ||
} | ||
|
||
public function executeAfterTestError(string $test, string $message, float $time): void | ||
{ | ||
$this->callHooks(__FUNCTION__, $test, $message, $time); | ||
} | ||
|
||
public function executeAfterTestFailure(string $test, string $message, float $time): void | ||
{ | ||
$this->callHooks(__FUNCTION__, $test, $message, $time); | ||
} | ||
|
||
public function executeAfterTest(string $test, float $time): void | ||
{ | ||
$this->callHooks(__FUNCTION__, $test, $time); | ||
} | ||
|
||
public function executeAfterTestWarning(string $test, string $message, float $time): void | ||
{ | ||
$this->callHooks(__FUNCTION__, $test, $message, $time); | ||
} | ||
|
||
public function executeBeforeFirstTest(): void | ||
{ | ||
$this->callHooks(__FUNCTION__); | ||
} | ||
|
||
public function executeBeforeTest(string $test): void | ||
{ | ||
$this->callHooks(__FUNCTION__, $test); | ||
} | ||
|
||
public function callHooks(string $method, ...$arguments): void | ||
{ | ||
foreach ($this->hooks[$method] as $hookParams) { | ||
$callback = [$hookParams['hook'], $method]; | ||
\call_user_func_array($callback, $arguments); | ||
} | ||
}); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.