Skip to content
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

Replacing the mocks in phpunit dataproviders with actual objects #7412

Merged
merged 5 commits into from
May 9, 2024

Conversation

mamazu
Copy link
Contributor

@mamazu mamazu commented May 7, 2024

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Fixed tickets fixes #7406
Related issues/PRs -
License MIT
Documentation PR -

What's in this PR?

Replacing the mock object with real objects in the dataproviders

Why?

For the phpunit 10 upgrade and mocking hides implementation problems.

@mamazu mamazu force-pushed the no_mocking_in_dataprovider branch 3 times, most recently from a22c0fd to a00fe76 Compare May 7, 2024 16:11
use PHPCR\NodeInterface;
use Sulu\Component\Content\Extension\AbstractExtension;

class TestExtension extends AbstractExtension
Copy link
Member

Choose a reason for hiding this comment

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

would not create a TestExtension class here instead use anonymous class inside the specific test case: e.g.:

private static function createTestExtension(): AbstractExtension
{
     return new class extends AbstractExtension() {
         // ..
     };
}

@alexander-schranz alexander-schranz added the DX Affecting the end developer label May 7, 2024
@alexander-schranz alexander-schranz changed the base branch from 2.6 to 2.5 May 7, 2024 16:48
@alexander-schranz
Copy link
Member

We should target the 2.5 to make backmerge of bugfixes easier.

@mamazu mamazu force-pushed the no_mocking_in_dataprovider branch 2 times, most recently from fc3949e to 19905d0 Compare May 7, 2024 17:54
@mamazu mamazu force-pushed the no_mocking_in_dataprovider branch from 19905d0 to 266f65e Compare May 7, 2024 18:00
@mamazu mamazu force-pushed the no_mocking_in_dataprovider branch from 8d23d10 to 7a5587f Compare May 7, 2024 23:48
@mamazu mamazu force-pushed the no_mocking_in_dataprovider branch from 7a5587f to 1741ea8 Compare May 8, 2024 00:13
Comment on lines 244 to 253
self::setPrivateProperty($entity, 'id', $id);
self::setPrivateProperty($entity, 'number', $id);
self::setPrivateProperty($entity, 'name', $name);
self::setPrivateProperty($entity, 'tags', new ArrayCollection($tags));
self::setPrivateProperty($entity, 'placeOfJurisdiction', '');
self::setPrivateProperty($entity, 'uid', '');
self::setPrivateProperty($entity, 'corporation', '');
self::setPrivateProperty($entity, 'created', new \DateTime());
self::setPrivateProperty($entity, 'changed', new \DateTime());
self::setPrivateProperty($entity, 'medias', new ArrayCollection([]));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is highly in efficient because we are reflecting on this class with every method call. But it's just the tests.

Copy link
Member

Choose a reason for hiding this comment

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

@mamazu for properties providing a setter I would directly call the setter method and not go over reflection. So in our case the reflection mostly only used for the primary keys.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. The only place I have also left with the function is the cache in the MediaDataProvider.

@mamazu mamazu force-pushed the no_mocking_in_dataprovider branch from af9ad1d to 421d4f9 Compare May 8, 2024 10:06
@alexander-schranz alexander-schranz merged commit df87d1c into sulu:2.5 May 9, 2024
8 checks passed
@alexander-schranz
Copy link
Member

@mamazu Thank you!

@mamazu mamazu deleted the no_mocking_in_dataprovider branch May 9, 2024 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Affecting the end developer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert existing PHPUnit DataProvider to not longer use mocks
2 participants