hamcrest / hamcrest-php

PHP Hamcrest implementation [Official]
Other
6.95k stars 45 forks source link

This test did not perform any assertions #61

Open kschroeer opened 4 years ago

kschroeer commented 4 years ago

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 commented 4 years ago

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: