How to test model proper way?
I have some code in models I want to test. I found in phalcon incubator there is class ModelTestCase. It setup db connection base on DI.
My default DI set db service as default db with my data. To not lose data I created new DI for test where db service return connection with test database. I found that I need to manually prepare this database, run migrations on this test database (here is first problem), populate db, run tests, delete database.
Is there maybe easier way of testing models?
If I run test in the same directory that I develop app .phalcon/migration-version will be in highest point so I need create hack to run migrations on test connection. Of course I can use Travis CI to run test and then everything works fine, but if I write tests I want first run them locally before commiting something to repository.
If I have some Class that use Model::find() method it is nearly impossible to test that code. I don't undestand why using static methods when testing them is so hard.
- Is there maybe ready mock Db adapter which simulate db connection but all ORM relations works in the memory?
P.S. Now I'm using phpspec/prophecy to mock almost all ORM functions and testing my code without DB, but again static make this very hard. For example I don't find way to mock Model::create method :(.