Skip to content
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

fix: $model->getChanges() triggered due to strict comparison #187

Merged
merged 3 commits into from
Feb 16, 2021

Conversation

atymic
Copy link
Contributor

@atymic atymic commented Oct 25, 2020

  • Added or updated tests
  • Added or updated the README.md
  • Detailed changes in the CHANGELOG.md unreleased section

Related Issue/Intent

Resolves #166

Changes

Fixes getChanges() being polluted by non changes. Laravel is using strict comparison under the hood, so comparing two different enum instances will return false. Comparing the underlying native types will return true.

Breaking changes

None

@@ -495,6 +495,10 @@ public static function parseDatabase($value)
*/
public static function serializeDatabase($value)
{
if ($value instanceof self) {
return $value->value;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the meat of the change and falls back to $value just in case

use Illuminate\Contracts\Console\Kernel;
use Illuminate\Filesystem\Filesystem;

class ArtisanCommandsTest extends ApplicationTestCase
{
/**
* TODO remove once we cut support for Laravel < 5.7
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dropped < 7

@@ -72,4 +73,21 @@ public function test_model_with_trait_but_no_casts()
$model->foo = true;
$this->assertTrue($model->foo);
}

public function test_get_changes_works_correctly()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to repro the test case from #166

@Propaganistas
Copy link
Contributor

Propaganistas commented Feb 16, 2021

@BenSampo Please review this. Laravel's "dirty attribute" logic is currently broken because of this.

@BenSampo BenSampo closed this Feb 16, 2021
@BenSampo BenSampo reopened this Feb 16, 2021
@BenSampo BenSampo merged commit 8422afb into BenSampo:master Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

enum cast getChanges() not work as expect?
3 participants