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
Since v1.5.1 I'm getting "This test did not perform any assertions" #1190
Comments
And my main issue is that from the changelog I'm unable to find out what should I do. |
Noticing the same issue here, could it be this change that has caused it potentially? |
Found the reason why these are failing, it looks like it may be by design. Mockery::mock(Foo::class)->shouldReceive('bar'); The above will fail as we have not provided the number of calls we expect to it, we will need to update it to something like below adding Mockery::mock(Foo::class)->shouldReceive('bar')->once(); The added test in the commit show this expected behaviour 72cf17b#diff-e290c245179d001a519df9ee5cecf659df2e2ff8506829ef10dcc6900559fe56 |
@andrewbroberg that's nice actually. I guess it's a fix then? |
this was a minor bug.
we'll update the changelog to reflect the changes.
correct, |
I think that is debatable. That should probably be regarded as a breaking change, and delayed till 2.x, and reverted in 1.x. |
Definitely debatable, but nobody turned up to the debate and then I forgot... |
Regarding BC Break, could/should we internally set the default expectation for method stubs $mock = Mockery::mock();
$mock->shouldReceive('foo'); // Same as: $mock->shouldReceive('foo')->once();
// can be overwritten
// $mock->shouldReceive('foo')->atLeast()->once();
// $mock->shouldReceive('foo')->never();
$this->assertSame(1, Mockery::getContainer()->mockery_getExpectationCount());
$mock->shouldReceive("test1");
$mock->shouldReceive("test2")->atLeast()->once();
$mock->shouldReceive("test3")->once();
$mock->shouldReceive('foo')->never();
$mock->test1();
$mock->test2();
$mock->test3();
Thoughts? |
IMO this is a good change, we should be calling |
If what we've already done is considered a BC break, I would also consider that a BC break. Regardless, this is essentially one of the driving forces for what I did for the (not so) new
|
I thought that Because |
I've previously commented at #1180 (comment) and only afterwards found this issue now. Turns out the change is affecting us in a bigger way than I initially was able to see. From a testsuite of 20k+ tests, we have ~500+ being reported as "Risky". What added more to the confusion in our case is how different environments treated this.
However we also agree those tests are broken and need to be fixed, so we're not advocating for any change here (1.5.1 is released, aka "damage is done" anyway) and are simply going ahead and add a lot of |
Just wanted to point out that this doesn't only affect userland tests, but also the tests of Mockery itself. I've re-run the tests for Mockery itself on the commit before PR #1180 was merged (as GH Actions had already thrown away the logs): this shows 5 tests which are marked as "risky" by PHPUnit (prior to the change). When we compare this to a (re-run) build of the commit merging PR #1180, it shows between 39 and 44 tested marked as "risky" by PHPUnit (exact number depends on the PHP version used). |
FTR, no idea how I came up with this strange setting but simply adding We also found a couple of bugs in our test suite thanks to this change 🙏🏼 |
While not debating that this was a bug that needed fixing, the 1.5.1 patch change has caused our test suite to throw several new failure cases. That's a breaking change in no uncertain terms. Semver would suggest that this change be delayed until the next major release. To leave it as-is has a negative impact on downstream users; this could be preventing someone from deploying an urgent bugfix to their application. Regardless of whether a test suite is technically flawed or not, we shouldn't be forcing people to update their tests just because they installed a new patch version of mockery. For the record, this kind of change is why I prefer using Ferver over Semver. Breaking changes should not be something to be afraid of, you just have to ensure that people don't get caught out by them. In Ferver, this would be a new minor version; if people wanted to update to the latest version, they would need to consciously change composer.json and can handle the consequences of that appropriately.
Seeing as this is outstanding, please see #1192 |
Mockery 1.5.1 requires count of shouldReceive calls. mockery/mockery#1190
* Fix risky tests Mockery 1.5.1 requires count of shouldReceive calls. mockery/mockery#1190 * Fix orchestra testbench View the resolved discussion about it: orchestral/testbench-core#88 (review) Co-authored-by: Daniel de Wit <daniel@muman.nl>
The issue is, if you have other assertions in your test, then PHPUnit will happily mark the test as successful, even though the expectation failed: interface I {
public function test(): void;
}
class MyTest extends TestCase
{
public function test(): void
{
$i = Mockery::mock(I::class);
$i->shouldReceive('test');
self::assertTrue(true);
Mockery::close(); // will not complain, and PHPUnit will mark the test as successful!
}
} Calling I can see a couple ways to solve this:
Also, if Thoughts? |
We often use a blank If we did go down this route, I think we would also need to add an $mock = Mockery::mock(Example::class);
// Currently, the two following expectations would be identical
// If we assign `->once()` by default, the latter allows for method calls we don't need to worry about in this test
$mock->shouldReceive('test');
$mock->shouldReceive('test')->any(); |
I compared 1.5.1 to 1.5.0 and it seems the only function change is this #1180
I'm getting "This test did not perform any assertions" for tests that contain
->shouldReceive
calls.It was counted towards assertions in all previouis Mockery versions.
The text was updated successfully, but these errors were encountered: