Skip to content

[PhpUnitBridge] Enable configuring mock namespaces with attributes #59384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2025

Conversation

HypeMC
Copy link
Contributor

@HypeMC HypeMC commented Jan 7, 2025

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Issues -
License MIT

This PR adds the ability to configure clock and DNS mock namespaces through attributes, removing the need to add them to phpunit.xml:

#[DnsSensitive(Foo::class)]
class FooTest extends KernelTestCase
{
    #[TimeSensitive(Bar::class)]
    public function testFoo()
    {
        // ...
    }
}

run: find ./src/Symfony/Bridge/PhpUnit -name '*.php' | grep -v -e /Tests/ -e ForV7 -e ForV8 -e ForV9 -e ConstraintLogicTrait | parallel -j 4 php -l {}
run: find ./src/Symfony/Bridge/PhpUnit -name '*.php' | grep -v -e /Tests/ -e /Attribute/ -e /Extension/ -e /Metadata/ -e ForV7 -e ForV8 -e ForV9 -e ConstraintLogicTrait | parallel -j 4 php -l {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PhpUnit 10+ is PHP >=8.1, so it should be ok for the extension classes to use PHP >=8 syntax.

@@ -33,7 +40,12 @@ public function notify(Finished $event): void
foreach ($test->metadata() as $metadata) {
if ($metadata instanceof Group && 'time-sensitive' === $metadata->groupName()) {
ClockMock::withClockMock(false);
break;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor optimization

@HypeMC HypeMC force-pushed the phpunit-bridge-attributes branch 2 times, most recently from 3199197 to 54c59f7 Compare January 7, 2025 08:33
@HypeMC HypeMC force-pushed the phpunit-bridge-attributes branch from 54c59f7 to 42cc6d2 Compare January 7, 2025 08:53
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (after composer.json change is reverted)

@HypeMC HypeMC force-pushed the phpunit-bridge-attributes branch from 42cc6d2 to 130cc26 Compare January 7, 2025 09:45
@nicolas-grekas
Copy link
Member

Thank you @HypeMC.

@nicolas-grekas nicolas-grekas merged commit 4c071c2 into symfony:7.3 Jan 7, 2025
6 of 12 checks passed
@HypeMC HypeMC deleted the phpunit-bridge-attributes branch January 7, 2025 11:15
chalasr added a commit that referenced this pull request Jan 11, 2025
This PR was merged into the 7.3 branch.

Discussion
----------

[PhpUnitBridge] Mark `AttributeReader` as internal

| Q             | A
| ------------- | ---
| Branch?       | 7.3
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Follow-up to #59384

Didn't notice this in my original PR, but it'd make sense for the `AttributeReader` class to be marked as internal.

Commits
-------

ba073c2 [PhpUnitBridge] Mark `AttributeReader` as internal
@fabpot fabpot mentioned this pull request May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants