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

before and after annotations don't work in some traits #1763

Closed
GrahamCampbell opened this issue Jun 23, 2015 · 4 comments
Closed

before and after annotations don't work in some traits #1763

GrahamCampbell opened this issue Jun 23, 2015 · 4 comments

Comments

@GrahamCampbell
Copy link
Contributor

If you use a trait in a class then extend that class then phpunit doesn't process the before and after annotations for those methods in that trait.

NB, experiencing this with phpunit 4.7.5.

@sebastianbergmann
Copy link
Owner

Can you please provide a minimal, self-contained, reproducing test case? I am afraid I don't fully understand what you are trying to do.

@GrahamCampbell
Copy link
Contributor Author

class Foo
{
    public function bar()
    {
        return 'baz';
    }
}

trait MockeryTrait
{
    /**
     * @after
     */
    public function tearDownMockery()
    {
        if ($container = Mockery::getContainer()) {
            $this->addToAssertionCount($container->mockery_getExpectationCount());
        }

        Mockery::close();
    }
}

abstract class AbstractTestCase extends PHPUnit_Framework_TestCase
{
    use MockeryTrait;
}

class FooTest extends AbstractTestCase
{
    public function testStuff()
    {
        $mock = Mockery::mock(Foo::class);
        $mock->shouldReceive('bar')->andReturn('foobarbaz');
        $mock->bar();
    }
}

@GrahamCampbell
Copy link
Contributor Author

If running in strict mode, phpunit thinks there have been no assertions and warns because the tearDownMockery method was never called.

@GrahamCampbell
Copy link
Contributor Author

PHPUnit will also fail without the trait, like, if we just put that method into the "AbstractTestCase" class.

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