-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Tests\TestCase requests will show wasRecentlyCreated = true in models generated before the simulated request. #23270
Comments
Similar to #2110. Still seems like the framework should be able to handle this more appropriately, but looks like calling "fresh" before using the instance, should be enough. |
@devcircus you mean I think you tagged the wrong issue btw. |
Ahhh I did. The other issue said you could call $model->fresh(). Seems like refresh would do the same but haven't looked at the code. I'll track down the correct issue. |
Yup, that's the same issue I'm seeing. Shall I continue in that thread? |
I'd stay here since yours is still open. |
It's not a bug, but please feel free to submit a PR for this to v5.7. |
Description:
In the feature test
Tests\TestCase
, Eloquent models that were created during the mocking of a database will retain thewasRecentlyCreated
property when a request is issued to the same model using theTestCase::json()
method. In effect, not simulating an "update" to an existing database entry, but showing as just created in that request.Steps To Reproduce:
In a feature
TestCase::setup()
generate a new model, and utilize it in a test making a request to an endpoint that accesses that model. In the controller inspect theIlluminate\Database\Eloquent\Model::$wasRecentlyCreated
property, it will be booltrue
.I uncovered it when I saw updates returning a 201 from a Resource handler.
I'm curious if
wasRecentlyCreated
should be reset in theModel::refresh()
method?* Edit - this may only relate to the User model, I have not tested on others.*
The text was updated successfully, but these errors were encountered: