Ideas for testing our classes

We’ve got a lot of “model” classes which all extends Entity. When in controller classes/methods we want to get multiple objects of one model we do Model::find()->where()->orderby()->etc… find() as shown returns an object where we can filter out our objects and then retrieve them.

We want to make tests for our codebase but I’m thinking testing the controllers will be hard because we access the models using a static method directly on the concrete model classes.

If we just want to create a new model we do $model = new Model(); $model->property = “value”; $model->save(); so that is probably a lot more testable if we change to using a dependency injection tool like Phemto.

I’d definitely recommend looking at dependency injection.

What’s in Entity?

Entity contains save, delete, find (which returns another object used for building a sql query and fetching entities), etc. The Model objects only contain the properties for that specific model and methods specific to the model.

I’ve started using dependency injection now but those objects are still a problem. I was thinking about moving away from doing everything in the model/entity objects and make the model objects simple and then use some kind of entity manager to retrieve and save entieis but thats in the future.