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

This test did not perform any assertions #61

Open
kschroeer opened this issue Jan 15, 2020 · 1 comment
Open

This test did not perform any assertions #61

kschroeer opened this issue Jan 15, 2020 · 1 comment

Comments

@kschroeer
Copy link

I have some problems to use Hamcrest in combination with PHPUnit. I loaded phpuNit 7.0 and hamcrest-php (dev-master) with composer. The environment is PHP 7.2.
And then I build this first test:

<?php

namespace App\HamcrestTest;

use PHPUnit\Framework\TestCase;

class MyTest extends TestCase
{
    public function setUp()
    {
        \Hamcrest\Util::registerGlobalFunctions();
    }

    public function testHamcrestWorks()
    {
        assertThat('a', is(equalTo('a')));
    }
}

Executing the test I will get this error message:

There was 1 risky test:
1) App\HamcrestTest\MyTest::testHamcrestWorks
This test did not perform any assertions
@aik099
Copy link
Member

aik099 commented Jan 16, 2020

This can be solved by adding below code snippet to tearDown method of your test case class:

$this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount());

Some more ideas:

  • if your test case classes share some base test case class, then adding above shown code there will solve the problem for all of your test case classes
  • you're not overriding tearDown method in your test classes, then adding tearDown method via trait is also possible

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