phalcon/cphalcon — pull request #1472 by DavertMik (2013-10-29 03:41:14+00:00)
Title: initial codeception test suite

Here are tests run with Codeception engine. Basically, in those tests Codeception does nothing special that PHPUnit can't, yet it looks like the tests lacked a proper structure. So moving tests into Codeception should be not just changing the file location, but also some refactoring in order to gain more readability and maintainability of tests. The ideal test is that can be taken into documentation.

``` php
array('id', 'name')
))
)->equals(
'' . PHP_EOL
. chr(9) . '
Robotina
' . PHP_EOL
. chr(9) . '
Astro Boy
' . PHP_EOL
. chr(9) . '
Terminator
' . PHP_EOL
. ''
);
}

```

Looks a way like a documentation. Or:

``` php
router()
->add('/admin/:controller/p/:action', array('controller' => 1, 'action'=> 2))
->setName('adminProducts');

expect(
$this->url()->get(array(
'for' => 'adminProducts',
'controller' => 'products',
'action' => 'index',
))
)->equals('/admin/products/p/index');
}

```

So I'd like to propose some simple rules for writing tests:

* separation helpers from tests. All preparation methods should be moved into helpers. Thus, no Model/TestCase ierarchy needed.
* usage of `expect()` instead of assertion. This is taken from Codeception/Verify project. A bit more readable then `assert`. Much easier to get what is actual, and what is expected.
* docblocks should not be used for comments. Currently they are just the source of confusion: Because of this :(
https://github.com/DavertMik/cphalcon/blob/Codeception/php-tests/tests/Phalcon/Url/UnitTest.php#L190
* and yes, the shorter tests are, the more are they easy to maintain.

-----

File Structure:

tests are in `tests` dir. There are 3 suites:

* functional - TestGuy (not used)
* integration - DbGuy - with database - PhalconDbHelper + PhalconApiHelper
* unit - CodeGuy - without database - PhalconApiHelper

*Guy classes contain all passed methods from Helper classes. They are generated with `built` command in order to provide multiple inheritance from helpers/modules. Take a look into `tests/_helper` files, and especially PhalconDbHelper and PhalconApiHelper.

All data (fixtures, etc) should be put into `tests/_data` dir.

P.S. Currently integration tests run for MySQL only. That's limitation of Codeception which I'm going to fix in next version.
P.S.S. RIght now some Tag tests are failing. Not sure why :(