Skip to content

Commit

Permalink
Disabling Accessor setter when value resolution falls back to the pro…
Browse files Browse the repository at this point in the history
…perty default value
  • Loading branch information
joaojacome committed Aug 10, 2022
1 parent e23f0d1 commit 47aed2b
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 8 deletions.
1 change: 1 addition & 0 deletions phpstan-7-4.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ parameters:
excludePaths:
- %currentWorkingDirectory%/tests/Fixtures/TypedProperties/UnionTypedProperties.php
- %currentWorkingDirectory%/tests/Fixtures/TypedProperties/ConstructorPromotion/Vase.php
- %currentWorkingDirectory%/tests/Fixtures/TypedProperties/ConstructorPromotion/DefaultValuesAndAccessors.php
- %currentWorkingDirectory%/tests/Fixtures/TypedProperties/UnionTypedProperties.php
- %currentWorkingDirectory%/tests/Metadata/Driver/UnionTypedPropertiesDriverTest.php
- %currentWorkingDirectory%/tests/Serializer/BaseSerializationTest.php
Expand Down
1 change: 0 additions & 1 deletion src/Accessor/DefaultAccessorStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use JMS\Serializer\DeserializationContext;
use JMS\Serializer\Exception\ExpressionLanguageRequiredException;
use JMS\Serializer\Exception\LogicException;
use JMS\Serializer\Exception\NotAcceptableException;
use JMS\Serializer\Exception\UninitializedPropertyException;
use JMS\Serializer\Expression\CompilableExpressionEvaluatorInterface;
use JMS\Serializer\Expression\Expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ public function setPromotedWithSetter(string $value): void
{
$this->promotedWithSetter = $value . '_fromsetter';
}
}
}
8 changes: 3 additions & 5 deletions tests/Fixtures/TypedProperties/ConstructorPromotion/Vase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,29 @@ class Vase
{
public function __construct(
public string $color,

#[JMS\Accessor(setter: 'setSize')]
public string $size,

public ?string $plant = null,
public string $typeOfSoil = 'potting mix',
public int $daysSincePotting = -1,

#[JMS\Accessor(setter: 'setWeight')]
public int $weight = 10,
) {
}

public function setWeight(int $weight): void
{
$this->weight = $weight+30;
$this->weight = $weight + 30;
}

public function setSize(string $size): void
{
if ($size === 'big') {
if ('big' === $size) {
$this->size = 'huge';

return;
}

$this->size = $size;
}
}
1 change: 0 additions & 1 deletion tests/Serializer/ArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public function testConstructorPromotionWithDefaultValuesOnly()
$this->markTestSkipped(sprintf('%s requires PHP 8.0', __METHOD__));
}

/** @var DefaultValuesAndAccessors $deserialized */
$deserialized = $this->serializer->fromArray([], DefaultValuesAndAccessors::class);

$expected = [
Expand Down

0 comments on commit 47aed2b

Please sign in to comment.