-
Notifications
You must be signed in to change notification settings - Fork 127
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
called syncOriginal() after setting attributes getAll() and find() - … #58
Conversation
…this fixes the 'dirty' issue, support timestamps (dirty needs to work for timestamps to function properly for updated_at)
Nice. This change would need some unit tests to make sure it is working and won't break in the future. If you need help with the tests, let me know. It'd be nice if we can support timestamps. |
Having trouble getting DynamoDbLocal setup for the test. I already have DDb Local setup for my laravel project, and use the following to start it ...
I adjusted this to the following for the tests
Doing this, I managed to go from having every test generate errors (and take forever trying to connect to what was not there), and now am getting 6 errors ... they all appear to be the same error though.
Do I need to do something other than start DDb Local pointing at the project directory? Looks like the tests take the dynamodb_local_init.db and move it to dynamodb_local_test.db which I assume creates all of the necessary tables, with expected default items in it? |
Yes Can you make sure you
Then in a new tab, run:
|
…CONTRIBUTING.md with instructions to start DynamoDB Local and PHPUnit
Ahh, looks like I actually did have it all setup correctly. Following the errors, the timestamp logic does apparently try to connect to the database at some point to retrieve a date/time format in the event that one is not already set on the model. Should be an easy fix to explicitly set the date/time format on DynamoDbModel - just a matter of picking a default format. I'm thinking we should use the format generated by JavaScript's Date toJSON method, as described here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON |
Since Laravel is using Carbon so why not use its |
I figured using the JavaScript json format would make the json document more compatible with other application code that may be using/accessing it (lambda triggers, client side code, mobile apps, etc) either directly or indirectly. |
Looks like those two formats are the same actually. Javascripts date object calls toIsoString behind the scenes. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString |
ISO 8601 format it is then 👍 |
Adding
|
Ah yeah totally forgot about that! Still need to have 2 test cases though, one for created_at and one for updated_at. |
# The "O" or "o" standard format specifier represents a custom date and time format string using a pattern that preserves time zone information and emits a result string that complies with ISO 8601. # https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings#Roundtrip
Not quite sure why, but all the timestamps are being set to 1970-01-01 ... in my app, they are being set to the correct current time. I checked the HasTimestamps trait and verified that it's creating a new Carbon instance, with the current time ... but for some reason, after it's being set to $this->testModel->created_at it gets set to 1970-01-01 ... not quite sure where this is happening - any ideas? I'm thinking it may have something to do with the tests themselves? -- Nevermind, I think it has to do with the format I'm using ... working on it now. |
Let me try and see |
For a more deterministic test, maybe we should try |
tests/DynamoDbTimestampTest.php
Outdated
return $item; | ||
} | ||
|
||
} |
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 closing brace for the class must go on the next line after the body
tests/DynamoDbTimestampTest.php
Outdated
|
||
} | ||
|
||
class TimestampModel extends \BaoPham\DynamoDb\DynamoDbModel |
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.
Each class must be in a file by itself
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.
Nitpick is really nit-picky... can I just ignore some of these?
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.
Haha yeah, this one can be ignored.
'hash' => 'count', | ||
], | ||
]; | ||
} |
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.
Expected 1 blank line at end of file; 2 found
I created a new test class, so we can setup as many tests as needed - this also allows the other test classes to set I did use Carbon::setTestNow() The problem was using |
"scripts": { | ||
"test": "phpunit", | ||
"dynamodb_local": "java -Djava.library.path=./DynamoDBLocal_lib -jar dynamodb_local/DynamoDBLocal.jar --port 3000" | ||
}, |
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.
Very nice! just like package.json
😄
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.
Thanks :)
CONTRIBUTING.md
Outdated
|
||
or | ||
|
||
```composer run-script 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.
Do you mean test
here?
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.
I did ... fixing now
CONTRIBUTING.md
Outdated
@@ -1,3 +1,19 @@ | |||
# Contribution Guide | |||
|
|||
Thank you for considering contributing to this library. Please make sure your code follows the PSR-2 coding standard and the PSR-4 autoloading standard before sending a pull request. | |||
|
|||
## Running 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.
Might as well remove the test section in README.
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.
Ahh, didn't realize there was a test section there - did you add it recently?
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.
No it's been there for a while :)
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.
I updated CONTRIBUTING.md and README.md
tests/DynamoDbTimestampTest.php
Outdated
|
||
public function testCreateRecord() | ||
{ | ||
\Carbon\Carbon::setTestNow(\Carbon\Carbon::create(2017, 06, 24, 5, 30, 0)); |
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.
Maybe put a use Carbon\Carbon
on top?
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.
yeah, ... that would make sense :)
} | ||
} | ||
|
||
class TimestampModel extends \BaoPham\DynamoDb\DynamoDbModel |
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.
Each class must be in a file by itself
…ch README.md style (- and = instead of #), added DynamoDb Local details to CONTRIBUTING.md
Many thanks @zoul0813 for pushing this through. |
Your welcome, and don't forget to check off the TODO item at the bottom of README.md ... just saw that. |
Yep one down! |
added support for timestamps, and fixed "isDirty" logic (isDirty is required for timestamps to work properly).
This change is