Skip to content

Commit f5c6227

Browse files
authored
Merge pull request #1595 from schmittjoh/fix-warnings-in-tests
Fix warnings in a test code
2 parents 8331493 + ed57a2b commit f5c6227

15 files changed

+38
-44
lines changed

tests/Expression/ExpressionEvaluatorTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace JMS\Serializer\Tests\Expression;
66

7-
use JMS\Serializer\Expression\Expression;
87
use JMS\Serializer\Expression\ExpressionEvaluator;
98
use PHPUnit\Framework\TestCase;
109
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
@@ -29,8 +28,6 @@ public function testEvaluate()
2928
public function testParse()
3029
{
3130
$parsed = $this->evaluator->parse('a + b', ['a', 'b']);
32-
self::assertInstanceOf(Expression::class, $parsed);
33-
3431
$evaluated = $this->evaluator->evaluateParsed($parsed, ['a' => 1, 'b' => 2]);
3532
self::assertSame(3, $evaluated);
3633
}

tests/Fixtures/IndexedCommentsBlogPost.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ class IndexedCommentsList
5959
public function addComment(Comment $comment)
6060
{
6161
$this->comments[] = $comment;
62-
$this->count += 1;
62+
++$this->count;
6363
}
6464
}

tests/Fixtures/ObjectWithEmptyArrayAndHash.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ObjectWithEmptyArrayAndHash
2828
* @Serializer\SkipWhenEmpty()
2929
*/
3030
#[Serializer\SkipWhenEmpty]
31-
private $object = [];
31+
private $object;
3232

3333
public function __construct()
3434
{

tests/Fixtures/TypedProperties/UnionTypedProperties.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class UnionTypedProperties
88
{
99
public bool|float|string|array|int $data;
1010

11-
private int|bool|float|string|null $nullableData = null;
11+
private int|bool|float|string|null $nullableData;
1212

1313
private string|false $valueTypedUnion;
1414

tests/Handler/FormErrorHandlerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,12 @@ protected function getMockForm($name = 'name'): MockObject
282282
$form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
283283
$config = $this->getMockBuilder('Symfony\Component\Form\FormConfigInterface')->getMock();
284284

285-
$form->expects($this->any())
285+
$form
286286
->method('getName')
287-
->will($this->returnValue($name));
288-
$form->expects($this->any())
287+
->willReturn($name);
288+
$form
289289
->method('getConfig')
290-
->will($this->returnValue($config));
290+
->willReturn($config);
291291

292292
return $form;
293293
}

tests/Metadata/Driver/BaseDriverTestCase.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ public function testVirtualProperty()
162162
self::assertArrayHasKey('virtualSerializedValue', $m->propertyMetadata);
163163
self::assertArrayHasKey('typedVirtualProperty', $m->propertyMetadata);
164164

165-
self::assertEquals($m->propertyMetadata['virtualSerializedValue']->serializedName, 'test', 'Serialized name is missing');
165+
self::assertEquals(
166+
'test',
167+
$m->propertyMetadata['virtualSerializedValue']->serializedName,
168+
'Serialized name is missing',
169+
);
166170

167171
$p = new VirtualPropertyMetadata($m->name, 'virtualValue');
168172
$p->getter = 'getVirtualValue';

tests/Metadata/Driver/DoctrinePHPCRDriverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ public function getAnnotationDriver()
122122
{
123123
if (class_exists(DoctrinePHPCRDriver::class)) {
124124
return new AnnotationDriver(new AnnotationReader(), new IdenticalPropertyNamingStrategy());
125-
} else {
126-
return new AnnotationOrAttributeDriver(new IdenticalPropertyNamingStrategy());
127125
}
126+
127+
return new AnnotationOrAttributeDriver(new IdenticalPropertyNamingStrategy());
128128
}
129129

130130
protected function getDoctrinePHPCRDriver()

tests/Serializer/BaseSerializationTestCase.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ public function testDeserializingNull()
975975
$builder->setObjectConstructor($objectConstructor);
976976
$this->serializer = $builder->build();
977977

978-
$post = new BlogPost('This is a nice title.', $author = new Author('Foo Bar'), new \DateTime('2011-07-30 00:00', new \DateTimeZone('UTC')), new Publisher('Bar Foo'));
978+
$post = new BlogPost('This is a nice title.', new Author('Foo Bar'), new \DateTime('2011-07-30 00:00', new \DateTimeZone('UTC')), new Publisher('Bar Foo'));
979979

980980
$this->setField($post, 'author', null);
981981
$this->setField($post, 'publisher', null);
@@ -1309,11 +1309,7 @@ public function testFormErrorsWithNonFormComponents($type)
13091309
$context = SerializationContext::create();
13101310
$context->setInitialType($type);
13111311

1312-
try {
1313-
$this->serialize($form, $context);
1314-
} catch (\Throwable $e) {
1315-
self::assertTrue(false, 'Serialization should not throw an exception');
1316-
}
1312+
$this->serialize($form, $context);
13171313
}
13181314

13191315
public static function initialFormTypeProvider()
@@ -1998,9 +1994,7 @@ public function testThrowingExceptionWhenDeserializingUnionDocBlockTypes()
19981994
}
19991995

20001996
$this->expectException(RuntimeException::class);
2001-
2002-
$object = new UnionTypedDocBlockProperty(10000);
2003-
$deserialized = $this->deserialize(static::getContent('data_integer'), UnionTypedDocBlockProperty::class);
1997+
$this->deserialize(static::getContent('data_integer'), UnionTypedDocBlockProperty::class);
20041998
}
20051999

20062000
public function testIterable(): void

tests/Serializer/ContextTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testSerializationContextPathAndDepth()
3535
$self = $this;
3636

3737
$exclusionStrategy = $this->getMockBuilder(ExclusionStrategyInterface::class)->getMock();
38-
$exclusionStrategy->expects($this->any())
38+
$exclusionStrategy
3939
->method('shouldSkipClass')
4040
->with($this->anything(), $this->callback(static function (SerializationContext $context) use ($self, $objects) {
4141
$expectedDepth = $expectedPath = null;
@@ -61,7 +61,7 @@ public function testSerializationContextPathAndDepth()
6161
}))
6262
->willReturn(false);
6363

64-
$exclusionStrategy->expects($this->any())
64+
$exclusionStrategy
6565
->method('shouldSkipProperty')
6666
->with($this->anything(), $this->callback(static function (SerializationContext $context) use ($self, $objects) {
6767
$expectedDepth = $expectedPath = null;

tests/Serializer/DateIntervalFormatTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ public function testFormat()
1414
$dtf = new DateHandler();
1515

1616
$ATOMDateIntervalString = $dtf->format(new \DateInterval('P0D'));
17-
self::assertEquals($ATOMDateIntervalString, 'P0DT0S');
17+
self::assertEquals('P0DT0S', $ATOMDateIntervalString);
1818

1919
$ATOMDateIntervalString = $dtf->format(new \DateInterval('P0DT0S'));
20-
self::assertEquals($ATOMDateIntervalString, 'P0DT0S');
20+
self::assertEquals('P0DT0S', $ATOMDateIntervalString);
2121

2222
$ATOMDateIntervalString = $dtf->format(new \DateInterval('PT45M'));
2323

24-
self::assertEquals($ATOMDateIntervalString, 'PT45M');
24+
self::assertEquals('PT45M', $ATOMDateIntervalString);
2525

2626
$ATOMDateIntervalString = $dtf->format(new \DateInterval('P2YT45M'));
2727

28-
self::assertEquals($ATOMDateIntervalString, 'P2YT45M');
28+
self::assertEquals('P2YT45M', $ATOMDateIntervalString);
2929

3030
$ATOMDateIntervalString = $dtf->format(new \DateInterval('P2Y4DT6H8M16S'));
3131

32-
self::assertEquals($ATOMDateIntervalString, 'P2Y4DT6H8M16S');
32+
self::assertEquals('P2Y4DT6H8M16S', $ATOMDateIntervalString);
3333
}
3434
}

0 commit comments

Comments
 (0)