Intervention / image

PHP Image Processing
https://image.intervention.io
MIT License
13.84k stars 1.5k forks source link

Unable to mock final classes #1324

Closed clementlanot closed 5 months ago

clementlanot commented 5 months ago

Describe the bug Impossible to test with PHPUnit and Laravel.

Code Example

Image::shouldReceive('save')->andThrow(new NotWritableException());

Throw the error:

Mockery\Exception: The class \Intervention\Image\ImageManager is marked final and its methods cannot be replaced. Classes marked final can be passed in to \Mockery::mock() as instantiated objects to create a partial mock, but only if the mock is not subject to type hinting checks.

And using Mockery:

$m = Mockery::mock(new Image());

Throw the error:

Cannot redeclare Mockery_3_Intervention_Image_Laravel_Facades_Image::shouldReceive()

Expected behavior Perhaps we should not declare classes as final?

Environment (please complete the following information):

olivervogel commented 5 months ago

I think this is more a topic for Mockery. Also have a look at dg/bypass-finals.