Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number of stub invocations is not verified #6662

Open
AdrienPoupa opened this issue Apr 20, 2023 · 2 comments
Open

Number of stub invocations is not verified #6662

AdrienPoupa opened this issue Apr 20, 2023 · 2 comments

Comments

@AdrienPoupa
Copy link

What are you trying to achieve?

This is to report something similar to this bug: https://stackoverflow.com/questions/26140295/codeception-util-stub-methods-exactly-and-once-dont-work

Given this test:

   public function checkMyMethodIsNeverCalled(AcceptanceTester $I): void
    {
        $account = factory(Account::class)->create();

        $myService = Stub::make(
            MyService::class,
            [
                'myMethod' => Stub\Expected::never()
            ],
            $this
        );

        $myService->someAction($account);
    }

If someAction calls myMethod, it is not verified and the test passes.

I can manually run the tests with this: $myService->__phpunit_verify(); but I should not need to.

I think it's because $this is simply a TestCest class that does not extend anything whereas Stub's doGenerateMock expects the test case to be a PHPUnitTestCase to attach it:

        // using PHPUnit 5.4 mocks registration
        if (version_compare(PHPUnitVersion::series(), '5.4', '>=')
            && $testCase instanceof PHPUnitTestCase
        ) {
            $mock = call_user_func_array([$generatorClass, $methodName], $args);
            $testCase->registerMockObject($mock);
            return $mock;
        }
        if ($testCase instanceof PHPUnitTestCase) {
            $generatorClass = $testCase;
        }

Details

  • Codeception version: 5.0.10
  • PHP Version: 8.1
  • Operating System: Linux
  • Installation type:Composer
@Naktibalda
Copy link
Member

You are right that mock is only verified in TestCase format.

Won't fix.

@AdrienPoupa
Copy link
Author

Alright, but I did not see any mention of that in the documentation, maybe it should be specified?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants