Codeception: Bug: Stub method invoke count test not working

This test should fail because the method is called only one time but is expected to be called two times. However the test won’t fail in current stable version (I didn’t try dev).

Similarly Stub::once(...) won’t fail if never called.

<?php

use Codeception\Util\Stub;

class Foo
{
    public function method() {}
}

class ExampleTest extends \Codeception\TestCase\Test
{

    public function testSomething()
    {
        $foo = Stub::makeEmpty('Foo', array(
            'method' => Stub::exactly(2, function () {}),
        ));

        $foo->method();
    }

}

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 27 (21 by maintainers)

Most upvoted comments

To make verification working automatically you have to pass an instance of PhpUnit_Framework_TestCase as the last argument to Stub::makeX() method. $this works in all test formats in Codeception 2.1.


class ExampleTest extends \Codeception\TestCase\Test
{

    public function testSomething()
    {
        $foo = Stub::makeEmpty('Foo', array(
            'method' => Stub::exactly(2, function () {}),
        ), $this);

        $foo->method();
    }

}