Skip to content

Commit

Permalink
updated several packages to update PHPUnit to version 11
Browse files Browse the repository at this point in the history
- PHPUnit 11 does not allow extensions as it was used in phpunit-injector, so the workaround has been introduced
- PHPUnit 11 no longer supports doc-blocks and uses attributes, so the code has been updated to the new standard
- PHPUnit 11 supports only data providers from the public static method so all providers have been updated
    - this led to rewriting some of the providers and associated methods
- PHPUnit 11 no longer supports abstract mocks so some mocks have to be updated
- setMethods method has been replaced by onlyMethods
  • Loading branch information
TomasLudvik committed Jul 3, 2024
1 parent a28011c commit 9ced099
Show file tree
Hide file tree
Showing 88 changed files with 450 additions and 414 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/components
/vendor
/composer.lock
/.phpunit.result.cache
/.phpunit.cache
6 changes: 3 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,7 @@
<phingcall target="npm-translations-dump"/>
<exec executable="${path.php.executable}" passthru="true" checkreturn="true">
<arg value="${path.bin-console}"/>
<arg value="translation:extract"/>
<arg value="jms:translation:extract"/>
<arg value="--dir=${path.src}"/>
<arg value="--dir=${path.config}"/>
<arg value="--dir=${path.templates}"/>
Expand All @@ -1600,7 +1600,7 @@
<phingcall target="npm-translations-dump"/>
<exec executable="${path.php.executable}" passthru="true" checkreturn="true">
<arg value="${path.bin-console}"/>
<arg value="translation:extract"/>
<arg value="jms:translation:extract"/>
<arg value="--dir=${path.src}"/>
<arg value="--dir=${path.templates}"/>
<arg value="--dir=${path.var}/translations/projectBase"/>
Expand All @@ -1623,7 +1623,7 @@
<target name="translations-import" description="Import translatable messages from front-end source files in your project.">
<exec executable="${path.php.executable}" passthru="true" checkreturn="true">
<arg value="${path.bin-console}"/>
<arg value="translation:import"/>
<arg value="jms:translation:import"/>
<arg value="${path.root}/translations-update/"/>
<arg value="${path.root}/translations/"/>
<arg value="messages"/>
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@
"helios-ag/fm-elfinder-bundle": "^12.2",
"heureka/overeno-zakazniky": "^4.0.1",
"jms/metadata": "^2.6.1",
"jms/translation-bundle": "^1.6.2",
"jms/translation-bundle": "^2.2.1",
"knplabs/knp-menu-bundle": "^3.2",
"league/csv": "^9.6",
"league/flysystem": "^3.11",
"litipk/php-bignumbers": "^0.8.6",
"league/iso3166": "^4.2.1",
"nette/utils": "^3.0",
"nikic/php-parser": "^4.0",
"nikic/php-parser": "^5.0",
"phpdocumentor/reflection-docblock": "^5.3.0",
"presta/sitemap-bundle": "^3.3",
"prezent/doctrine-translatable": "^3.3.0",
"prezent/doctrine-translatable-bundle": "^1.4",
"psr/log": "^1.0",
"ramsey/uuid": "^4.3.1",
"roave/better-reflection": "^6.0",
"roave/better-reflection": "^6.37",
"shopsys/form-types-bundle": "15.0.x-dev",
"shopsys/jsformvalidator-bundle": "^1.7.0",
"shopsys/migrations": "15.0.x-dev",
Expand Down Expand Up @@ -112,10 +112,10 @@
"phpstan/phpstan-doctrine": "^1.3.4",
"phpstan/phpstan-phpunit": "^1.1.1",
"phpstan/phpstan-symfony": "^1.1.8",
"phpunit/phpunit": "^9.5.20",
"phpunit/phpunit": "^11.2.1",
"psr/event-dispatcher": "^1.0.0",
"shopsys/coding-standards": "15.0.x-dev",
"sspooky13/yaml-standards": "^8.1.0",
"sspooky13/yaml-standards": "^9.0",
"symfony/var-dumper": "^5.4"
},
"extra": {
Expand Down
22 changes: 9 additions & 13 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
failOnWarning="true"
beStrictAboutTestsThatDoNotTestAnything="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<coverage/>

<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>

<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<source/>
</phpunit>
4 changes: 2 additions & 2 deletions src/Component/Translation/ConstraintMessageExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Translation\Extractor\FileVisitorInterface;
use PhpParser\Node;
use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Scalar\String_;
Expand Down Expand Up @@ -101,7 +101,7 @@ protected function extractMessagesFromOptions(Node $optionsNode)
}

/**
* @param \PhpParser\Node\Expr\ArrayItem $node
* @param \PhpParser\Node\ArrayItem $node
* @return bool
*/
protected function isMessageOptionItem(ArrayItem $node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Translation\Extractor\FileVisitorInterface;
use PhpParser\Node;
use PhpParser\Node\PropertyItem;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\PropertyProperty;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
use PhpParser\NodeVisitor\NameResolver;
Expand Down Expand Up @@ -114,10 +114,10 @@ protected function extractMessagesFromProperty(Property $node)
}

/**
* @param \PhpParser\Node\Stmt\PropertyProperty $node
* @param \PhpParser\Node\PropertyItem $node
* @return bool
*/
protected function isMessagePropertyProperty(PropertyProperty $node)
protected function isMessagePropertyProperty(PropertyItem $node)
{
return strtolower(substr($node->name->toString(), -7)) === 'message';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Component/Translation/ConstraintViolationExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected function setCurrentExecutionContextVariableNamesFromNode(ClassMethod $
protected function isParameterExecutionContextInterfaceSubclass(Node\Param $parameter)
{
if ($parameter->type instanceof FullyQualified) {
$fullyQualifiedName = implode('\\', $parameter->type->parts);
$fullyQualifiedName = implode('\\', $parameter->type->getParts());

return $fullyQualifiedName === ExecutionContextInterface::class
|| is_subclass_of($fullyQualifiedName, ExecutionContextInterface::class);
Expand Down
3 changes: 1 addition & 2 deletions tests/Test/IsMoneyEqual.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
namespace Tests\FrameworkBundle\Test;

use PHPUnit\Framework\Constraint\Constraint;
use SebastianBergmann\Exporter\Exporter;
use Shopsys\FrameworkBundle\Component\Money\Money;

final class IsMoneyEqual extends Constraint
{
private Exporter $exporter;
private MoneyExporter $exporter;

/**
* @param \Shopsys\FrameworkBundle\Component\Money\Money $value
Expand Down
3 changes: 1 addition & 2 deletions tests/Test/IsPriceEqual.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
namespace Tests\FrameworkBundle\Test;

use PHPUnit\Framework\Constraint\Constraint;
use SebastianBergmann\Exporter\Exporter;
use Shopsys\FrameworkBundle\Model\Pricing\Price;

final class IsPriceEqual extends Constraint
{
private Exporter $exporter;
private PriceExporter $exporter;

/**
* @param \Shopsys\FrameworkBundle\Model\Pricing\Price $value
Expand Down
15 changes: 4 additions & 11 deletions tests/Test/MoneyExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@

namespace Tests\FrameworkBundle\Test;

use SebastianBergmann\Exporter\Exporter;
use Shopsys\FrameworkBundle\Component\Money\Money;

final class MoneyExporter extends Exporter
final class MoneyExporter
{
/**
* @param mixed $value
* @param int $indentation
* @param \SebastianBergmann\RecursionContext\Context $processed
* @param \Shopsys\FrameworkBundle\Component\Money\Money $value
* @return string
*/
protected function recursiveExport(&$value, $indentation, $processed = null): string
public function export(Money $value): string
{
if ($value instanceof Money) {
return $value->getAmount();
}

return parent::recursiveExport($value, $indentation, $processed);
return $value->getAmount();
}
}
15 changes: 4 additions & 11 deletions tests/Test/PriceExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@

namespace Tests\FrameworkBundle\Test;

use SebastianBergmann\Exporter\Exporter;
use Shopsys\FrameworkBundle\Model\Pricing\Price;

final class PriceExporter extends Exporter
final class PriceExporter
{
/**
* @param mixed $value
* @param int $indentation
* @param \SebastianBergmann\RecursionContext\Context $processed
* @param \Shopsys\FrameworkBundle\Model\Pricing\Price $value
* @return string
*/
protected function recursiveExport(&$value, $indentation, $processed = null): string
public function export(Price $value): string
{
if ($value instanceof Price) {
return $value->getPriceWithVat()->getAmount() . ' with Vat (' . $value->getPriceWithoutVat()->getAmount() . ' without VAT)';
}

return parent::recursiveExport($value, $indentation, $processed);
return $value->getPriceWithVat()->getAmount() . ' with Vat (' . $value->getPriceWithoutVat()->getAmount() . ' without VAT)';
}
}
30 changes: 17 additions & 13 deletions tests/Unit/Command/CheckRedisCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tests\FrameworkBundle\Unit\Command;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Redis;
use RedisException;
Expand All @@ -17,30 +18,33 @@ final class CheckRedisCommandTest extends TestCase
/**
* @return iterable
*/
public function pingAllRedisClientsProvider(): iterable
public static function pingAllRedisClientsProvider(): iterable
{
yield [true, new RedisFacade([])];
yield [true, []];

yield [true, new RedisFacade([$this->createRedisMockExpectingPing()])];
yield [true, ['createRedisMockExpectingPing']];

yield [true, new RedisFacade(
[$this->createRedisMockExpectingPing(), $this->createRedisMockExpectingPing(), $this->createRedisMockExpectingPing()],
)];
yield [true, ['createRedisMockExpectingPing', 'createRedisMockExpectingPing', 'createRedisMockExpectingPing']];

yield [false, new RedisFacade([$this->createRedisMockThrowingException()])];
yield [false, ['createRedisMockThrowingException']];

yield [false, new RedisFacade(
[$this->createRedisMockExpectingPing(), $this->createRedisMockThrowingException()],
)];
yield [false, ['createRedisMockExpectingPing', 'createRedisMockThrowingException']];
}

/**
* @dataProvider pingAllRedisClientsProvider
* @param bool $expectSuccess
* @param \Shopsys\FrameworkBundle\Component\Redis\RedisFacade $redisFacade
* @param array $mockMethodNames
*/
public function testPingAllRedisClients(bool $expectSuccess, RedisFacade $redisFacade): void
#[DataProvider('pingAllRedisClientsProvider')]
public function testPingAllRedisClients(bool $expectSuccess, array $mockMethodNames): void
{
$redisMocks = [];

foreach ($mockMethodNames as $mockMethodName) {
$redisMocks[] = $this->{$mockMethodName}();
}

$redisFacade = new RedisFacade($redisMocks);
$checkRedisCommand = new CheckRedisCommand($redisFacade);

$output = new BufferedOutput();
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/Component/Bytes/BytesHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

namespace Tests\FrameworkBundle\Unit\Component\Bytes;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Shopsys\FrameworkBundle\Component\Bytes\BytesHelper;

class BytesHelperTest extends TestCase
{
/**
* @dataProvider phpStringBytesToBytesDataProvider
* @param string $phpStringBytes
* @param int $expectedBytes
*/
#[DataProvider('phpStringBytesToBytesDataProvider')]
public function testConvertPhpStringByteDefinitionToBytes(string $phpStringBytes, int $expectedBytes): void
{
$this->assertSame($expectedBytes, BytesHelper::convertPhpStringByteDefinitionToBytes($phpStringBytes));
Expand All @@ -22,7 +23,7 @@ public function testConvertPhpStringByteDefinitionToBytes(string $phpStringBytes
/**
* @return array[]
*/
public function phpStringBytesToBytesDataProvider(): array
public static function phpStringBytesToBytesDataProvider(): array
{
return [
['phpStringBytes' => '-1', 'expectedBytes' => -1],
Expand Down
11 changes: 6 additions & 5 deletions tests/Unit/Component/ClassExtension/AnnotationsAdderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tests\FrameworkBundle\Unit\Component\ClassExtension;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Roave\BetterReflection\Reflection\ReflectionObject;
use Shopsys\FrameworkBundle\Component\ClassExtension\AnnotationsAdder;
Expand All @@ -19,7 +20,7 @@ public function testAddAnnotationToClassThatHasNoAnnotationYet(): void
$betterReflectionClass = ReflectionObject::createFromName(DummyClassWithNoAnnotation::class);
/** @var \Shopsys\FrameworkBundle\Component\ClassExtension\FileContentsReplacer|\PHPUnit\Framework\MockObject\MockObject $fileContentsReplacerMock */
$fileContentsReplacerMock = $this->getMockBuilder(FileContentsReplacer::class)
->setMethods(['replaceInFile'])
->onlyMethods(['replaceInFile'])
->getMock();
$classKeywordWithName = 'class ' . $betterReflectionClass->getShortName();
$propertyAndMethodAnnotationsLines = "@property CategoryFacade \$categoryFacade\n@method CategoryFacade getCategoryFacade()\n";
Expand All @@ -41,7 +42,7 @@ public function testAddAnnotationToClassThatHasAlreadyAnAnnotation(): void
$betterReflectionClass = ReflectionObject::createFromName(DummyClassWithAnAnnotation::class);
/** @var \Shopsys\FrameworkBundle\Component\ClassExtension\FileContentsReplacer|\PHPUnit\Framework\MockObject\MockObject $fileContentsReplacerMock */
$fileContentsReplacerMock = $this->getMockBuilder(FileContentsReplacer::class)
->setMethods(['replaceInFile'])
->onlyMethods(['replaceInFile'])
->getMock();
$propertyAndMethodAnnotationsLines = "@property CategoryFacade \$categoryFacade\n@method CategoryFacade getCategoryFacade()\n";
$docComment = $betterReflectionClass->getDocComment();
Expand All @@ -63,7 +64,7 @@ public function testAddAnnotationToClassEmptyAnnotation(): void
$betterReflectionClass = ReflectionObject::createFromName(DummyClassWithAnAnnotation::class);
/** @var \Shopsys\FrameworkBundle\Component\ClassExtension\FileContentsReplacer|\PHPUnit\Framework\MockObject\MockObject $fileContentsReplacerMock */
$fileContentsReplacerMock = $this->getMockBuilder(FileContentsReplacer::class)
->setMethods(['replaceInFile'])
->onlyMethods(['replaceInFile'])
->getMock();
$fileContentsReplacerMock->expects($this->never())->method('replaceInFile');

Expand Down Expand Up @@ -91,7 +92,7 @@ public function testAddMethodAnnotationToClassReplacesPrevious(): void
/**
* @return string[][]
*/
public function extractPropertyOrMethodAnnotationNameDataProvider(): array
public static function extractPropertyOrMethodAnnotationNameDataProvider(): array
{
return [
['property-test', '@property $test'],
Expand Down Expand Up @@ -121,10 +122,10 @@ public function extractPropertyOrMethodAnnotationNameDataProvider(): array
}

/**
* @dataProvider extractPropertyOrMethodAnnotationNameDataProvider
* @param string $expectedPropertyName
* @param string $propertyLine
*/
#[DataProvider('extractPropertyOrMethodAnnotationNameDataProvider')]
public function testExtractPropertyOrMethodAnnotationName(string $expectedPropertyName, string $propertyLine): void
{
$fileContentsReplacerMock = $this->createMock(FileContentsReplacer::class);
Expand Down
Loading

0 comments on commit 9ced099

Please sign in to comment.