-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial work on expecting E_USER_DEPRECATED issues
- Loading branch information
1 parent
d6affa8
commit 029aa2b
Showing
9 changed files
with
379 additions
and
0 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
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,56 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\Runner\DeprecationCollector; | ||
|
||
use PHPUnit\Event\EventFacadeIsSealedException; | ||
use PHPUnit\Event\Facade; | ||
use PHPUnit\Event\Test\DeprecationTriggered; | ||
use PHPUnit\Event\UnknownSubscriberTypeException; | ||
|
||
/** | ||
* @internal This class is not covered by the backward compatibility promise for PHPUnit | ||
*/ | ||
final class Collector | ||
{ | ||
/** | ||
* @psalm-var list<non-empty-string> | ||
*/ | ||
private array $deprecations = []; | ||
|
||
/** | ||
* @throws EventFacadeIsSealedException | ||
* @throws UnknownSubscriberTypeException | ||
*/ | ||
public function __construct(Facade $facade) | ||
{ | ||
$facade->registerSubscribers( | ||
new TestPreparedSubscriber($this), | ||
new TestTriggeredDeprecationSubscriber($this), | ||
); | ||
} | ||
|
||
/** | ||
* @psalm-return list<non-empty-string> | ||
*/ | ||
public function deprecations(): array | ||
{ | ||
return $this->deprecations; | ||
} | ||
|
||
public function testPrepared(): void | ||
{ | ||
$this->deprecations = []; | ||
} | ||
|
||
public function testTriggeredDeprecation(DeprecationTriggered $event): void | ||
{ | ||
$this->deprecations[] = $event->message(); | ||
} | ||
} |
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,55 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\Runner\DeprecationCollector; | ||
|
||
use PHPUnit\Event\EventFacadeIsSealedException; | ||
use PHPUnit\Event\Facade as EventFacade; | ||
use PHPUnit\Event\UnknownSubscriberTypeException; | ||
|
||
/** | ||
* @internal This class is not covered by the backward compatibility promise for PHPUnit | ||
*/ | ||
final class Facade | ||
{ | ||
private static ?Collector $collector = null; | ||
|
||
/** | ||
* @throws EventFacadeIsSealedException | ||
* @throws UnknownSubscriberTypeException | ||
*/ | ||
public static function init(): void | ||
{ | ||
self::collector(); | ||
} | ||
|
||
/** | ||
* @psalm-return list<non-empty-string> | ||
* | ||
* @throws EventFacadeIsSealedException | ||
* @throws UnknownSubscriberTypeException | ||
*/ | ||
public static function deprecations(): array | ||
{ | ||
return self::collector()->deprecations(); | ||
} | ||
|
||
/** | ||
* @throws EventFacadeIsSealedException | ||
* @throws UnknownSubscriberTypeException | ||
*/ | ||
private static function collector(): Collector | ||
{ | ||
if (self::$collector === null) { | ||
self::$collector = new Collector(EventFacade::instance()); | ||
} | ||
|
||
return self::$collector; | ||
} | ||
} |
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,28 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\Runner\DeprecationCollector; | ||
|
||
/** | ||
* @internal This class is not covered by the backward compatibility promise for PHPUnit | ||
*/ | ||
abstract class Subscriber | ||
{ | ||
private readonly Collector $collector; | ||
|
||
public function __construct(Collector $collector) | ||
{ | ||
$this->collector = $collector; | ||
} | ||
|
||
protected function collector(): Collector | ||
{ | ||
return $this->collector; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Runner/DeprecationCollector/Subscriber/TestPreparedSubscriber.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,24 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\Runner\DeprecationCollector; | ||
|
||
use PHPUnit\Event\Test\Prepared; | ||
use PHPUnit\Event\Test\PreparedSubscriber; | ||
|
||
/** | ||
* @internal This class is not covered by the backward compatibility promise for PHPUnit | ||
*/ | ||
final class TestPreparedSubscriber extends Subscriber implements PreparedSubscriber | ||
{ | ||
public function notify(Prepared $event): void | ||
{ | ||
$this->collector()->testPrepared(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Runner/DeprecationCollector/Subscriber/TestTriggeredDeprecationSubscriber.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,24 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\Runner\DeprecationCollector; | ||
|
||
use PHPUnit\Event\Test\DeprecationTriggered; | ||
use PHPUnit\Event\Test\DeprecationTriggeredSubscriber; | ||
|
||
/** | ||
* @internal This class is not covered by the backward compatibility promise for PHPUnit | ||
*/ | ||
final class TestTriggeredDeprecationSubscriber extends Subscriber implements DeprecationTriggeredSubscriber | ||
{ | ||
public function notify(DeprecationTriggered $event): void | ||
{ | ||
$this->collector()->testTriggeredDeprecation($event); | ||
} | ||
} |
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
50 changes: 50 additions & 0 deletions
50
tests/end-to-end/event/_files/TestForDeprecatedFeatureTest.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,50 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\TestFixture\Event; | ||
|
||
use const E_USER_DEPRECATED; | ||
use function trigger_error; | ||
use PHPUnit\Framework\Attributes\IgnoreDeprecations; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class TestForDeprecatedFeatureTest extends TestCase | ||
{ | ||
#[IgnoreDeprecations] | ||
public function testOne(): void | ||
{ | ||
$this->expectUserDeprecationMessage('message'); | ||
|
||
@trigger_error('message', E_USER_DEPRECATED); | ||
} | ||
|
||
#[IgnoreDeprecations] | ||
public function testTwo(): void | ||
{ | ||
$this->expectUserDeprecationMessage('message'); | ||
|
||
@trigger_error('something else', E_USER_DEPRECATED); | ||
} | ||
|
||
#[IgnoreDeprecations] | ||
public function testThree(): void | ||
{ | ||
$this->expectUserDeprecationMessageMatches('/message/'); | ||
|
||
@trigger_error('...message...', E_USER_DEPRECATED); | ||
} | ||
|
||
#[IgnoreDeprecations] | ||
public function testFour(): void | ||
{ | ||
$this->expectUserDeprecationMessage('message'); | ||
|
||
@trigger_error('something else', E_USER_DEPRECATED); | ||
} | ||
} |
Oops, something went wrong.