0

I have downloaded and installed Codeception. I used the following instructions: http://codeception.com/thanks After writing and running the tests I get the following error:

Fatal error: Call to protected method Codeception\TestCase\Test::_before() from context 'Codeception\Subscriber\Cest' in phar://C:/xampp/htdocs/codeceptiontest/codecept.phar/src/Codeception/Subscriber/Cest.php on line 11

My unit test is the following:

<?php
use \CodeGuy;
use \User; // My own class

class UserCest extends \Codeception\TestCase\Test
{
    private $user;

    protected function _before()
    {
        $this->user = new User();
    }

    protected function _after()
    {
        // Do nothing
    }

    // tests
    public function changeUsername(CodeGuy $I) 
    {        
        $I->wantTo("change my username");
        $I->amGoingTo("name my user Tim");
        $this->user->setName("Tim");
        $this->assertEquals($this->user->getName(), "Tim");
        $this->assertTrue(true);
    }
}

When my class does not extend \Codeception\TestCase\Test, the _before() function is not called and the assert functions will not work.

Any suggestions are welcome.

Rick Slinkman
  • 643
  • 10
  • 23

1 Answers1

2

Have you tried making _before() and _after() public?

The Codeception docs are sadly outdated in many places, and quite a few recent changes break the examples given in the documentation.

Tom
  • 2,688
  • 3
  • 29
  • 53