-
Notifications
You must be signed in to change notification settings - Fork 21
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
makeWithModelListenersAndBehaviors should be a transient state change, not permanent #23
Comments
@Zuluru, I was under the impression that the overall process of testing in phpUnit would clear the slate between tests so I checked this with one of my tests that use this call to prove your concerns were unfounded. To my surprise, the flag to enable listeners and behaviors did persist in later tests methods once it was enabled. That was a bit of a surprise! |
There are some other save and marshaling options that can be set. I wonder if those also persist. Is this something that the FixtureFactory listener could simply reset to a default state at the same time the previous test data is cleared? |
My experience has been that anything global remains from one test to the next. Static properties are an example. Also defined constants. |
Thanks for the feedback. I agree that the handling of listeners and behaviors may be treated separatly. I will remove the heavy |
I don't mind |
Behaviors were disabled mostly because they generally work with Model Events, and our feeling was that Fixture Factories should insert data as fast and as blind as possible in the test DB. But this is actualy not necessary. Facit in the new versions v0.2.25 and v0.1.20:
|
I'm now finding that tests that are testing lifecycle events are failing. Need to be able to:
Not sure if I should report this here or as a new issue... |
What happens if you consider an ArticlesTable and do:
Does this work? |
That would probably work for some scenarios, but many check |
In that case, how about:
Does this work in your new scenario? The |
Yes, this is what I'm doing. But with the recent changes to disable events, step 4 sometimes doesn't happen, because the table has had all those events removed. If I run only the test in question, then it works fine; if I run the entire test suite, then something earlier in the run disables them and they don't get added back. Which is weird, because I thought that Cake makes a fresh table registry for each test. |
The package does not disable any events. If the method ::make is used, a different TableLocator, cloned on the regular TableLocator is used. But at no time the events of a TableRegistry get removed or added. The test here illustrates that what you suspect to happen through the package does not happen: https://github.com/pakacuda/cakephp-fixture-factories/blob/master/tests/TestCase/ORM/Locator/FactoryTableLocatorTest.php#L116 I do not know the context in which the issue occurs, but I would suggest isolating the case you are having and possibly propose a test case showing that the package would fail. |
makeWithModelListenersAndBehaviors
as currently implemented sets theapplyListenersAndBehaviors
property of the factory, and leaves it set. I have two concerns with this: one philosophical and one practical.The philosophical issue is that the function name does not reflect that it will be permanently changing the state. A name like
enableModelListenersAndBehaviorsAndMake
would be clearer about this. But secondly, modern design principles prefer that functions not have two effects; if you need to use "and" to describe what a function does, it should generally be split into two functions.The practical issue is that if I have
testA
andtestB
, wheretestA
callsmakeWithModelListenersAndBehaviors
buttestB
uses onlymake
, then the behaviour oftestB
will depend on whethertestA
was run before it or not, because it's not just the concrete factory object that's affected by this, but a static property thatmake
references.The text was updated successfully, but these errors were encountered: