'EUR', ], [ 'currency' => [new CurrencyRule], ]); // Act $isValid = $validator->passes(); $messages = $validator->messages()->toArray(); // Assert $this->assertTrue($isValid); $this->assertArrayNotHasKey('currency', $messages); } public function test_validation_fails_if_value_is_not_a_string(): void { // Arrange $validator = Validator::make([ 'currency' => true, ], [ 'currency' => [new CurrencyRule], ]); // Act $isValid = $validator->passes(); $messages = $validator->messages()->toArray(); // Assert $this->assertFalse($isValid); $this->assertEquals('The currency field must be a string.', $messages['currency'][0]); } public function test_validation_fails_if_value_is_not_a_valid_currency(): void { // Arrange $validator = Validator::make([ 'currency' => 'XXX', ], [ 'currency' => [new CurrencyRule], ]); // Act $isValid = $validator->passes(); $messages = $validator->messages()->toArray(); // Assert $this->assertFalse($isValid); $this->assertEquals('The currency field must be a valid currency code (ISO 4217).', $messages['currency'][0]); } public function test_validation_fails_if_value_is_lower_case(): void { // Arrange $validator = Validator::make([ 'currency' => 'eur', ], [ 'currency' => [new CurrencyRule], ]); // Act $isValid = $validator->passes(); $messages = $validator->messages()->toArray(); // Assert $this->assertFalse($isValid); $this->assertEquals('The currency field must be a valid currency code (ISO 4217).', $messages['currency'][0]); } }