-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[4.x] use mongodb driver to check for dirtiness #1990
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #1990 +/- ##
=============================================
- Coverage 82.80% 82.72% -0.09%
+ Complexity 531 526 -5
=============================================
Files 27 27
Lines 1210 1204 -6
=============================================
- Hits 1002 996 -6
Misses 208 208 Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## develop #1990 +/- ##
=============================================
- Coverage 82.8% 82.72% -0.09%
+ Complexity 531 526 -5
=============================================
Files 27 27
Lines 1210 1204 -6
=============================================
- Hits 1002 996 -6
Misses 208 208
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@halaei first of all, good work! I think we need to add a test with casted attribute to check if it's working correctly as expected.
return $current == $original; | ||
} | ||
|
||
if ($this->hasCast($key)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only problem I see is a casted attributes, probably we need to check after keys was casted back to their values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@divine Looking at the code, I don't see it is required to check for casts. The input values passed by getDirty() are uncasted:
public function getDirty()
{
$dirty = [];
foreach ($this->getAttributes() as $key => $value) {
if (! $this->originalIsEquivalent($key, $value)) {
$dirty[$key] = $value;
}
}
return $dirty;
}
public function getAttributes()
{
return $this->attributes;
}
Besides, I don't see why one should use Laravel <=6 casting system for MongoDB, I don't see a test for it in the repository either. Laravel 7 custom casts are a different story. I hope they won't make things go wrong. I've already had my custom cast implementation along side this PR in Larave 5.8 production without an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we're dropping support for laravel 6 (no other way to drop object id auto-casting) and this branch will be focused for versions > 7.0, so that's the reason why I've asked this question.
This might be an issue with Laravel 7 when it wouldn't check dirtiness for casted objects.
Yes, there are no tests, I think a lot of tests are missing, might take a look myself (for tests).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably no, it's not ready yet, still have something to do. I will let you know, ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jenssegers Nice coverage tool. But I feel I decreased the source code complexity in terms of both lines of code and branches. I also added new tests. How come the coverage is decreased? I think the report is somehow wrong. |
I see the report now. I didn't test for when exception is thrown. I don't quite remember. Maybe it has to do with my next pull request regarding unset field #1667 |
public function testGetDirty(): void | ||
{ | ||
$ids = [ | ||
new ObjectId(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add value for ObjectId please
$item->nullable = null; | ||
$item->new_val = 'new'; | ||
$item->number = '4'; | ||
$item->ids = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like strange, i suggest to replace on
$item->ids = $ids;
or
$item->ids = [
new ObjectId('576c25db6118fd406e6e6471'),
new ObjectId('576c25db6118fd406e6e6472')
];
Reopening of #1664