Skip to content
Advertisement

phpunit, laravel: Cannot use “parent” when current class scope has no parent

I’m using PHPUnit 6.5.13 and Laravel 5.5 on PHP 7.4. I recently upgraded from PHP 7.2 to 7.4. and it seems like that triggered the error.

In my test I use $this->expectsEvents in order to test that an event is fired. The test class looks a little like this:

JavaScript

OrderReSent looks like this (I’ve tried commenting out broadcastOn and remove InteractsWithSockets use, no change in result):

JavaScript

The only place I see parent::__construct being called is in IlluminateBroadcastingPrivateChannel, which extends IlluminateBroadcastingChannel (and it is a child class, so I don’t understand why it would throw this error):

JavaScript

The stacktrace looks like this and makes me believe Mockery is the culprit:

JavaScript

Advertisement

Answer

I had same issue – it turned out that mockery/mockery was set to version 0.9 in my composer.json. Upgrading mockery/mockery to version 1.3 solved the problem for me.

Related composer.json fragment:

JavaScript

Try setting same versions and run composer update

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement