Skip to content

Configurize default fixtureStrategy. #18328

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 3 commits into from
Apr 23, 2025
Merged

Configurize default fixtureStrategy. #18328

merged 3 commits into from
Apr 23, 2025

Conversation

dereuromark
Copy link
Member

Docs mention that you can create base classes
https://book.cakephp.org/4/en/development/testing.html#fixture-state-managers

But since those are usually spread across different types and namespaces, this can become cumbersome.
Would it be acceptable to find some kind of default config opt-in?

If not set, nothing would change, so sounds fully BC.

@dereuromark dereuromark added this to the 5.2.2 milestone Apr 14, 2025
@othercorey
Copy link
Member

Is it really possible to use the transaction strategy as default? It has very limited use cases, right?

@dereuromark
Copy link
Member Author

That's up to the project I guess.
This just allows an easier way to set the default than having to change hundreds of test case classes

@dereuromark dereuromark requested a review from markstory April 16, 2025 10:44
@LordSimal
Copy link
Contributor

It has very limited use cases, right?

As the docs say

By using TransactionStrategy each test method will be run inside a transaction that is rolled back at the end of the test. This can yield improved performance but requires your tests not heavily rely on static fixture data, as auto-increment values are not reset before each test.

What other limitations are you referring to?

@dereuromark
Copy link
Member Author

@markstory That would be super helpful to quickly change the strategy per app without having to change hundreds or even more files to different base class in between.

@markstory
Copy link
Member

When would you use this? Do you have a plugin or application that can run all of its tests with TransactionStrategy?

@dereuromark
Copy link
Member Author

dereuromark commented Apr 18, 2025

Yeah, any application itself as well.
Any application that already has 100+ tests would be nightmare to have to add a middleman test class that would extend and modify this protected method.
Having a global config here switches it out without the need for massive refactoring.

The default one as given right now is sure not helpful beyond a few tests, as it becomes a pain to work with, everywhere relicts after test runs breaking the next tests.

@markstory markstory modified the milestones: 5.2.2, 5.2.3 Apr 18, 2025
@dereuromark
Copy link
Member Author

dereuromark commented Apr 22, 2025

@markstory can we ship this with tonights release maybe?

Docs update in cakephp/docs#8025

@markstory markstory merged commit 5816610 into 5.x Apr 23, 2025
12 of 13 checks passed
@markstory markstory deleted the 5.x-test-fixture-strategy branch April 23, 2025 13:53
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