-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Comments
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. |
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();
}
} |
If running in strict mode, phpunit thinks there have been no assertions and warns because the tearDownMockery method was never called. |
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
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.
The text was updated successfully, but these errors were encountered: