Skip to content

Commit

Permalink
Manual fix
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Aug 31, 2020
1 parent 2a7ee2d commit 4cb7047
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/EventDispatcher/Subscriber/DoctrineProxySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function onPreSerialize(PreSerializeEvent $event): void
if ($object instanceof LazyLoadingInterface) {
$object->initializeProxy();
} else {
$object->__load();
$object->load();
}

if (!$virtualType) {
Expand Down
2 changes: 0 additions & 2 deletions src/Metadata/Driver/AbstractDoctrineTypeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ public function loadMetadataForClass(\ReflectionClass $class): ?BaseClassMetadat
// We base our scan on the internal driver's property list so that we
// respect any internal white/blacklisting like in the AnnotationDriver
foreach ($classMetadata->propertyMetadata as $key => $propertyMetadata) {
/** @var PropertyMetadata $propertyMetadata */

// If the inner driver provides a type, don't guess anymore.
if ($propertyMetadata->type || $this->isVirtualProperty($propertyMetadata)) {
continue;
Expand Down
8 changes: 1 addition & 7 deletions src/Metadata/Driver/TypedPropertiesDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ public function loadMetadataForClass(ReflectionClass $class): ?ClassMetadata
// We base our scan on the internal driver's property list so that we
// respect any internal white/blacklisting like in the AnnotationDriver
foreach ($classMetadata->propertyMetadata as $key => $propertyMetadata) {
/** @var PropertyMetadata $propertyMetadata */

// If the inner driver provides a type, don't guess anymore.
if ($propertyMetadata->type || $this->isVirtualProperty($propertyMetadata)) {
continue;
Expand Down Expand Up @@ -100,11 +98,7 @@ private function shouldTypeHint(ReflectionProperty $propertyReflection): bool
return true;
}

if (class_exists($propertyReflection->getType()->getName())) {
return true;
}

return false;
return class_exists($propertyReflection->getType()->getName());
}

private function getReflection(PropertyMetadata $propertyMetadata): ReflectionProperty
Expand Down
18 changes: 9 additions & 9 deletions tests/Fixtures/ObjectWithEmptyNullableAndEmptyArrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,53 @@ class ObjectWithEmptyNullableAndEmptyArrays
* @Serializer\XmlList(inline = true, entry = "comment")
* @Serializer\Type("array")
*/
public $null_inline = null;
public $nullInline = null;

/**
* @Serializer\XmlList(inline = true, entry = "comment")
* @Serializer\Type("array")
*/
public $empty_inline = [];
public $emptyInline = [];

/**
* @Serializer\XmlList(inline = true, entry = "comment")
* @Serializer\Type("array")
*/
public $not_empty_inline = ['not_empty_inline'];
public $notEmptyInline = ['not_empty_inline'];

/**
* @Serializer\XmlList(inline = false, entry = "comment")
* @Serializer\Type("array")
*/
public $null_not_inline = null;
public $nullNotInline = null;

/**
* @Serializer\XmlList(inline = false, entry = "comment")
* @Serializer\Type("array")
*/
public $empty_not_inline = [];
public $emptyNotInline = [];

/**
* @Serializer\XmlList(inline = false, entry = "comment", skipWhenEmpty=false)
* @Serializer\Type("array")
*/
public $not_empty_not_inline = ['not_empty_not_inline'];
public $notEmptyNotInline = ['not_empty_not_inline'];

/**
* @Serializer\XmlList(inline = false, entry = "comment", skipWhenEmpty=false)
* @Serializer\Type("array")
*/
public $null_not_inline_skip = null;
public $nullNotInlineSkip = null;

/**
* @Serializer\XmlList(inline = false, entry = "comment", skipWhenEmpty=false)
* @Serializer\Type("array")
*/
public $empty_not_inline_skip = [];
public $emptyNotInlineSkip = [];

/**
* @Serializer\XmlList(inline = false, entry = "comment", skipWhenEmpty=false)
* @Serializer\Type("array")
*/
public $not_empty_not_inline_skip = ['not_empty_not_inline_skip'];
public $notEmptyNotInlineSkip = ['not_empty_not_inline_skip'];
}
18 changes: 9 additions & 9 deletions tests/Fixtures/SimpleObjectLazyLoading.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@

class SimpleObjectLazyLoading extends SimpleObject implements LazyLoadingInterface
{
public $__isInitialized__ = false;
private $isInitialized = false;

private $initializer;

private $baz = 'baz';

public function __load()
public function load()
{
if (!$this->__isInitialized__) {
if (!$this->isInitialized) {
$this->camelCase = 'proxy-boo';
$this->__isInitialized__ = true;
$this->isInitialized = true;
}
}

public function __isInitialized()
public function isInitialized()
{
return $this->__isInitialized__;
return $this->isInitialized;
}

/**
Expand All @@ -43,9 +43,9 @@ public function getProxyInitializer(): ?Closure

public function initializeProxy(): bool
{
if (!$this->__isInitialized__) {
if (!$this->isInitialized) {
$this->camelCase = 'proxy-boo';
$this->__isInitialized__ = true;
$this->isInitialized = true;

return !$this->initializer || call_user_func($this->initializer);
}
Expand All @@ -55,6 +55,6 @@ public function initializeProxy(): bool

public function isProxyInitialized(): bool
{
return $this->__isInitialized__;
return $this->isInitialized;
}
}
12 changes: 6 additions & 6 deletions tests/Fixtures/SimpleObjectProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@

class SimpleObjectProxy extends SimpleObject implements Proxy
{
public $__isInitialized__ = false;
private $isInitialized = false;

private $baz = 'baz';

public function __load()
public function load()
{
if (!$this->__isInitialized__) {
if (!$this->isInitialized) {
$this->camelCase = 'proxy-boo';
$this->__isInitialized__ = true;
$this->isInitialized = true;
}
}

public function __isInitialized()
public function isInitialized()
{
return $this->__isInitialized__;
return $this->isInitialized;
}
}
8 changes: 4 additions & 4 deletions tests/Handler/FormErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use JMS\Serializer\JsonSerializationVisitor;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\Visitor\Factory\JsonSerializationVisitorFactory;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -146,12 +147,11 @@ public function testSerializeChildElements()

public function testDefaultTranslationDomain()
{
/** @var Translator|\PHPUnit_Framework_MockObject_MockObject $translator */

$interface = interface_exists(TranslatorInterface::class)
? TranslatorInterface::class
: LegacyTranslatorInterface::class;
$translator = $this->getMockBuilder($interface)->getMock();
\assert($translator instanceof Translator || $translator instanceof MockObject);

$handler = new FormErrorHandler($translator);

Expand All @@ -173,11 +173,11 @@ public function testDefaultTranslationDomain()

public function testDefaultTranslationDomainWithPluralTranslation()
{
/** @var Translator|\PHPUnit_Framework_MockObject_MockObject $translator */
$interface = interface_exists(TranslatorInterface::class)
? TranslatorInterface::class
: LegacyTranslatorInterface::class;
$translator = $this->getMockBuilder($interface)->getMock();
\assert($translator instanceof Translator || $translator instanceof MockObject);

$handler = new FormErrorHandler($translator);

Expand Down Expand Up @@ -210,11 +210,11 @@ public function testDefaultTranslationDomainWithPluralTranslation()

public function testCustomTranslationDomain()
{
/** @var Translator|\PHPUnit_Framework_MockObject_MockObject $translator */
$interface = interface_exists(TranslatorInterface::class)
? TranslatorInterface::class
: LegacyTranslatorInterface::class;
$translator = $this->getMockBuilder($interface)->getMock();
\assert($translator instanceof Translator || $translator instanceof MockObject);

$handler = new FormErrorHandler($translator, 'custom_domain');

Expand Down
16 changes: 9 additions & 7 deletions tests/Serializer/BaseSerializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;

use function assert;

abstract class BaseSerializationTest extends TestCase
{
protected $factory;
Expand Down Expand Up @@ -159,8 +161,8 @@ public function testSerializeNullArray()

public function testNoMetadataNeededWhenDeSerializingNotUsedProperty()
{
/** @var ParentNoMetadataChildObject $dObj */
$object = $this->deserialize($this->getContent('ParentNoMetadataChildObject'), ParentNoMetadataChildObject::class);
assert($object instanceof ParentNoMetadataChildObject);

self::assertSame('John', $object->bar);
self::assertNull($object->foo);
Expand All @@ -173,7 +175,7 @@ public function testDeserializeObjectWithMissingTypedArrayProp()
ObjectWithTypedArraySetter::class,
$this->getFormat()
);
\assert($dObj instanceof ObjectWithTypedArraySetter);
assert($dObj instanceof ObjectWithTypedArraySetter);

self::assertInstanceOf(ObjectWithTypedArraySetter::class, $dObj);

Expand Down Expand Up @@ -224,7 +226,7 @@ public function testDeserializeNullObject()
ObjectWithNullProperty::class,
$this->getFormat()
);
\assert($dObj instanceof ObjectWithNullProperty);
assert($dObj instanceof ObjectWithNullProperty);

self::assertEquals($obj, $dObj);
self::assertNull($dObj->getNullProperty());
Expand Down Expand Up @@ -644,7 +646,7 @@ public function testDateTimeArrays()

if ($this->hasDeserializer()) {
$deserializedObject = $this->deserialize($this->getContent('array_datetimes_object'), 'Jms\Serializer\Tests\Fixtures\DateTimeArraysObject');
\assert($deserializedObject instanceof DateTimeArraysObject);
assert($deserializedObject instanceof DateTimeArraysObject);

/** deserialized object has a default timezone set depending on user's timezone settings. That's why we manually set the UTC timezone on the DateTime objects. */
foreach ($deserializedObject->getArrayWithDefaultDateTime() as $dateTime) {
Expand Down Expand Up @@ -678,7 +680,7 @@ public function testNamedDateTimeArrays()
}

$deserializedObject = $this->deserialize($this->getContent('array_named_datetimes_object'), 'Jms\Serializer\Tests\Fixtures\NamedDateTimeArraysObject');
\assert($deserializedObject instanceof NamedDateTimeArraysObject);
assert($deserializedObject instanceof NamedDateTimeArraysObject);

/** deserialized object has a default timezone set depending on user's timezone settings. That's why we manually set the UTC timezone on the DateTime objects. */
foreach ($deserializedObject->getNamedArrayWithFormattedDate() as $dateTime) {
Expand Down Expand Up @@ -710,7 +712,7 @@ public function testNamedDateTimeImmutableArrays()
}

$deserializedObject = $this->deserialize($this->getContent('array_named_datetimeimmutables_object'), 'Jms\Serializer\Tests\Fixtures\NamedDateTimeImmutableArraysObject');
\assert($deserializedObject instanceof NamedDateTimeArraysObject);
assert($deserializedObject instanceof NamedDateTimeArraysObject);

/** deserialized object has a default timezone set depending on user's timezone settings. That's why we manually set the UTC timezone on the DateTime objects. */
foreach ($deserializedObject->getNamedArrayWithFormattedDate() as $dateTime) {
Expand Down Expand Up @@ -1164,7 +1166,7 @@ public function testInitializedDoctrineProxy()
}

$object = new SimpleObjectProxy('foo', 'bar');
$object->__load();
$object->load();

self::assertEquals($this->getContent('orm_proxy'), $this->serialize($object));
}
Expand Down
18 changes: 9 additions & 9 deletions tests/Serializer/EventDispatcher/EventDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testDispatch()
$a = new MockListener();
$this->dispatcher->addListener('foo', [$a, 'Foo']);
$this->dispatch('bar');
$a->_verify('Listener is not called for other event.');
$a->verify('Listener is not called for other event.');

$b = new MockListener();
$this->dispatcher->addListener('pre', [$b, 'bar'], 'Bar');
Expand All @@ -68,10 +68,10 @@ public function testDispatch()
$b->foo($this->event, 'pre', 'Foo', 'json', $this->dispatcher);
$b->all($this->event, 'pre', 'Foo', 'json', $this->dispatcher);

$b->_replay();
$b->replay();
$this->dispatch('pre', 'Bar');
$this->dispatch('pre', 'Foo');
$b->_verify();
$b->verify();
}

public function testDispatchWithInstanceFilteringBothListenersInvoked()
Expand All @@ -88,9 +88,9 @@ public function testDispatchWithInstanceFilteringBothListenersInvoked()
$a->onlyProxy($event, 'pre', 'Bar', 'json', $this->dispatcher);
$a->all($event, 'pre', 'Bar', 'json', $this->dispatcher);

$a->_replay();
$a->replay();
$this->dispatch('pre', 'Bar', 'json', $event);
$a->_verify();
$a->verify();
}

public function testDispatchWithInstanceFilteringOnlyGenericListenerInvoked()
Expand All @@ -106,9 +106,9 @@ public function testDispatchWithInstanceFilteringOnlyGenericListenerInvoked()
// expected
$a->all($event, 'pre', 'Bar', 'json', $this->dispatcher);

$a->_replay();
$a->replay();
$this->dispatch('pre', 'Bar', 'json', $event);
$a->_verify();
$a->verify();
}

public function testListenerCanStopPropagation()
Expand Down Expand Up @@ -237,12 +237,12 @@ public function __call($method, array $args = [])
$this->actual[] = [$method, $args];
}

public function _replay()
public function replay()
{
$this->wasReplayed = true;
}

public function _verify($message = '')
public function verify($message = '')
{
Assert::assertSame($this->expected, $this->actual, $message);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Serializer/EventDispatcher/LazyEventDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testDispatchWithListenerAsService()

$this->dispatcher->addListener('foo', ['a', 'foo']);
$this->dispatch('bar');
$a->_verify('Listener is not called for other event.');
$a->verify('Listener is not called for other event.');

$b = new MockListener();
$this->registerListenerService('b', $b);
Expand All @@ -47,10 +47,10 @@ public function testDispatchWithListenerAsService()
$b->all($this->event, 'pre', 'Bar', 'json', $this->dispatcher);
$b->foo($this->event, 'pre', 'Foo', 'json', $this->dispatcher);
$b->all($this->event, 'pre', 'Foo', 'json', $this->dispatcher);
$b->_replay();
$b->replay();
$this->dispatch('pre', 'Bar');
$this->dispatch('pre', 'Foo');
$b->_verify();
$b->verify();
}

protected function createEventDispatcher()
Expand Down
Loading

0 comments on commit 4cb7047

Please sign in to comment.