I am trying to add a custom helper method to unit test suite, but when running the test I get Fatal error: Uncaught ArgumentCountError: Too few arguments to function
error.
This is what I have so far
When I run the test I get:
ArgumentCountError: Too few arguments to function ExampleTest::__construct(), 0
_support/Helper/Unit.php:
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Unit extends \Codeception\Module
{
public function get_hello()
{
return 'Hello';
}
}
Test method:
public function testMe1(\UnitTester $I)
{
$hello = $I->get_hello();
$this->assertEquals(2, $hello);
}
# Codeception Test Suite Configuration
#
# Suite for unit (internal) tests.
class_name: UnitTester
modules:
enabled:
- Asserts
- \Helper\Unit
Why doesn't testme1() accept any arguments? What step am I missing?
Unit tests methods don't get actor passed as a parameter.
You can call them on $this->tester
, like in this example
function testSavingUser()
{
$user = new User();
$user->setName('Miles');
$user->setSurname('Davis');
$user->save();
$this->assertEquals('Miles Davis', $user->getFullName());
$this->tester->seeInDatabase('users', ['name' => 'Miles', 'surname' => 'Davis']);
}