assertEquals(self::STRING_ENCODED, QrCode::encode(self::STRING_TO_ENCODE)); } #[Test] public function test_decode_valid_image_returns_correct_value() { $file = LocalFile::fake()->validQrcode(); $this->assertEquals(self::DECODED_IMAGE, QrCode::decode($file)); } #[Test] public function test_decode_invalid_image_throws_an_exception() { $this->expectException(\App\Exceptions\InvalidQrCodeException::class); QrCode::decode(LocalFile::fake()->invalidQrcode()); } #[Test] #[DataProvider('QrReaderExceptionProvider')] public function test_decodee_throws_an_exception($exception) { $this->expectException(\App\Exceptions\InvalidQrCodeException::class); // QrReader is a final class, so we need to mock it here with a new object instance // to then bind it to the container $fileContent = LocalFile::fake()->validQrcode()->get(); $qrReader = \Mockery::mock(new QrReader($fileContent, QrReader::SOURCE_TYPE_BLOB))->makePartial(); $qrReader->shouldReceive('text')->andReturn(''); $qrReader->shouldReceive('getError')->andReturn($exception); $this->app->bind(QrReader::class, function() use($qrReader) { return $qrReader; }); QrCode::decode(LocalFile::fake()->validQrcode()); } /** * */ public static function QrReaderExceptionProvider() { return [ 'NotFoundException' => [new NotFoundException()], 'FormatException' => [new FormatException()], 'ChecksumException' => [new ChecksumException()], 'default' => [new Exception()], ]; } }