Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP shell unit tests

I want to write unit tests for a CakePHP shell that I'm creating, but they aren't mentioned in the testing documentation or bake:

---------------------------------------------------------------
Bake Tests
Path: /home/brad/sites/farmlogs/app/Test/
---------------------------------------------------------------
---------------------------------------------------------------
Select an object type:
---------------------------------------------------------------
1. Model
2. Controller
3. Component
4. Behavior
5. Helper
Enter the type of object to bake a test for or (q)uit (1/2/3/4/5/q) 

Since CakePHP doesn't appear to have a default shell testing setup, what should the structure of my basic shell tests look like?

like image 922
Brad Koch Avatar asked Sep 18 '12 15:09

Brad Koch


1 Answers

Judging from examples in Mark Story's AssetCompress and the CakeDC's Migrations, just mimic the directory structure for other tests:

Test/
  Case/
    Console/
      Command/
        Task/
          MyShellTaskTest.php
        MyShellTest.php

Your tests can just extend the CakeTestCase object, just like any other generic test:

class MyShellTest extends CakeTestCase {
}

If needed, you can override the base shell, just like you would do with a Controller test:

class TestMyShell extends MyShell {
}

Nothing all that special, just stick with the conventions.

like image 192
Brad Koch Avatar answered Sep 20 '22 04:09

Brad Koch