Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: symfony/phpunit-bridge
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.4.33
Choose a base ref
...
head repository: symfony/phpunit-bridge
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7.2
Choose a head ref
Loading
Showing with 1,581 additions and 509 deletions.
  1. +1 −2 .gitattributes
  2. +8 −0 .github/PULL_REQUEST_TEMPLATE.md
  3. +20 −0 .github/workflows/close-pull-request.yml
  4. +33 −0 CHANGELOG.md
  5. +27 −7 ClassExistsMock.php
  6. +32 −8 ClockMock.php
  7. +1 −1 ConstraintTrait.php
  8. +1 −1 CoverageListener.php
  9. +49 −36 DeprecationErrorHandler.php
  10. +69 −69 DeprecationErrorHandler/Configuration.php
  11. +32 −74 DeprecationErrorHandler/Deprecation.php
  12. +5 −18 DeprecationErrorHandler/DeprecationGroup.php
  13. +2 −2 DeprecationErrorHandler/DeprecationNotice.php
  14. +4 −4 DnsMock.php
  15. +30 −0 ExpectUserDeprecationMessageTrait.php
  16. +39 −0 Extension/EnableClockMockSubscriber.php
  17. +39 −0 Extension/RegisterClockMockSubscriber.php
  18. +39 −0 Extension/RegisterDnsMockSubscriber.php
  19. +0 −5 Legacy/CommandForV7.php
  20. +0 −5 Legacy/CommandForV9.php
  21. +1 −3 Legacy/ExpectDeprecationTraitBeforeV8_4.php
  22. +0 −70 Legacy/SetUpTearDownTraitForV7.php
  23. +0 −58 Legacy/SetUpTearDownTraitForV8.php
  24. +22 −23 Legacy/SymfonyTestsListenerTrait.php
  25. +0 −30 SetUpTearDownTrait.php
  26. +103 −0 SymfonyExtension.php
  27. +46 −0 Tests/ClassExistsMockTest.php
  28. +10 −0 Tests/ClockMockTest.php
  29. +31 −16 Tests/CoverageListenerTest.php
  30. +61 −2 Tests/DeprecationErrorHandler/ConfigurationTest.php
  31. +1 −1 Tests/DeprecationErrorHandler/DeprecationTest.php
  32. +80 −0 Tests/DeprecationErrorHandler/ignore.phpt
  33. +3 −1 Tests/DeprecationErrorHandler/log_file.phpt
  34. +82 −0 Tests/EnumExistsMockTest.php
  35. +3 −0 Tests/ExpectDeprecationTraitTest.php
  36. +3 −0 Tests/ExpectedDeprecationAnnotationTest.php
  37. +2 −0 Tests/FailTests/ExpectDeprecationTraitTestFail.php
  38. +2 −0 Tests/FailTests/NoAssertionsTestNotRisky.php
  39. +2 −0 Tests/FailTests/NoAssertionsTestRisky.php
  40. +16 −0 Tests/Fixtures/ExistingEnum.php
  41. +16 −0 Tests/Fixtures/ExistingEnumReal.php
  42. +12 −16 Tests/Fixtures/coverage/phpunit-with-listener.xml.dist
  43. +11 −14 Tests/Fixtures/coverage/phpunit-without-listener.xml.dist
  44. +29 −0 Tests/Fixtures/symfonyextension/phpunit-with-extension.xml.dist
  45. +22 −0 Tests/Fixtures/symfonyextension/phpunit-without-extension.xml.dist
  46. +16 −0 Tests/Fixtures/symfonyextension/src/ClassExtendingFinalClass.php
  47. +19 −0 Tests/Fixtures/symfonyextension/src/FinalClass.php
  48. +32 −0 Tests/Fixtures/symfonyextension/tests/bootstrap.php
  49. +2 −0 Tests/ProcessIsolationTest.php
  50. +140 −0 Tests/SymfonyExtension.php
  51. +2 −0 Tests/expectdeprecationfail.phpt
  52. +3 −1 Tests/expectnotrisky.phpt
  53. +3 −1 Tests/expectrisky.phpt
  54. +19 −0 Tests/symfonyextension.phpt
  55. +296 −0 Tests/symfonyextensionnotregistered.phpt
  56. +30 −21 bin/simple-phpunit.php
  57. +14 −3 bootstrap.php
  58. +7 −8 composer.json
  59. +9 −9 phpunit.xml.dist
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/Tests export-ignore
/phpunit.xml.dist export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.git* export-ignore
8 changes: 8 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Please do not submit any Pull Requests here. They will be closed.
---

Please submit your PR here instead:
https://github.com/symfony/symfony

This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
20 changes: 20 additions & 0 deletions .github/workflows/close-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Close Pull Request

on:
pull_request_target:
types: [opened]

jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: superbrothers/close-pull-request@v3
with:
comment: |
Thanks for your Pull Request! We love contributions.
However, you should instead open your PR on the main repository:
https://github.com/symfony/symfony
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
CHANGELOG
=========

7.2
---

* Add a PHPUnit extension that registers the clock mock and DNS mock and the `DebugClassLoader` from the ErrorHandler component if present
* Add `ExpectUserDeprecationMessageTrait` with a polyfill of PHPUnit's `expectUserDeprecationMessage()`
* Use `total` for asserting deprecation count when a group is not defined

6.4
---

* Allow setting the locale using `SYMFONY_PHPUNIT_LOCALE` env var

6.3
---

* Add support for mocking the `enum_exists` function
* Enable reporting of deprecations triggered by Doctrine by default

6.2
---

* Add support for mocking the `hrtime()` function

6.1
---

* Add option `ignoreFile` to configure a file that lists deprecation messages to ignore

6.0
---

* Remove `SetUpTearDownTrait`

5.3
---

34 changes: 27 additions & 7 deletions ClassExistsMock.php
Original file line number Diff line number Diff line change
@@ -18,38 +18,58 @@ class ClassExistsMock
{
private static $classes = [];

private static $enums = [];

/**
* Configures the classes to be checked upon existence.
*
* @param array $classes Mocked class names as keys (case sensitive, without leading root namespace slash) and booleans as values
* @param array $classes Mocked class names as keys (case-sensitive, without leading root namespace slash) and booleans as values
*/
public static function withMockedClasses(array $classes)
public static function withMockedClasses(array $classes): void
{
self::$classes = $classes;
}

public static function class_exists($name, $autoload = true)
/**
* Configures the enums to be checked upon existence.
*
* @param array $enums Mocked enums names as keys (case-sensitive, without leading root namespace slash) and booleans as values
*/
public static function withMockedEnums(array $enums): void
{
self::$enums = $enums;
self::$classes += $enums;
}

public static function class_exists($name, $autoload = true): bool
{
$name = ltrim($name, '\\');

return isset(self::$classes[$name]) ? (bool) self::$classes[$name] : \class_exists($name, $autoload);
}

public static function interface_exists($name, $autoload = true)
public static function interface_exists($name, $autoload = true): bool
{
$name = ltrim($name, '\\');

return isset(self::$classes[$name]) ? (bool) self::$classes[$name] : \interface_exists($name, $autoload);
}

public static function trait_exists($name, $autoload = true)
public static function trait_exists($name, $autoload = true): bool
{
$name = ltrim($name, '\\');

return isset(self::$classes[$name]) ? (bool) self::$classes[$name] : \trait_exists($name, $autoload);
}

public static function register($class)
public static function enum_exists($name, $autoload = true):bool
{
$name = ltrim($name, '\\');

return isset(self::$enums[$name]) ? (bool) self::$enums[$name] : \enum_exists($name, $autoload);
}

public static function register($class): void
{
$self = static::class;

@@ -61,7 +81,7 @@ public static function register($class)
$mockedNs[] = substr($class, 6, strrpos($class, '\\') - 6);
}
foreach ($mockedNs as $ns) {
foreach (['class', 'interface', 'trait'] as $type) {
foreach (['class', 'interface', 'trait', 'enum'] as $type) {
if (\function_exists($ns.'\\'.$type.'_exists')) {
continue;
}
40 changes: 32 additions & 8 deletions ClockMock.php
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ class ClockMock
{
private static $now;

public static function withClockMock($enable = null)
public static function withClockMock($enable = null): ?bool
{
if (null === $enable) {
return null !== self::$now;
@@ -30,7 +30,7 @@ public static function withClockMock($enable = null)
return null;
}

public static function time()
public static function time(): int
{
if (null === self::$now) {
return \time();
@@ -39,7 +39,7 @@ public static function time()
return (int) self::$now;
}

public static function sleep($s)
public static function sleep($s): int
{
if (null === self::$now) {
return \sleep($s);
@@ -50,7 +50,7 @@ public static function sleep($s)
return 0;
}

public static function usleep($us)
public static function usleep($us): void
{
if (null === self::$now) {
\usleep($us);
@@ -59,6 +59,9 @@ public static function usleep($us)
}
}

/**
* @return string|float
*/
public static function microtime($asFloat = false)
{
if (null === self::$now) {
@@ -69,10 +72,10 @@ public static function microtime($asFloat = false)
return self::$now;
}

return sprintf('%0.6f00 %d', self::$now - (int) self::$now, (int) self::$now);
return \sprintf('%0.6f00 %d', self::$now - (int) self::$now, (int) self::$now);
}

public static function date($format, $timestamp = null)
public static function date($format, $timestamp = null): string
{
if (null === $timestamp) {
$timestamp = self::time();
@@ -81,7 +84,7 @@ public static function date($format, $timestamp = null)
return \date($format, $timestamp);
}

public static function gmdate($format, $timestamp = null)
public static function gmdate($format, $timestamp = null): string
{
if (null === $timestamp) {
$timestamp = self::time();
@@ -90,7 +93,23 @@ public static function gmdate($format, $timestamp = null)
return \gmdate($format, $timestamp);
}

public static function register($class)
/**
* @return array|int|float
*/
public static function hrtime($asNumber = false)
{
$ns = (self::$now - (int) self::$now) * 1000000000;

if ($asNumber) {
$number = \sprintf('%d%d', (int) self::$now, $ns);

return \PHP_INT_SIZE === 8 ? (int) $number : (float) $number;
}

return [(int) self::$now, (int) $ns];
}

public static function register($class): void
{
$self = static::class;

@@ -137,6 +156,11 @@ function gmdate(\$format, \$timestamp = null)
{
return \\$self::gmdate(\$format, \$timestamp);
}
function hrtime(\$asNumber = false)
{
return \\$self::hrtime(\$asNumber);
}
EOPHP
);
}
2 changes: 1 addition & 1 deletion ConstraintTrait.php
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ trait ConstraintTrait
{
use Legacy\ConstraintTraitForV7;
}
} elseif (\PHP_VERSION_ID < 70100 || !$r->getMethod('evaluate')->hasReturnType()) {
} elseif (!$r->getMethod('evaluate')->hasReturnType()) {
trait ConstraintTrait
{
use Legacy\ConstraintTraitForV8;
2 changes: 1 addition & 1 deletion CoverageListener.php
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ class CoverageListener implements TestListener
private $sutFqcnResolver;
private $warningOnSutNotFound;

public function __construct(callable $sutFqcnResolver = null, bool $warningOnSutNotFound = false)
public function __construct(?callable $sutFqcnResolver = null, bool $warningOnSutNotFound = false)
{
$this->sutFqcnResolver = $sutFqcnResolver ?? static function (Test $test): ?string {
$class = \get_class($test);
Loading