-
Notifications
You must be signed in to change notification settings - Fork 7
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
Additional Mutators #1
Conversation
Adds 2 additional mutators: - HexBinaryMutator which presents an attribute as a hex string but stores it as binary data - UnixTimestampMutator which presents an attribute as a Carbon dateobject but stores it as an int
src/Mutators/HexBinaryMutator.php
Outdated
*/ | ||
public function serializeAttribute($value) | ||
{ | ||
if (!\ctype_xdigit($value)) { |
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.
We don't need the \
for global functions
if (!$value instanceof Carbon) { | ||
throw new MutateException(__METHOD__." expects a Carbon\Carbon value. Received: ". print_r($value, true)); | ||
} | ||
return $value->timestamp;; |
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 [ | ||
[new \stdClass], | ||
[0], | ||
[base64_encode(random_bytes(20))], |
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.
Can we hardcode our test values + get descriptions for these tests?
{ | ||
for ($i = 0; $i < 10; $i++) { | ||
$bytes = random_bytes(20); | ||
yield [bin2hex($bytes), $bytes]; |
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.
We should find the hard coded tests cases that will pass/fail instead of a for loop and a random value, otherwise this test should be marked as flaky.
for ($i = 0; $i < 10; $i++) { | ||
$t = rand(1, time()); | ||
$c = Carbon::createFromTimestamp($t); | ||
yield [$c, $t]; |
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.
Same with this for loop...
Adds 2 additional mutators:
HexBinaryMutator
which presents an attribute as a hex string but stores it as binary dataUnixTimestampMutator
which presents an attribute as a Carbon dateobject but stores it as an int