TestHelper for your CakePHP apps

5 years ago I mentioned it as a side topic.
Now I want to showcase it with fresh look and feel and lots of more useful tooling.

The TestHelper plugin

It now ships with its own default standalone template.
That makes it easier to "work" and "look correctly", as the app itself is less likely to conflict here.

img

Cake Linter

A super useful tool you can opt-in for your CakePHP apps to make sure they are up to date and use best practice approaches.
Use the built in tools, and also add your own tasks on top.

img

Add it to your CI as

bin/cake linter

For some tasks auto-fixing is possible, in that case run it locally to auto-fix those issues found:

bin/cake linter --fix

Browser test runner

You recall the 2.x days? Yes, there was a browser-based (click and run) test runner included.
It lives on in this plugin.

Why is this a good thing? In many cases clicking a link can be much quicker than manually typing or copy pasting the whole path to the test file.
It also directly links the coverage to that file.

But even if you want to keep the CLI for testing, the GUI offers a few more things:

  • See all CakePHP types as overview (controller, components, tables, helpers, forms, mailers, …) and which of those have test cases and which don’t.
  • With a simple click bake the missing test cases directly from that backend. You read that right: It also bakes from the GUI.

tests

Reverse URL Lookup

A handy tool for e.g.

  • $this->redirect()
  • HtmlHelper::link() and UrlHelper::build() usage
  • $this->Form->postLink()
  • $this->get() and $htis->post() in tests

etc. All of those should get an array instead of plain strings for compatibility.

img

Compare models, DB tables and fixture (factories)

You can also bake missing fixture factories per click from the backend.

Migration Re-Do tool

Provides a multi-step process to ensure a fresh migration file replacing your current ones (merging all together).
Works on a tmp-DB ton confirm the result as diff in the end.

Summary

The browser based addons can help for test-driven development, the CLI tools for asserting high quality.
Check out the plugin now.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.