Phpunit mocking pages

Hello!

I would like to step up the unit tests (phpunit) for my plugins. For that I was looking for the best/easiest way to mock kirby pages. I’ve got a lot of methods which are working with (data of) pages. I didn’t find anything in the docs about that topic. I hope someone here can give me a good hint or even an example.

Thank you!

Check out @bnomei’s setup for plugin testing: kirby3-bolt/tests at master · bnomei/kirby3-bolt · GitHub

There’s also this recipe that might be helpful, I think it’s a different approach from what @bnomei’s doing: Plugin test workflow with PHPUnit | Kirby

Not sure if that’s what you are looking for but maybe it helps as a starting point.

The idea was to work with pages, without creating “real” ones (as this will collide with my monolithic setup). Create different sets of data and see if the methods do what they are supposed to do.

I will have a look how @bnomei did this, thank you for the hint.

A look at the kirby tests might be helpful as well: kirby/tests/Cms/Pages at master · getkirby/kirby · GitHub

1 Like