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

Static data providers required in PHPUnit 10 #7117

Open
leofeyer opened this issue Apr 15, 2024 · 3 comments
Open

Static data providers required in PHPUnit 10 #7117

leofeyer opened this issue Apr 15, 2024 · 3 comments
Labels
up for discussion Issues and PRs which will be discussed in our monthly Mumble calls.

Comments

@leofeyer
Copy link
Member

Description

PHPUnit 10 requires all data providers to be static, however, we have about 40 that use $this->createMock() or $this->mockClassWithProperties(). For example:

$page1 = $this->mockClassWithProperties(PageModel::class, except: ['getTable']);
$page1->id = 5;
$page2 = $this->mockClassWithProperties(PageModel::class, except: ['getTable']);
$page2->id = 6;
$modelCollection = new Collection([$page1, $page2], 'tl_page');
yield 'specific tag for entity instance' => [
$post,
['contao.db.tl_blog_post.5'],
];
yield 'specific tag for model instance' => [
$page1,
['contao.db.tl_page.5'],
];
yield 'mixed' => [
[$post, $post->getAuthor(), $post->getComments(), $post->getTags(), $modelCollection, ArticleModel::class, 'foo'],
[

I have no idea how to fix this without encapsulating the code in a separate test method. We could of course replace every $this->createMock() with (new class() extends TestCase {})->createMock() in the static methods, but then these doubled types would no longer be tracked in the original test case object.

@leofeyer leofeyer added the up for discussion Issues and PRs which will be discussed in our monthly Mumble calls. label Apr 15, 2024
@ausi
Copy link
Member

ausi commented Apr 15, 2024

We could probably use (new MockGenerator)->testDouble(…) directly?

but then these doubled types would no longer be tracked in the original test case object.

Do they need to be tracked? If they don’t have any assertions that should not be needed I think.

@leofeyer
Copy link
Member Author

I don‘t know. The createMock() method calls $this->registerMockObject() which adds the object to the TestCase::$mockObjects property.

@aschempp
Copy link
Member

I think it would be better to pass the mock object data from the generator method to the test method, and create the mock in there. or simply fix it like #7150

leofeyer pushed a commit that referenced this issue May 10, 2024
Description
-----------

see #7117

Commits
-------

d00665c Make EntityCacheTagsTest compatible with PHPUnit 10
leofeyer pushed a commit to contao/core-bundle that referenced this issue May 10, 2024
Description
-----------

see contao/contao#7117

Commits
-------

d00665c0 Make EntityCacheTagsTest compatible with PHPUnit 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
up for discussion Issues and PRs which will be discussed in our monthly Mumble calls.
Projects
None yet
Development

No branches or pull requests

3 participants