baopham / laravel-dynamodb

Eloquent syntax for DynamoDB
https://packagist.org/packages/baopham/dynamodb
MIT License
490 stars 127 forks source link

Run tests without firing a DynamoDB instance ? #238

Closed Adesin-fr closed 3 years ago

Adesin-fr commented 3 years ago

Hi,

I'm used to code with TDD habits, and having a big bunch of tests is a big plus to me.

How do you guys do test your apps with DynamoDB without needing to run a local instance of DynamoDB ? Usualy, I use sqlite to run all my tests : this allows to run tests really quick.

One of the answer I've found (for node) was to use the Data Mapper pattern, so you still can use the Model classes and just have to mock the data mapper objects...

Any thoughts ?

zoe-edwards commented 3 years ago

Yeah this is a huge problem and it’s not easy. I’ve found it has got in the way quite a bit. I’ve tended to use an Amazon instance for testing that relies upon the fact that the UUIDs are unlikely (very unlikely) to repeat. Then occasionally I’ll empty the table if it’s got too big, but it’s not great.

I was going to look into running a Docker container soon, but it’s not ideal as it’s kind of slow like you say.

A PHP mock of Dynamo would be pretty great.

Adesin-fr commented 3 years ago

Yes, mocking is really the goal : on the previous appllication I coded, the 210 tests are ran in less than a minute. TDD is really possible this way, having all those tests running against a real DB would not be possible so quickly (the DB is wiped before each test !)

bruno-rodrigues commented 2 years ago

@thomasedwards Was this closed because the solution is already out there or because it won't be fixed? Thanks

zoe-edwards commented 2 years ago

I think it’s out of scope for this package to provide – but there’s no reason that you can’t use this package to connect it to a mock DynamoDB endpoint.

There’s a bit about this from Amazon: https://aws.amazon.com/blogs/aws/amazon-dynamodb-libraries-mappers-and-mock-implementations-galore/