j4mie / idiorm

A lightweight nearly-zero-configuration object-relational mapper and fluent query builder for PHP5.
http://j4mie.github.com/idiormandparis/
2.01k stars 369 forks source link

Unit testing with Idiorm #226

Closed henryruhs closed 10 years ago

henryruhs commented 10 years ago

Hello,

I wonder there is no essay about unit testing with Idioorm in your documentation. What is the recommended way to mock the ORM methods?

PHPUnit's getMock() cannot be used to mock static methods, there are a few mock frameworks that provide this missing feature. Is an local sqlite database for unit testing the way to go? Please give me a hint or provide a recommended tutorial.

Thanks

treffynnon commented 10 years ago

I don't test the database/ORM, but the adapter I have for my project at hand instead and even then only loosely. That's a personal preference as I reserve testing for intricate components in my app not external dependencies and I am not so worried about getting 100% test coverage. So I have never seen the need to document a workflow I don't use.

You can use something like mockery I would guess or write your own custom mock that emulates Idiorm. Idiorm itself does not currently have any tests that are run against a database, but only tests that verify the query builder is outputting the correct SQL for a given situation.

henryruhs commented 10 years ago

Let me understand this, are you talking about models to mock or what do you mean by adapter? Your answer does not provide a way todo it probably - I have static calls inside some classes, these classes won't work without, so I cannot ignore them.

Maby we have a design / pattern issue here, so let me know what I should do.

A friend of mine had the idea to load a fake ORM class for the testing that returns dummy data.

treffynnon commented 10 years ago

I am not really sure what your looking for, but the repository pattern might be a good place for you to start.

henryruhs commented 10 years ago

I was looking for examples but it seems that you cannot help me... closed