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

Additional Mutators #1

Merged
merged 15 commits into from
Sep 11, 2017
Merged

Additional Mutators #1

merged 15 commits into from
Sep 11, 2017

Conversation

khepin
Copy link
Collaborator

@khepin khepin commented Sep 8, 2017

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

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
*/
public function serializeAttribute($value)
{
if (!\ctype_xdigit($value)) {
Copy link
Contributor

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;;
Copy link
Contributor

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))],
Copy link
Contributor

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];
Copy link
Contributor

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];
Copy link
Contributor

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...

@elliotfehr elliotfehr merged commit 8199009 into Weebly:master Sep 11, 2017
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.

None yet

2 participants