8000 Testing in the core and its plugins · cakephp/cakephp Wiki · GitHub
[go: up one dir, main page]

Skip to content

Testing in the core and its plugins

Kevin Pfeifer edited this page Sep 8, 2024 · 1 revision

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.

  1. Do not mock, if its not necessary
  2. Mock via anonymous classes if easily possible
  3. If neither 1. and 2. can be achieved, use Mockery instead of PHPUnit mocks.

Examples

https://github.com/cakephp/cakephp/pull/17880/files#diff-74e5ede82df5bfe50aa5d1043a89b5410058638e77c3020f250a7661b17c26eaR135

The above example shows the fact, that creating table objects does not need to be mocked.


https://github.com/cakephp/cakephp/pull/17851/files#diff-f2f89dc3d8b4ad07ab0666497cbb8f82ae4d605d3723ed4f0b72b05d805a6444R101

The above example shows how to mock an ExceptionRenderer to return a specific response via an anonymous class.


https://github.com/cakephp/cakephp/pull/17246/files#diff-e02d58c1e187c30f9a7bea4724ffa4920dba3f2e2c2a1a0afb27f12dd8500017R132

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.

https://github.com/cakephp/cakephp/pull/17880/files#diff-74e5ede82df5bfe50aa5d1043a89b5410058638e77c3020f250a7661b17c26eaR338-R345

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.

Clone this wiki locally
0