QrCodeDecodeRequestTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. $validator = Validator::make($data, $request->rules());
  34. $this->assertFalse($validator->fails());
  35. }
  36. /**
  37. * Provide Valid data for validation test
  38. */
  39. public static function provideValidData() : array
  40. {
  41. $file = LocalFile::fake()->validQrcode();
  42. return [
  43. [[
  44. 'qrcode' => $file,
  45. ]],
  46. ];
  47. }
  48. #[Test]
  49. #[DataProvider('provideInvalidData')]
  50. public function test_invalid_data(array $data) : void
  51. {
  52. $request = new QrCodeDecodeRequest;
  53. $validator = Validator::make($data, $request->rules());
  54. $this->assertTrue($validator->fails());
  55. }
  56. /**
  57. * Provide invalid data for validation test
  58. */
  59. public static function provideInvalidData() : array
  60. {
  61. return [
  62. [[
  63. 'qrcode' => null, // required
  64. ]],
  65. [[
  66. 'qrcode' => true, // image
  67. ]],
  68. [[
  69. 'qrcode' => 8, // image
  70. ]],
  71. [[
  72. 'qrcode' => 'string', // image
  73. ]],
  74. ];
  75. }
  76. }