feat!: use mongodb function to check for dirtiness#2515
Conversation
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## master #2515 +/- ##
============================================
+ Coverage 90.64% 90.72% +0.07%
+ Complexity 758 754 -4
============================================
Files 34 34
Lines 1849 1843 -6
============================================
- Hits 1676 1672 -4
+ Misses 173 171 -2
☔ View full report in Codecov by Sentry. |
GromNaN
left a comment
There was a problem hiding this comment.
This change will leverage the MongoDB driver to detect attribute changes. It will reduce bugs and make the maintenance easier.
Could you rebase onto master and add a changelog entry?
Co-Authored-By: Jérôme Tamarelle <GromNaN@users.noreply.github.com> Co-Authored-By: Hamid Alaei Varnosfaderani <hamid.a85@gmail.com>
Hello, Done! Can you please review it? Thanks! |
|
|
||
| return is_numeric($attribute) && is_numeric($original) | ||
| && strcmp((string) $attribute, (string) $original) === 0; | ||
| return fromPHP([$attribute]) === fromPHP([$original]); |
There was a problem hiding this comment.
A couple of notes on this:
fromPHPwill be deprecated and is replaced byDocument::fromPHP- Root-Level encoding is only supported for documents (i.e. any object or array with string keys)
- If
$attributehappens to be an object (e.g. an embedded document), this conversion will not yield the correct results as only public properties are encoded, which is most likely wrong for any Model - This may not be an issue, but I'll note that using this comparison
['foo' => 'bar', 'bar' => 'foo']and['bar' => 'foo', 'foo' => 'bar']will not be treated as equal. That said, we don't have a good way to check BSON equality, and one may argue that two BSON documents with the same key/value pairs in different order shouldn't be considered equal.
For the time being, using this comparison may be feasible as long as we can ensure that it doesn't have side effects for embedded documents.
| $this->assertEmpty($user->getDirty()); | ||
| } | ||
|
|
||
| public function testGetDirty() |
There was a problem hiding this comment.
Please add a test using embedded documents and arrays to ensure correct behaviour.
This is rework of test for PR #1990