Skip to content

Commit

Permalink
deps(composer): Update to PHPUnit 11 & Rector 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Czarnecki committed Mar 4, 2024
1 parent b48dc57 commit 47525f8
Show file tree
Hide file tree
Showing 27 changed files with 205 additions and 159 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
"jackalope/jackalope-doctrine-dbal": "^1.3",
"ocramius/proxy-manager": "^1.0 || ^2.0",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "^1.0.2",
"phpunit/phpunit": "^9.0 || ^10.0",
"phpstan/phpstan": "^1.10.57",
"phpunit/phpunit": "^9.0 || ^10.0 || ^11.0",
"psr/container": "^1.0 || ^2.0",
"rector/rector": "^0.19.0",
"rector/rector": "^1.0.0",
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
"symfony/expression-language": "^5.4 || ^6.0 || ^7.0",
"symfony/filesystem": "^5.4 || ^6.0 || ^7.0",
Expand Down
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
$rectorConfig->paths([
__DIR__ . '/src',
]);
$rectorConfig->sets([LevelSetList::UP_TO_PHP_74]);
$rectorConfig->phpVersion(74);
};
3 changes: 3 additions & 0 deletions tests/Deserializer/BaseDeserializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
use JMS\Serializer\Tests\Fixtures\GroupsObject;
use JMS\Serializer\Tests\Fixtures\Price;
use JMS\Serializer\Tests\Fixtures\Publisher;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class BaseDeserializationTest extends TestCase
{
/**
* @dataProvider dataTypeCannotBeCasted
*/
#[DataProvider('dataTypeCannotBeCasted')]

Check failure on line 22 in tests/Deserializer/BaseDeserializationTest.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.0)

Attribute class PHPUnit\Framework\Attributes\DataProvider does not exist.
public function testDeserializationInvalidDataCausesException($data, string $type): void
{
$serializer = SerializerBuilder::create()->build();
Expand Down Expand Up @@ -48,6 +50,7 @@ public static function dataTypeCannotBeCasted(): iterable
/**
* @dataProvider dataDeserializerGroupExclusion
*/
#[DataProvider('dataDeserializerGroupExclusion')]

Check failure on line 53 in tests/Deserializer/BaseDeserializationTest.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.0)

Attribute class PHPUnit\Framework\Attributes\DataProvider does not exist.
public function testDeserializerGroupExclusion(array $data, array $groups, array $expected): void
{
$serializer = SerializerBuilder::create()->build();
Expand Down
20 changes: 10 additions & 10 deletions tests/Exclusion/DisjunctExclusionStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testShouldSkipClassShortCircuiting()
$first->expects($this->once())
->method('shouldSkipClass')
->with($metadata, $context)
->will($this->returnValue(true));
->willReturn(true);

$last->expects($this->never())
->method('shouldSkipClass');
Expand All @@ -46,12 +46,12 @@ public function testShouldSkipClassDisjunctBehavior()
$first->expects($this->once())
->method('shouldSkipClass')
->with($metadata, $context)
->will($this->returnValue(false));
->willReturn(false);

$last->expects($this->once())
->method('shouldSkipClass')
->with($metadata, $context)
->will($this->returnValue(true));
->willReturn(true);

self::assertTrue($strat->shouldSkipClass($metadata, $context));
}
Expand All @@ -69,12 +69,12 @@ public function testShouldSkipClassReturnsFalseIfNoPredicateMatched()
$first->expects($this->once())
->method('shouldSkipClass')
->with($metadata, $context)
->will($this->returnValue(false));
->willReturn(false);

$last->expects($this->once())
->method('shouldSkipClass')
->with($metadata, $context)
->will($this->returnValue(false));
->willReturn(false);

self::assertFalse($strat->shouldSkipClass($metadata, $context));
}
Expand All @@ -92,7 +92,7 @@ public function testShouldSkipPropertyShortCircuiting()
$first->expects($this->once())
->method('shouldSkipProperty')
->with($metadata, $context)
->will($this->returnValue(true));
->willReturn(true);

$last->expects($this->never())
->method('shouldSkipProperty');
Expand All @@ -113,12 +113,12 @@ public function testShouldSkipPropertyDisjunct()
$first->expects($this->once())
->method('shouldSkipProperty')
->with($metadata, $context)
->will($this->returnValue(false));
->willReturn(false);

$last->expects($this->once())
->method('shouldSkipProperty')
->with($metadata, $context)
->will($this->returnValue(true));
->willReturn(true);

self::assertTrue($strat->shouldSkipProperty($metadata, $context));
}
Expand All @@ -136,12 +136,12 @@ public function testShouldSkipPropertyReturnsFalseIfNoPredicateMatches()
$first->expects($this->once())
->method('shouldSkipProperty')
->with($metadata, $context)
->will($this->returnValue(false));
->willReturn(false);

$last->expects($this->once())
->method('shouldSkipProperty')
->with($metadata, $context)
->will($this->returnValue(false));
->willReturn(false);

self::assertFalse($strat->shouldSkipProperty($metadata, $context));
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Exclusion/GroupsExclusionStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
use JMS\Serializer\Exclusion\GroupsExclusionStrategy;
use JMS\Serializer\Metadata\StaticPropertyMetadata;
use JMS\Serializer\SerializationContext;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class GroupsExclusionStrategyTest extends TestCase
{
/**
* @param array $propertyGroups
* @param array $groups
* @param bool $exclude
*
* @dataProvider getExclusionRules
*/

Check failure on line 17 in tests/Exclusion/GroupsExclusionStrategyTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards (7.4)

There must be no blank lines after the function comment
public function testUninitializedContextIsWorking(array $propertyGroups, array $groups, $exclude)
#[DataProvider('getExclusionRules')]

Check failure on line 18 in tests/Exclusion/GroupsExclusionStrategyTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards (7.4)

Expected 0 blank lines between attribute and its target, found 1.

Check failure on line 18 in tests/Exclusion/GroupsExclusionStrategyTest.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.0)

Attribute class PHPUnit\Framework\Attributes\DataProvider does not exist.

public function testUninitializedContextIsWorking(array $propertyGroups, array $groups, bool $exclude)

Check failure on line 20 in tests/Exclusion/GroupsExclusionStrategyTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards (7.4)

Expected 0 blank lines before function; 1 found
{
$metadata = new StaticPropertyMetadata('stdClass', 'prop', 'propVal');
$metadata->groups = $propertyGroups;
Expand Down Expand Up @@ -57,6 +56,7 @@ public static function getExclusionRules()
/**
* @dataProvider getGroupsFor
*/
#[DataProvider('getGroupsFor')]

Check failure on line 59 in tests/Exclusion/GroupsExclusionStrategyTest.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.0)

Attribute class PHPUnit\Framework\Attributes\DataProvider does not exist.
public function testGroupsFor(array $groups, array $propsVisited, array $resultingGroups)
{
$exclusion = new GroupsExclusionStrategy($groups);
Expand Down
3 changes: 3 additions & 0 deletions tests/Handler/ArrayCollectionDepthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use JMS\Serializer\SerializationContext;
use JMS\Serializer\Serializer as JMSSerializer;
use JMS\Serializer\SerializerBuilder;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class ArrayCollectionDepthTest extends TestCase
Expand All @@ -28,6 +29,8 @@ protected function setUp(): void
*
* @dataProvider getCollections
*/

Check failure on line 31 in tests/Handler/ArrayCollectionDepthTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards (7.4)

There must be no blank lines after the function comment
#[DataProvider('getCollections')]

Check failure on line 32 in tests/Handler/ArrayCollectionDepthTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards (7.4)

Expected 0 blank lines between attribute and its target, found 1.

Check failure on line 32 in tests/Handler/ArrayCollectionDepthTest.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.0)

Attribute class PHPUnit\Framework\Attributes\DataProvider does not exist.

public function testDepth($collection)
{
$context = SerializationContext::create()
Expand Down
3 changes: 3 additions & 0 deletions tests/Handler/ArrayCollectionHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
use JMS\Serializer\Tests\Fixtures\ExclusionStrategy\AlwaysExcludeExclusionStrategy;
use JMS\Serializer\Visitor\SerializationVisitorInterface;
use Metadata\MetadataFactoryInterface;
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
use PHPUnit\Framework\TestCase;

class ArrayCollectionHandlerTest extends TestCase
{
/**
* @doesNotPerformAssertions
*/
#[DoesNotPerformAssertions]

Check failure on line 22 in tests/Handler/ArrayCollectionHandlerTest.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.0)

Attribute class PHPUnit\Framework\Attributes\DoesNotPerformAssertions does not exist.
public function testSerializeArray()
{
$handler = new ArrayCollectionHandler();
Expand All @@ -36,6 +38,7 @@ public function testSerializeArray()
/**
* @doesNotPerformAssertions
*/
#[DoesNotPerformAssertions]

Check failure on line 41 in tests/Handler/ArrayCollectionHandlerTest.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.0)

Attribute class PHPUnit\Framework\Attributes\DoesNotPerformAssertions does not exist.
public function testSerializeArraySkipByExclusionStrategy()
{
$handler = new ArrayCollectionHandler(false);
Expand Down
12 changes: 6 additions & 6 deletions tests/Handler/DateHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use JMS\Serializer\SerializationContext;
use JMS\Serializer\Visitor\DeserializationVisitorInterface;
use JMS\Serializer\Visitor\SerializationVisitorInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
use PHPUnit\Framework\TestCase;

class DateHandlerTest extends TestCase
Expand Down Expand Up @@ -39,11 +41,11 @@ public static function getParams()
}

/**
* @param array $params
*
* @doesNotPerformAssertions
* @dataProvider getParams
*/
#[DataProvider('getParams')]

Check failure on line 47 in tests/Handler/DateHandlerTest.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.0)

Attribute class PHPUnit\Framework\Attributes\DataProvider does not exist.
#[DoesNotPerformAssertions]

Check failure on line 48 in tests/Handler/DateHandlerTest.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.0)

Attribute class PHPUnit\Framework\Attributes\DoesNotPerformAssertions does not exist.
public function testSerializeDate(array $params)
{
$context = $this->getMockBuilder(SerializationContext::class)->getMock();
Expand All @@ -57,12 +59,10 @@ public function testSerializeDate(array $params)
}

/**
* @param string $dateInterval
* @param \DateTime $expected
*
* @dataProvider getDeserializeDateInterval
*/
public function testDeserializeDateInterval($dateInterval, $expected)
#[DataProvider('getDeserializeDateInterval')]

Check failure on line 64 in tests/Handler/DateHandlerTest.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.0)

Attribute class PHPUnit\Framework\Attributes\DataProvider does not exist.
public function testDeserializeDateInterval(string $dateInterval, array $expected)
{
$visitor = $this->getMockBuilder(DeserializationVisitorInterface::class)->getMock();
$visitor->method('visitString')->with('2017-06-18');
Expand Down
2 changes: 2 additions & 0 deletions tests/Handler/IteratorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use JMS\Serializer\SerializationContext;
use JMS\Serializer\Visitor\DeserializationVisitorInterface;
use JMS\Serializer\Visitor\SerializationVisitorInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class IteratorHandlerTest extends TestCase
Expand Down Expand Up @@ -40,6 +41,7 @@ public static function iteratorsProvider(): array
/**
* @dataProvider iteratorsProvider
*/
#[DataProvider('iteratorsProvider')]
public function testSerialize(\Iterator $iterator): void
{
$type = get_class($iterator);
Expand Down
6 changes: 6 additions & 0 deletions tests/Handler/SymfonyUidHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use JMS\Serializer\Handler\SymfonyUidHandler;
use JMS\Serializer\SerializerBuilder;
use JMS\Serializer\SerializerInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Uid\AbstractUid;
use Symfony\Component\Uid\Ulid;
Expand Down Expand Up @@ -46,6 +47,7 @@ public static function dataUid(): \Generator
/**
* @dataProvider dataUid
*/
#[DataProvider('dataUid')]
public function testSerializeUidToJson(AbstractUid $uid): void
{
self::assertJsonStringEqualsJsonString(
Expand All @@ -57,6 +59,7 @@ public function testSerializeUidToJson(AbstractUid $uid): void
/**
* @dataProvider dataUid
*/
#[DataProvider('dataUid')]
public function testSerializeUidToXmlWithCData(AbstractUid $uid): void
{
self::assertXmlStringEqualsXmlString(
Expand All @@ -68,6 +71,7 @@ public function testSerializeUidToXmlWithCData(AbstractUid $uid): void
/**
* @dataProvider dataUid
*/
#[DataProvider('dataUid')]
public function testSerializeUidToXmlWithoutCData(AbstractUid $uid): void
{
self::assertXmlStringEqualsXmlString(
Expand Down Expand Up @@ -117,6 +121,7 @@ public function testSerializeUidRejectsInvalidFormat(): void
/**
* @dataProvider dataUid
*/
#[DataProvider('dataUid')]
public function testDeserializeUidFromJson(AbstractUid $uid): void
{
self::assertTrue($uid->equals($this->createSerializer()->deserialize(sprintf('"%s"', (string) $uid), \get_class($uid), 'json')));
Expand All @@ -125,6 +130,7 @@ public function testDeserializeUidFromJson(AbstractUid $uid): void
/**
* @dataProvider dataUid
*/
#[DataProvider('dataUid')]
public function testDeserializeUidFromXml(AbstractUid $uid): void
{
self::assertTrue($uid->equals($this->createSerializer()->deserialize(sprintf('<?xml version="1.0" encoding="UTF-8"?><result>%s</result>', (string) $uid), \get_class($uid), 'xml')));
Expand Down
23 changes: 14 additions & 9 deletions tests/Metadata/ClassMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace JMS\Serializer\Tests\Metadata;

use JMS\Serializer\Exception\InvalidMetadataException;
use JMS\Serializer\Metadata\ClassMetadata;
use JMS\Serializer\Metadata\PropertyMetadata;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class ClassMetadataTest extends TestCase
Expand All @@ -23,14 +25,14 @@ public static function getAccessOrderCases()

public function testSerialization()
{
$meta = new PropertyMetadata('JMS\Serializer\Tests\Metadata\PropertyMetadataOrder', 'b');
$meta = new PropertyMetadata(PropertyMetadataOrder::class, 'b');
$restoredMeta = unserialize(serialize($meta));
self::assertEquals($meta, $restoredMeta);
}

public function testSerializationClass()
{
$meta = new ClassMetadata('JMS\Serializer\Tests\Metadata\PropertyMetadataOrder');
$meta = new ClassMetadata(PropertyMetadataOrder::class);
$meta->xmlRootPrefix = 'foo';
$meta->xmlDiscriminatorCData = true;
$meta->xmlDiscriminatorAttribute = false;
Expand All @@ -43,11 +45,12 @@ public function testSerializationClass()
/**
* @dataProvider getAccessOrderCases
*/
#[DataProvider('getAccessOrderCases')]
public function testSetAccessorOrderCustom(array $order, array $expected)
{
$metadata = new ClassMetadata('JMS\Serializer\Tests\Metadata\PropertyMetadataOrder');
$metadata->addPropertyMetadata(new PropertyMetadata('JMS\Serializer\Tests\Metadata\PropertyMetadataOrder', 'b'));
$metadata->addPropertyMetadata(new PropertyMetadata('JMS\Serializer\Tests\Metadata\PropertyMetadataOrder', 'a'));
$metadata = new ClassMetadata(PropertyMetadataOrder::class);
$metadata->addPropertyMetadata(new PropertyMetadata(PropertyMetadataOrder::class, 'b'));
$metadata->addPropertyMetadata(new PropertyMetadata(PropertyMetadataOrder::class, 'a'));
self::assertEquals(['b', 'a'], array_keys($metadata->propertyMetadata));

$metadata->setAccessorOrder(ClassMetadata::ACCESSOR_ORDER_CUSTOM, $order);
Expand All @@ -56,9 +59,9 @@ public function testSetAccessorOrderCustom(array $order, array $expected)

public function testSetAccessorOrderAlphabetical()
{
$metadata = new ClassMetadata('JMS\Serializer\Tests\Metadata\PropertyMetadataOrder');
$metadata->addPropertyMetadata(new PropertyMetadata('JMS\Serializer\Tests\Metadata\PropertyMetadataOrder', 'b'));
$metadata->addPropertyMetadata(new PropertyMetadata('JMS\Serializer\Tests\Metadata\PropertyMetadataOrder', 'a'));
$metadata = new ClassMetadata(PropertyMetadataOrder::class);
$metadata->addPropertyMetadata(new PropertyMetadata(PropertyMetadataOrder::class, 'b'));
$metadata->addPropertyMetadata(new PropertyMetadata(PropertyMetadataOrder::class, 'a'));
self::assertEquals(['b', 'a'], array_keys($metadata->propertyMetadata));

$metadata->setAccessorOrder(ClassMetadata::ACCESSOR_ORDER_ALPHABETICAL);
Expand All @@ -68,6 +71,7 @@ public function testSetAccessorOrderAlphabetical()
/**
* @dataProvider providerPublicMethodData
*/
#[DataProvider('providerPublicMethodData')]
public function testAccessorTypePublicMethod($property, $getterInit, $setterInit, $getterName, $setterName)
{
$object = new PropertyMetadataPublicMethod();
Expand All @@ -82,9 +86,10 @@ public function testAccessorTypePublicMethod($property, $getterInit, $setterInit
/**
* @dataProvider providerPublicMethodException
*/
#[DataProvider('providerPublicMethodException')]
public function testAccessorTypePublicMethodException($getter, $setter, $message)
{
$this->expectException('\JMS\Serializer\Exception\InvalidMetadataException');
$this->expectException(InvalidMetadataException::class);
$this->expectExceptionMessage($message);

$object = new PropertyMetadataPublicMethod();
Expand Down
2 changes: 1 addition & 1 deletion tests/Metadata/Driver/DoctrineDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected function getDoctrineDriver()
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$registry->expects($this->atLeastOnce())
->method('getManagerForClass')
->will($this->returnValue($this->getEntityManager()));
->willReturn($this->getEntityManager());

return new DoctrineTypeDriver(
$this->getMetadataDriver(),
Expand Down
Loading

0 comments on commit 47525f8

Please sign in to comment.