Skip to content

Commit e7816d4

Browse files
AxaliaNMichel Maas
andauthored
Makes the bundle compatible with Symfony 5.3+ (#6)
* Makes the bundle compatible with Symfony 5.3+ * Casts the value to string, because Symfony requires it to be a string * Allows PHP 8 Co-authored-by: Michel Maas <[email protected]>
1 parent 6fc517a commit e7816d4

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/vendor/
22
/composer.lock
33
/php_cs.cache
4+
.phpunit.result.cache

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
}
1515
],
1616
"require": {
17-
"php": "^7.2",
18-
"symfony/validator": "^3.4 || ^4.3",
17+
"php": "^7.2||^8.0",
18+
"symfony/validator": "^3.4 || ^4.3 || ^5.0",
1919
"doctrine/orm": "^2.4"
2020
},
2121
"require-dev": {
22-
"symfony/phpunit-bridge": "^4.3"
22+
"symfony/phpunit-bridge": "^4.3 || ^5.0"
2323
},
2424
"autoload": {
2525
"psr-4": {

src/EntityExistValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function validate($value, Constraint $constraint): void
4343
$this->context->buildViolation($constraint->message)
4444
->setParameter('%entity%', $constraint->entity)
4545
->setParameter('%property%', $constraint->property)
46-
->setParameter('%value%', $value)
46+
->setParameter('%value%', (string) $value)
4747
->addViolation();
4848
}
4949
}

tests/EntityExistValidatorTest.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ protected function setUp(): void
3434
$this->validator->initialize($this->context);
3535
}
3636

37-
public function testValidateWithWrongConstraint()
37+
public function testValidateWithWrongConstraint(): void
3838
{
3939
$this->expectException(\LogicException::class);
4040
$this->validator->validate('foo', new NotNull());
4141
}
4242

43-
public function testValidateWithNoEntity()
43+
public function testValidateWithNoEntity(): void
4444
{
4545
$constraint = new EntityExist();
4646

4747
$this->expectException(\LogicException::class);
4848
$this->validator->validate('foobar', $constraint);
4949
}
5050

51-
public function testValidateValidEntity()
51+
public function testValidateValidEntity(): void
5252
{
5353
$this->context->expects($this->never())->method('buildViolation');
5454
$constraint = new EntityExist();
@@ -57,6 +57,7 @@ public function testValidateValidEntity()
5757
$repository = $this->getMockBuilder(EntityRepository::class)
5858
->disableOriginalConstructor()
5959
->getMock();
60+
6061
$repository
6162
->expects($this->once())
6263
->method('findOneBy')
@@ -75,7 +76,7 @@ public function testValidateValidEntity()
7576
/**
7677
* @dataProvider getEmptyOrNull
7778
*/
78-
public function testValidateSkipsIfValueEmptyOrNull($value)
79+
public function testValidateSkipsIfValueEmptyOrNull($value): void
7980
{
8081
$this->context->expects($this->never())->method('buildViolation');
8182
$constraint = new EntityExist();
@@ -84,6 +85,7 @@ public function testValidateSkipsIfValueEmptyOrNull($value)
8485
$repository = $this->getMockBuilder(EntityRepository::class)
8586
->disableOriginalConstructor()
8687
->getMock();
88+
8789
$repository
8890
->expects($this->exactly(0))
8991
->method('findOneBy')
@@ -99,13 +101,13 @@ public function testValidateSkipsIfValueEmptyOrNull($value)
99101
$this->validator->validate($value, $constraint);
100102
}
101103

102-
public function getEmptyOrNull()
104+
public function getEmptyOrNull(): \Generator
103105
{
104106
yield [''];
105107
yield [null];
106108
}
107109

108-
public function testValidateValidEntityWithCustomProperty()
110+
public function testValidateValidEntityWithCustomProperty(): void
109111
{
110112
$this->context->expects($this->never())->method('buildViolation');
111113
$constraint = new EntityExist();
@@ -115,6 +117,7 @@ public function testValidateValidEntityWithCustomProperty()
115117
$repository = $this->getMockBuilder(EntityRepository::class)
116118
->disableOriginalConstructor()
117119
->getMock();
120+
118121
$repository
119122
->expects($this->once())
120123
->method('findOneBy')
@@ -130,7 +133,7 @@ public function testValidateValidEntityWithCustomProperty()
130133
$this->validator->validate('foobar', $constraint);
131134
}
132135

133-
public function testValidateInvalidEntity()
136+
public function testValidateInvalidEntity(): void
134137
{
135138
$violationBuilder = $this->getMockBuilder(ConstraintViolationBuilderInterface::class)->getMock();
136139
$violationBuilder->method('setParameter')->will($this->returnSelf());
@@ -142,6 +145,7 @@ public function testValidateInvalidEntity()
142145
$repository = $this->getMockBuilder(EntityRepository::class)
143146
->disableOriginalConstructor()
144147
->getMock();
148+
145149
$repository
146150
->expects($this->once())
147151
->method('findOneBy')
@@ -152,6 +156,6 @@ public function testValidateInvalidEntity()
152156
->method('getRepository')
153157
->willReturn($repository);
154158

155-
$this->validator->validate('foobar', $constraint);
159+
$this->validator->validate(1, $constraint);
156160
}
157161
}

0 commit comments

Comments
 (0)