-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Testing in the core and its plugins
To unify the testing procedure inside the core the following scenarios are provided as a guidance to help you decide how testing should be done inside CakePHP core and its plugins.
The goal is to achieve this new testing structure when CakePHP 6 is released.
- Do not mock, if its not necessary
- Mock via anonymous classes if easily possible
- If neither 1. and 2. can be achieved, use Mockery instead of PHPUnit mocks.
The above example shows the fact, that creating table objects does not need to be mocked.
The above example shows how to mock an ExceptionRenderer to return a specific response via an anonymous class.
The above example shows how to use Mockery to create a MiddlewareApplication, expect specific inputs on methods and returns given output.
Moc 8000 kery is very powerfull, but it should still only be used if not possible otherwise OR the anonymouse class gets too verbose.
The above example should be converted to mockery since specific passed down arguments need to be checked as well as the return value of that method.