once() ->andReturn(true); $request = new TwoFAccountExportRequest; $this->assertTrue($request->authorize()); } #[Test] #[DataProvider('provideValidData')] public function test_valid_data(array $data) : void { $request = new TwoFAccountExportRequest; $validator = Validator::make($data, $request->rules()); $this->assertFalse($validator->fails()); } /** * Provide Valid data for validation test */ public static function provideValidData() : array { return [ [[ 'ids' => '1', 'otpauth' => '1', ]], [[ 'ids' => '1', 'otpauth' => 1, ]], [[ 'ids' => '1', 'otpauth' => true, ]], [[ 'ids' => '1', ]], [[ 'ids' => '1', 'otpauth' => '0', ]], [[ 'ids' => '1', 'otpauth' => 0, ]], [[ 'ids' => '1', 'otpauth' => false, ]], ]; } #[Test] #[DataProvider('provideInvalidData')] public function test_invalid_data(array $data) : void { $request = new TwoFAccountExportRequest; $validator = Validator::make($data, $request->rules()); $this->assertTrue($validator->fails()); } /** * Provide invalid data for validation test */ public static function provideInvalidData() : array { return [ [[ 'ids' => '1', 'otpauth' => null, ]], [[ 'ids' => '1', 'otpauth' => '', ]], [[ 'ids' => '1', 'otpauth' => 2, ]], [[ 'ids' => '1', 'otpauth' => 'string', ]], [[ 'ids' => '1', 'otpauth' => 0.1, ]], [[ 'ids' => '1', 'otpauth' => '01/01/2020', ]], [[ 'ids' => '1', 'otpauth' => '01', ]], ]; } }