-
Notifications
You must be signed in to change notification settings - Fork 14
fix: checking the state of a database with a binary field. #240
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
c95a1ab
03606be
b68918a
4b349e7
ba961a8
bd8ca19
32f7886
f5ade29
1b6250a
9848df9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -89,14 +89,24 @@ protected function prepareChanges(array $changes): array | |||||||
| return array_map(function ($item) use ($jsonFields) { | ||||||||
| foreach ($jsonFields as $jsonField) { | ||||||||
| if (Arr::has($item, $jsonField)) { | ||||||||
| $item[$jsonField] = json_decode($item[$jsonField], true); | ||||||||
| $value = $item[$jsonField]; | ||||||||
|
|
||||||||
| $item[$jsonField] = $this->isBinary($value) | ||||||||
|
||||||||
| $item[$jsonField] = $this->isBinary($value) | |
| $item[$jsonField] = ($this->isBinary($value)) |
AZabolotnikov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
DenTray marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
AZabolotnikov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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.
| return !is_null($data) | |
| && !mb_check_encoding($data, 'UTF-8'); | |
| return !mb_check_encoding($data, 'UTF-8'); |
DenTray marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -35,7 +35,7 @@ public function testInitialization() | |||||||
| $jsonFields = $this->getProtectedProperty($reflectionClass, 'jsonFields', $modelTestState); | ||||||||
| $state = $this->getProtectedProperty($reflectionClass, 'state', $modelTestState); | ||||||||
|
|
||||||||
| $this->assertEquals(['json_field', 'castable_field'], $jsonFields); | ||||||||
| $this->assertEquals(['json_field', 'castable_field', 'binary_field'], $jsonFields); | ||||||||
|
||||||||
| $this->assertEquals(['json_field', 'castable_field', 'binary_field'], $jsonFields); | |
| $this->assertEquals(['json_field', 'castable_field'], $jsonFields); |
AZabolotnikov marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
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.
| $modelTestState->assertChangesEqualsFixture('assert_changes_binary_string.json'); | |
| $modelTestState->assertChangesEqualsFixture('null_to_binary_string_changes'); |
AZabolotnikov marked this conversation as resolved.
Show resolved
Hide resolved
AZabolotnikov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
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.
| $changedDatasetMock = collect([[ | |
| $changedDatasetMock = collect([[ |
Outdated
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.
| $modelTestState->assertChangesEqualsFixture('assert_changes_binary_string_to_null.json'); | |
| $modelTestState->assertChangesEqualsFixture('binary_string_to_null_changes'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "updated": [ | ||
| { | ||
| "id": 1, | ||
| "binary_field": "31ee76261d87fed8cb9d4c465c48158c" | ||
| } | ||
| ], | ||
| "created": [], | ||
| "deleted": [] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "updated": [ | ||
| { | ||
| "id": 1, | ||
| "binary_field": null | ||
| } | ||
| ], | ||
| "created": [], | ||
| "deleted": [] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <?php | ||
|
|
||
| namespace RonasIT\Support\Tests\Support\Mock\Casts; | ||
|
|
||
| use Illuminate\Contracts\Database\Eloquent\CastsAttributes; | ||
|
|
||
| class BinaryCast implements CastsAttributes | ||
| { | ||
| public function get($model, $key, $value, $attributes) | ||
| { | ||
| return is_null($value) ? $value : bin2hex($value); | ||
| } | ||
|
|
||
| public function set($model, $key, $value, $attributes) | ||
| { | ||
| return is_null($value) ? $value : md5($value, true); | ||
| } | ||
| } | ||
AZabolotnikov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.