SettingUpdateRequestTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace Tests\Api\v1\Requests;
  3. use App\Api\v1\Requests\SettingStoreRequest;
  4. use App\Api\v1\Requests\SettingUpdateRequest;
  5. use Illuminate\Foundation\Testing\WithoutMiddleware;
  6. use Illuminate\Support\Facades\Auth;
  7. use Illuminate\Support\Facades\Validator;
  8. use PHPUnit\Framework\Attributes\CoversClass;
  9. use PHPUnit\Framework\Attributes\DataProvider;
  10. use PHPUnit\Framework\Attributes\Test;
  11. use Tests\TestCase;
  12. /**
  13. * SettingUpdateRequestTest test class
  14. */
  15. #[CoversClass(SettingStoreRequest::class)]
  16. class SettingUpdateRequestTest 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 SettingUpdateRequest();
  26. $this->assertTrue($request->authorize());
  27. }
  28. #[Test]
  29. #[DataProvider('provideValidData')]
  30. public function test_valid_data(array $data) : void
  31. {
  32. $request = new SettingUpdateRequest();
  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. return [
  42. [[
  43. 'value' => true,
  44. ]],
  45. [[
  46. 'value' => 'MyValue',
  47. ]],
  48. [[
  49. 'value' => 10,
  50. ]],
  51. ];
  52. }
  53. #[Test]
  54. #[DataProvider('provideInvalidData')]
  55. public function test_invalid_data(array $data) : void
  56. {
  57. $request = new SettingUpdateRequest();
  58. $validator = Validator::make($data, $request->rules());
  59. $this->assertTrue($validator->fails());
  60. }
  61. /**
  62. * Provide invalid data for validation test
  63. */
  64. public static function provideInvalidData() : array
  65. {
  66. return [
  67. [[
  68. 'value' => '', // required
  69. ]],
  70. [[
  71. 'value' => null, // required
  72. ]],
  73. ];
  74. }
  75. }