Skip to content

[Validator] Add SemVer constraint for semantic versioning validation #60995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 28 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
74b2af6
[Validator] Add SemVer constraint for semantic versioning validation
OskarStark Jun 30, 2025
5a1aa4a
Add newlines at EOF and improve code formatting
OskarStark Jun 30, 2025
2ac6a74
Import DataProvider attribute and use short syntax
OskarStark Jun 30, 2025
1e3e416
fix
OskarStark Jun 30, 2025
bf610d8
-
OskarStark Jun 30, 2025
94fd2ac
Fix SemVer validation pattern and tests
OskarStark Jun 30, 2025
949d5e9
Simplify SemVer constraint to use single 'strict' option
OskarStark Jul 1, 2025
c287e8d
Update src/Symfony/Component/Validator/Constraints/SemVerValidator.php
OskarStark Jul 1, 2025
4e5ec8b
Change default value of strict option to true
OskarStark Jul 1, 2025
a1e9e3a
Remove array-based configuration support from SemVer constraint
OskarStark Jul 1, 2025
980da3b
Remove unnecessary comment
OskarStark Jul 1, 2025
24ae6af
Use x modifier for regex patterns to improve readability
OskarStark Jul 1, 2025
29fa35a
Apply stof's suggestions for better compatibility
OskarStark Jul 1, 2025
a1150a8
Apply suggestions from code review
OskarStark Jul 1, 2025
16a50f5
Update src/Symfony/Component/Validator/Constraints/SemVer.php
OskarStark Jul 2, 2025
eb7cb3a
Add min/max version constraints to SemVer validator
OskarStark Jul 2, 2025
c662126
Rename tooHighMessage/tooLowMessage to minMessage/maxMessage and make…
OskarStark Jul 2, 2025
b944f69
Update src/Symfony/Component/Validator/Tests/Constraints/SemVerValida…
OskarStark Jul 2, 2025
2481bab
Move expectException calls directly before the code that triggers the…
OskarStark Jul 2, 2025
ccf6364
Add tests for custom message, minMessage and maxMessage
OskarStark Jul 2, 2025
5fc3119
Follow Symfony constraint pattern: initialize message properties with…
OskarStark Jul 2, 2025
7b2c9d2
Update src/Symfony/Component/Validator/Tests/Constraints/SemVerValida…
OskarStark Jul 3, 2025
dd3a772
Update src/Symfony/Component/Validator/Tests/Constraints/SemVerValida…
OskarStark Jul 3, 2025
bcd66da
Remove unnecessary comments as requested in code review
OskarStark Jul 3, 2025
f87dff0
Apply code review feedback from fabpot and nicolas-grekas
OskarStark Jul 7, 2025
2af8ece
Add documentation for SemVer constraint options
OskarStark Jul 7, 2025
8d04e1e
Refactor SemVer constraint to use non-nullable constructor arguments
OskarStark Jul 8, 2025
09dbe1c
Fix parameter order: keep nullable parameters at the end
OskarStark Jul 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for custom message, minMessage and maxMessage
  • Loading branch information
OskarStark committed Jul 8, 2025
commit ccf636442f149dcf9659cb7478d03dd372614acf
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,50 @@ public function testInvalidStrictSemVersions(string $version)
->assertRaised();
}

public function testCustomInvalidMessage()
{
$constraint = new SemVer(message: 'Custom invalid version message');

$this->validator->validate('invalid-version', $constraint);

$this->buildViolation('Custom invalid version message')
->setParameter('{{ value }}', '"invalid-version"')
->setCode(SemVer::INVALID_SEMVER_ERROR)
->assertRaised();
}

public function testCustomMinMessage()
{
$constraint = new SemVer(
minMessage: 'Custom minimum version message',
min: '2.0.0'
);

$this->validator->validate('1.0.0', $constraint);

$this->buildViolation('Custom minimum version message')
->setParameter('{{ value }}', '"1.0.0"')
->setParameter('{{ min }}', '2.0.0')
->setCode(SemVer::TOO_LOW_ERROR)
->assertRaised();
}

public function testCustomMaxMessage()
{
$constraint = new SemVer(
maxMessage: 'Custom maximum version message',
max: '1.0.0'
);

$this->validator->validate('2.0.0', $constraint);

$this->buildViolation('Custom maximum version message')
->setParameter('{{ value }}', '"2.0.0"')
->setParameter('{{ max }}', '1.0.0')
->setCode(SemVer::TOO_HIGH_ERROR)
->assertRaised();
}

public static function getValidLooseSemVersions(): iterable
{
// Full versions
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy