mirror of
https://github.com/doctrine/reflection.git
synced 2026-03-24 08:42:07 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55e71912df | ||
|
|
fbc77cc1c8 | ||
|
|
1a5837f909 | ||
|
|
1ab281861b |
@@ -16,7 +16,7 @@ build:
|
||||
- phpcs-run
|
||||
dependencies:
|
||||
override:
|
||||
- composer install -noa
|
||||
- COMPOSER_ROOT_VERSION=1.2 composer install -noa
|
||||
|
||||
tools:
|
||||
external_code_coverage:
|
||||
|
||||
@@ -2,6 +2,10 @@ dist: trusty
|
||||
sudo: false
|
||||
language: php
|
||||
|
||||
env:
|
||||
global:
|
||||
- COMPOSER_ROOT_VERSION=1.2
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache
|
||||
|
||||
@@ -31,7 +31,7 @@ class TypedNoDefaultReflectionProperty extends ReflectionProperty
|
||||
*/
|
||||
public function setValue($object, $value = null)
|
||||
{
|
||||
if ($value === null) {
|
||||
if ($value === null && $this->hasType() && ! $this->getType()->allowsNull()) {
|
||||
$propertyName = $this->getName();
|
||||
|
||||
$unsetter = function () use ($propertyName) {
|
||||
|
||||
@@ -32,9 +32,26 @@ class TypedNoDefaultReflectionPropertyTest extends TestCase
|
||||
$object = new TypedFoo();
|
||||
$object->setId(1);
|
||||
|
||||
self::assertTrue($reflection->isInitialized($object));
|
||||
|
||||
$reflection->setValue($object, null);
|
||||
|
||||
self::assertNull($reflection->getValue($object));
|
||||
self::assertFalse($reflection->isInitialized($object));
|
||||
}
|
||||
|
||||
public function testSetValueNullOnNullableProperty() : void
|
||||
{
|
||||
$reflection = new TypedNoDefaultReflectionProperty(TypedNullableFoo::class, 'value');
|
||||
$reflection->setAccessible(true);
|
||||
|
||||
$object = new TypedNullableFoo();
|
||||
|
||||
$reflection->setValue($object, null);
|
||||
|
||||
self::assertNull($reflection->getValue($object));
|
||||
self::assertTrue($reflection->isInitialized($object));
|
||||
self::assertNull($object->getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,3 +69,18 @@ class TypedFoo
|
||||
$this->id = $id;
|
||||
}
|
||||
}
|
||||
|
||||
class TypedNullableFoo
|
||||
{
|
||||
private ?string $value;
|
||||
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user