2FAuth/tests/Feature/Services/QrCodeServiceTest.php

60 lines
16 KiB
PHP
Raw Normal View History

2021-11-30 17:39:33 +01:00
<?php
namespace Tests\Feature\Services;
use App\Facades\QrCode;
2023-08-01 11:28:27 +02:00
use App\Services\QrCodeService;
use PHPUnit\Framework\Attributes\CoversClass;
2022-11-22 15:15:52 +01:00
use Tests\Classes\LocalFile;
use Tests\FeatureTestCase;
2021-11-30 17:39:33 +01:00
/**
2023-08-01 11:28:27 +02:00
* QrCodeServiceTest test class
2021-11-30 17:39:33 +01:00
*/
2023-08-01 11:28:27 +02:00
#[CoversClass(QrCodeService::class)]
#[CoversClass(QrCode::class)]
2021-11-30 17:39:33 +01:00
class QrCodeServiceTest extends FeatureTestCase
{
private const STRING_TO_ENCODE = 'stringToEncode';
2022-11-22 15:15:52 +01:00
2024-05-29 09:27:56 +02:00
private const STRING_ENCODED = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGNsYXNzPSJxci1zdmcgcXJjb2RlIiB2aWV3Qm94PSIwIDAgMjUgMjUiIHByZXNlcnZlQXNwZWN0UmF0aW89InhNaWRZTWlkIj4KPHBhdGggY2xhc3M9InFyLWRhdGEgbGlnaHQgcXJjb2RlIiBmaWxsPSIjZmZmIiBkPSJNMTIgMiBoMSB2MSBoLTFaIE0xMyAyIGgxIHYxIGgtMVogTTEyIDMgaDEgdjEgaC0xWiBNMTMgMyBoMSB2MSBoLTFaIE0xMSA0IGgxIHYxIGgtMVogTTEzIDQgaDEgdjEgaC0xWiBNMTEgNSBoMSB2MSBoLTFaIE0xMiA1IGgxIHYxIGgtMVogTTE0IDUgaDEgdjEgaC0xWiBNMTQgNiBoMSB2MSBoLTFaIE0xMSA3IGgxIHYxIGgtMVogTTEyIDcgaDEgdjEgaC0xWiBNMTMgNyBoMSB2MSBoLTFaIE0xNCA3IG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DEgdjEgaC0xWiBNMyAxOSBoMSB2MSBoLTFaIE03IDE5IGgxIHYxIGgtMVogTTMgMjAgaDEgdjEgaC0xWiBNNyAyMCBoMSB2MSBoLTFaIE0zIDIxIGgxIHYxIGgtMVogTTQgMjEgaDEgdjEgaC0xWiBNNSAyMSBoMSB2MSBoLTFaIE02IDIxIGgxIHYxIGgtMVogTTcgMjEgaDEgdjEgaC0xWiIvPgo8cGF0aCBjbGFzcz0icXItc2VwYXJhdG9yIGxpZ2h0IHFyY29kZSIgZmlsbD0iI2ZmZiIgZD0iTTkgMiBoMSB2MSBoLTFaIE0xNSAyIGgxIHYxIGgtM
2022-11-22 15:15:52 +01:00
2021-11-30 17:39:33 +01:00
private const DECODED_IMAGE = 'otpauth://totp/test@test.com?secret=A4GRFHVIRBGY7UIW';
/**
* @test
*/
2022-12-13 12:07:29 +01:00
public function setUp() : void
2021-11-30 17:39:33 +01:00
{
parent::setUp();
}
/**
* @test
*/
public function test_encode_returns_correct_value()
{
$this->assertEquals(self::STRING_ENCODED, QrCode::encode(self::STRING_TO_ENCODE));
2021-11-30 17:39:33 +01:00
}
/**
* @test
*/
public function test_decode_valid_image_returns_correct_value()
{
$file = LocalFile::fake()->validQrcode();
$this->assertEquals(self::DECODED_IMAGE, QrCode::decode($file));
2021-11-30 17:39:33 +01:00
}
/**
* @test
*/
public function test_decode_invalid_image_returns_correct_value()
{
$this->expectException(\App\Exceptions\InvalidQrCodeException::class);
QrCode::decode(LocalFile::fake()->invalidQrcode());
2021-11-30 17:39:33 +01:00
}
2022-11-22 15:15:52 +01:00
}