public function testItUsesMaxQualityIfFileSizeHasNoNetDecreaseInRequestedCompressionRange() { $file = $this->getImageFile(300, 500); $image = new Image($file, false); $new_handler = Mockery::mock(Imagick::class); $image->setImageHandler($new_handler); $new_handler->shouldReceive('getimageblob')->once()->andReturn(openssl_random_pseudo_bytes(1600)); $new_handler->shouldReceive('setimagecompressionquality')->once()->with(5); $new_handler->shouldReceive('getimageblob')->once()->andReturn(openssl_random_pseudo_bytes(1800)); $new_handler->shouldReceive('setimagecompressionquality')->once()->with(6); $new_handler->shouldReceive('getimageblob')->once()->andReturn(openssl_random_pseudo_bytes(1700)); $new_handler->shouldReceive('setimagecompressionquality')->once()->with(7); $new_handler->shouldReceive('getimageblob')->once()->andReturn(openssl_random_pseudo_bytes(1650)); $new_handler->shouldReceive('setimagecompressionquality')->once()->with(8); $new_handler->shouldReceive('getimageblob')->once()->andReturn(openssl_random_pseudo_bytes(1625)); // Should finally set the min compression (max quality) because we don't gain anything by compressing further $new_handler->shouldReceive('setimagecompressionquality')->once()->with(8); $return = $image->setQualityLevel(5, 8, 1500); $this->assertEquals($image, $return); }