Summary: I want to use Module assertions in my Tests.
Previously I have tested Symfony2 services using PHPUnit tests. This is ok but I would like to use some of the facilities that the Codeception Symfony2 Module provides as well as the cleaner testing style.
I created a new suite with the following services.suite.yml
class_name: ServiceGuy
modules:
enabled: [Symfony2, Doctrine2, Filesystem, ServiceHelper]
I ran build and generate:cest and have a ServiceCest.php test file with
public function getServiceUrl(\ServiceGuy $I) {
$this->myservice = $I->grabServiceFromContainer("myservice");
$I->wantTo("get service URL");
$I->seeTrue("http://example.com/services"
== $this->ecservice->getServiceUrl());
}
This test passes because I added an assertion function to my ServiceHelper.php file.
class ServiceHelper extends \Codeception\Module {
function seeTrue($flag) {
$this->assertTrue($flag);
}
}
The Module class has a rich set of assertion functions that I would like to be able to use directly in my tests. But I don't think module object is available to the test. It would seem repetitive to have to add a range of assertion functions to the ServiceHelper. Is there a better way?
For example in the phpunit test I might have these assertions.
$station = $ecservice->getStation("Auckland");
$this->assertEquals(1,count($stations)); $this->assertEquals('Auckland',$station->getDisplayName());
My question is whether there is a way to have all these assertions in the functional test, or whether I have to move a lot of test specific assertions into the helper.
The Unit module appears to provide many of these facilities - but is deprecated.
I tried putting \PHPUnit_Framework_Assert::assertEquals(1,count($stations)); in the test - but this throws an exception on failure that is not handled by the test harness.
Thanks Andrew
PS I'd tag this 'codeception' but I don't have the points yet. perhaps someone else can.