QrCodeDecodeRequestTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace Tests\Api\v1\Requests;
  3. use App\Api\v1\Requests\QrCodeDecodeRequest;
  4. use Illuminate\Foundation\Testing\WithoutMiddleware;
  5. use Illuminate\Support\Facades\Auth;
  6. use Illuminate\Support\Facades\Validator;
  7. use PHPUnit\Framework\Attributes\CoversClass;
  8. use PHPUnit\Framework\Attributes\DataProvider;
  9. use PHPUnit\Framework\Attributes\Test;
  10. use Tests\Classes\LocalFile;
  11. use Tests\TestCase;
  12. /**
  13. * QrCodeDecodeRequestTest test class
  14. */
  15. #[CoversClass(QrCodeDecodeRequest::class)]
  16. class QrCodeDecodeRequestTest extends TestCase
  17. {
  18. use WithoutMiddleware;
  19. #[Test]
  20. public function test_user_is_authorized()
  21. {
  22. Auth::shouldReceive('check')
  23. ->once()
  24. ->andReturn(true);
  25. $request = new QrCodeDecodeRequest;
  26. $this->assertTrue($request->authorize());
  27. }
  28. #[Test]
  29. #[DataProvider('provideValidData')]
  30. public function test_valid_data(array $data) : void
  31. {
  32. $request = new QrCodeDecodeRequest;
  33. $request->merge($data);
  34. $validator = Validator::make($data, $request->rules());
  35. $this->assertFalse($validator->fails());
  36. }
  37. /**
  38. * Provide Valid data for validation test
  39. */
  40. public static function provideValidData() : array
  41. {
  42. $file = LocalFile::fake()->validQrcode();
  43. return [
  44. [[
  45. 'qrcode' => $file,
  46. ]],
  47. ];
  48. }
  49. #[Test]
  50. #[DataProvider('provideInvalidData')]
  51. public function test_invalid_data(array $data) : void
  52. {
  53. $request = new QrCodeDecodeRequest;
  54. $request->merge($data);
  55. $validator = Validator::make($data, $request->rules());
  56. $this->assertTrue($validator->fails());
  57. }
  58. /**
  59. * Provide invalid data for validation test
  60. */
  61. public static function provideInvalidData() : array
  62. {
  63. return [
  64. [[
  65. 'qrcode' => null, // required
  66. ]],
  67. [[
  68. 'qrcode' => true, // image
  69. ]],
  70. [[
  71. 'qrcode' => 8, // image
  72. ]],
  73. [[
  74. 'qrcode' => 'string', // image
  75. ]],
  76. ];
  77. }
  78. }