Skip to content

Commit c054288

Browse files
committed
feat: add JoliNotif and BypassFinals integration for PHPUnit notifications; update installation instructions
Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
1 parent ab13b34 commit c054288

13 files changed

Lines changed: 721 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A Composer plugin and console toolkit designed to unify and standardize developm
1313
## 🚀 Installation
1414

1515
```bash
16-
composer require --dev fast-forward/dev-tools
16+
composer require --dev fast-forward/dev-tools:dev-main
1717
```
1818

1919
## 🛠️ Usage

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727
"php": "^8.3",
2828
"composer-plugin-api": "^2.0",
2929
"composer/composer": "^2.9",
30+
"dg/bypass-finals": "^1.9",
3031
"ergebnis/composer-normalize": "^2.50",
3132
"ergebnis/rector-rules": "^1.14",
3233
"esi/phpunit-coverage-check": "^3.0",
3334
"fakerphp/faker": "^1.24",
3435
"fast-forward/phpdoc-bootstrap-template": "^1.0",
3536
"friendsofphp/php-cs-fixer": "^3.94",
37+
"jolicode/jolinotif": "^3.3",
3638
"phpdocumentor/shim": "^3.9",
3739
"phpowermove/docblock": "^4.0",
3840
"phpro/grumphp": "^2.19",

docs/getting-started/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Require the package as a development dependency using Composer:
1515

1616
.. code-block:: bash
1717
18-
composer require --dev fast-forward/dev-tools
18+
composer require --dev fast-forward/dev-tools:dev-main
1919
2020
What happens during installation?
2121
---------------------------------

phpunit.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@
88
displayDetailsOnPhpunitDeprecations="true"
99
failOnPhpunitDeprecation="true"
1010
failOnRisky="true"
11-
failOnWarning="true"/>
11+
failOnWarning="true">
12+
<extensions>
13+
<bootstrap class="FastForward\DevTools\PhpUnit\Runner\Extension\DevToolsExtension" />
14+
</extensions>
15+
</phpunit>

resources/phpunit.avif

7.07 KB
Binary file not shown.

src/PhpUnit/Event/EventTracer.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of fast-forward/dev-tools.
7+
*
8+
* This source file is subject to the license bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @copyright Copyright (c) 2026 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
12+
* @license https://opensource.org/licenses/MIT MIT License
13+
*
14+
* @see https://github.com/php-fast-forward/dev-tools
15+
* @see https://github.com/php-fast-forward
16+
* @see https://datatracker.ietf.org/doc/html/rfc2119
17+
*/
18+
19+
namespace FastForward\DevTools\PhpUnit\Event;
20+
21+
use PHPUnit\Event\Event;
22+
use PHPUnit\Event\Tracer\Tracer;
23+
24+
/**
25+
* Collects PHPUnit events grouped by their concrete event class.
26+
*
27+
* This tracer MUST store every received event instance under its fully
28+
* qualified class name so tests MAY later inspect which events were emitted
29+
* and how many times each event type occurred during execution.
30+
*
31+
* The collected events SHALL remain available in memory for the lifetime of
32+
* this tracer instance. Consumers SHOULD treat the stored event collection as
33+
* test-support state and SHOULD NOT rely on it for production behavior.
34+
*
35+
* @codeCoverageIgnore
36+
*/
37+
class EventTracer implements Tracer
38+
{
39+
/**
40+
* Stores traced events grouped by their concrete event class name.
41+
*
42+
* Each key MUST be a fully qualified event class name and each value MUST
43+
* contain the list of event instances received for that class.
44+
*
45+
* @var array<class-string<Event>, list<Event>>
46+
*/
47+
private array $events = [];
48+
49+
/**
50+
* Records a PHPUnit event in the internal event registry.
51+
*
52+
* This method MUST group the event by its concrete runtime class and SHALL
53+
* append the received instance to the corresponding event list without
54+
* discarding previously traced events of the same type.
55+
*
56+
* @param Event $event the PHPUnit event instance to record
57+
*
58+
* @return void
59+
*/
60+
public function trace(Event $event): void
61+
{
62+
if (! \array_key_exists($event::class, $this->events)) {
63+
$this->events[$event::class] = [];
64+
}
65+
66+
$this->events[$event::class][] = $event;
67+
}
68+
69+
/**
70+
* Returns the number of traced events for the given event class.
71+
*
72+
* This method MUST return the exact number of stored events matching the
73+
* provided fully qualified event class name. When no events were recorded
74+
* for the given class, the method SHALL return 0.
75+
*
76+
* @param class-string<Event> $eventClass the fully qualified PHPUnit event
77+
* class name to count
78+
*
79+
* @return int the number of recorded events for the specified class
80+
*/
81+
public function count(string $eventClass): int
82+
{
83+
return \array_key_exists($eventClass, $this->events)
84+
? \count($this->events[$eventClass])
85+
: 0;
86+
}
87+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of fast-forward/dev-tools.
7+
*
8+
* This source file is subject to the license bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @copyright Copyright (c) 2026 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
12+
* @license https://opensource.org/licenses/MIT MIT License
13+
*
14+
* @see https://github.com/php-fast-forward/dev-tools
15+
* @see https://github.com/php-fast-forward
16+
* @see https://datatracker.ietf.org/doc/html/rfc2119
17+
*/
18+
19+
namespace FastForward\DevTools\PhpUnit\Event\TestSuite;
20+
21+
use DG\BypassFinals;
22+
use PHPUnit\Event\TestSuite\Started;
23+
use PHPUnit\Event\TestSuite\StartedSubscriber;
24+
25+
/**
26+
* Enables BypassFinals when the PHPUnit test suite starts.
27+
*
28+
* This subscriber MUST activate BypassFinals as soon as the test suite start
29+
* event is emitted so that final classes, final methods, and readonly
30+
* protections can be bypassed where the test environment requires that
31+
* behavior.
32+
*
33+
* This subscriber SHALL perform only the activation side effect associated
34+
* with the test suite start event.
35+
*/
36+
final class ByPassfinalsStartedSubscriber implements StartedSubscriber
37+
{
38+
/**
39+
* Handles the PHPUnit test suite started event.
40+
*
41+
* This method MUST enable BypassFinals for the current test execution
42+
* context when the test suite starts.
43+
*
44+
* @param Started $event the emitted test suite started event
45+
*
46+
* @return void
47+
*/
48+
public function notify(Started $event): void
49+
{
50+
BypassFinals::enable();
51+
}
52+
}

0 commit comments

Comments
 (0)