QrCodeDecodeRequestTest.php 1.9 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 Tests\Classes\LocalFile;
  8. use Tests\TestCase;
  9. /**
  10. * @covers \App\Api\v1\Requests\QrCodeDecodeRequest
  11. */
  12. class QrCodeDecodeRequestTest extends TestCase
  13. {
  14. use WithoutMiddleware;
  15. /**
  16. * @test
  17. */
  18. public function test_user_is_authorized()
  19. {
  20. Auth::shouldReceive('check')
  21. ->once()
  22. ->andReturn(true);
  23. $request = new QrCodeDecodeRequest();
  24. $this->assertTrue($request->authorize());
  25. }
  26. /**
  27. * @dataProvider provideValidData
  28. */
  29. public function test_valid_data(array $data): void
  30. {
  31. $request = new QrCodeDecodeRequest();
  32. $validator = Validator::make($data, $request->rules());
  33. $this->assertFalse($validator->fails());
  34. }
  35. /**
  36. * Provide Valid data for validation test
  37. */
  38. public function provideValidData(): array
  39. {
  40. $file = LocalFile::fake()->validQrcode();
  41. return [
  42. [[
  43. 'qrcode' => $file,
  44. ]],
  45. ];
  46. }
  47. /**
  48. * @dataProvider provideInvalidData
  49. */
  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 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. }