Skip to content

Commit

Permalink
Merge pull request #396 from gsteel/not-empty-message-templates
Browse files Browse the repository at this point in the history
`NotEmpty` Validator Input Filter Affordances
  • Loading branch information
gsteel authored Oct 21, 2024
2 parents 0f73c25 + f0187df commit 0303bc6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/NotEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,22 @@ public function isValid(mixed $value): bool

return true;
}

/**
* Return the configured message templates
*
* This method is an affordance to laminas-inputfilter.
* It needs to introspect configured message templates in order to provide a default error message for empty inputs.
*
* In future versions of laminas-validator, this method will likely be deprecated and removed. Please avoid.
*
* @internal
*
* @psalm-internal \Laminas
* @return array<string, string>
*/
public function getMessageTemplates(): array
{
return $this->messageTemplates;
}
}
9 changes: 9 additions & 0 deletions test/NotEmptyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,4 +695,13 @@ public static function arrayConfigNotationWithoutKeyProvider(): array
[null, true],
];
}

public function testRetrievalOfMessageTemplates(): void
{
/** @psalm-suppress InternalMethod */
$templates = (new NotEmpty())->getMessageTemplates();
self::assertNotSame([], $templates);
self::assertArrayHasKey(NotEmpty::IS_EMPTY, $templates);
self::assertArrayHasKey(NotEmpty::INVALID, $templates);
}
}

0 comments on commit 0303bc6

Please sign in to comment.