Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use PHPUnit assert methods in a Codeception functional test?

I'm using Codeception for unit, functional, and acceptance tests of my Laravel 4 PHP application.

My unit tests look this:

use Codeception\Util\Stub;
class ExampleTest extends \Codeception\TestCase\Test 
{
 public function testExample()
 {
  $example = true;
  $this->assertSame($example, true);
 }
}

My functional tests look like this:

use \TestGuy;
class ExampleCest
{
 public function example(TestGuy $I)
 { 
  $I->amOnPage('/auth/login');
  $I->see('Sign in');
 }
}

But I also want to use PHPUnit assert methods in my functional tests. But when I try to, I get this error:

Call to undefined method ExampleCest::assertSame()

How do I use PHP assert methods in a Codeception functional test?

like image 831
mtmacdonald Avatar asked Jan 29 '14 12:01

mtmacdonald


2 Answers

In Codeception 4 just add the Asserts Module:

modules:
    enabled:
        - \Codeception\Module\Asserts

to your suite.yml config file and run codeception build

like image 141
Tavo Nieves J Avatar answered Nov 20 '22 22:11

Tavo Nieves J


Since Codeception 2.1 (not 2.0) you can use it like the other asserts with:

$I->assertSame($expected, $actual, $message);

But don't forget to enable the Asserts module in your config - e.g.:

class_name: UnitTester
modules:
    enabled: [ Asserts ]

Please note: You might need to change your configuration when upgrading to 2.1 - see upgrade instructions: http://codeception.com/06-19-2015/codeception-2.1-rc.html

like image 29
conceptdeluxe Avatar answered Nov 20 '22 23:11

conceptdeluxe