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

Expectations are not evaluated on mock objects passed via @depends #1821

Closed
sebastianbergmann opened this Issue Aug 12, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Aug 12, 2015

Example

<?php
class Foo
{
    public function bar()
    {
    }
}

class Test extends PHPUnit_Framework_TestCase
{
    public function testOne()
    {
        $mock = $this->getMock(Foo::class);
        $mock->expects($this->once())->method('bar');

        $mock->bar();

        return $mock;
    }

    /**
     * @depends testOne
     */
    public function testTwo(Foo $mock)
    {
        $mock->bar();
    }
}

Actual output

PHPUnit 4.8.3 by Sebastian Bergmann and contributors.

..

Time: 64 ms, Memory: 4.75Mb

OK (2 tests, 1 assertion)

Expected output

PHPUnit 4.8.3 by Sebastian Bergmann and contributors.

.F

Time: 64 ms, Memory: 4.75Mb

There was 1 failure:

1) Test::testTwo
Foo::bar() was not expected to be called more than once.

/home/sb/phpunit-mock-depends/Test.php:26

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
@nicolas-grekas

This comment has been minimized.

Copy link
Contributor

nicolas-grekas commented Oct 6, 2015

Couldn't this be considered as a bug fix on 4.8? It's a shame we have to use php 5.6 to get these assertions correctly verified...

@nicolas-grekas

This comment has been minimized.

Copy link
Contributor

nicolas-grekas commented Oct 6, 2015

Btw, this issue is also about mock objects passed via data collectors.

nicolas-grekas added a commit to nicolas-grekas/symfony that referenced this issue Oct 6, 2015

nicolas-grekas added a commit to symfony/symfony that referenced this issue Oct 6, 2015

minor #16138 [Security\Core] Fix test failure after sebastianbergmann…
…/phpunit#1821 (nicolas-grekas)

This PR was merged into the 2.3 branch.

Discussion
----------

[Security\Core] Fix test failure after sebastianbergmann/phpunit#1821

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16112
| License       | MIT
| Doc PR        | -

See sebastianbergmann/phpunit#1821

Commits
-------

742547c [Security\Core] Fix test failure after sebastianbergmann/phpunit#1821

axiac pushed a commit to axiac/phpunit that referenced this issue May 8, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.