Skip to content

Commit

Permalink
Merge pull request #392 from Ocramius/renovate/phpunit-phpunit-11.x
Browse files Browse the repository at this point in the history
Update dependency phpunit/phpunit to v11
  • Loading branch information
Ocramius authored Feb 5, 2025
2 parents d19b101 + 6fc8fda commit 35b164e
Show file tree
Hide file tree
Showing 10 changed files with 389 additions and 328 deletions.
22 changes: 22 additions & 0 deletions .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extensions": [
"bcmath",
"pcov"
],
"ini": [
"memory_limit=-1"
],
"exclude": [
{"name": "Infection [8.2, locked]"}
],
"additional_checks": [
{
"name": "Infection (with PCOV)",
"job": {
"php": "8.4",
"dependencies": "locked",
"command": "./vendor/bin/roave-infection-static-analysis-plugin"
}
}
]
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"require-dev": {
"doctrine/coding-standard": "^12.0.0",
"roave/infection-static-analysis-plugin": "^1.36.0",
"phpunit/phpunit": "^9.6.22",
"phpunit/phpunit": "^11.5.6",
"vimeo/psalm": "^6.3.0",
"doctrine/dbal" : "^4.2.2",
"psalm/plugin-phpunit": "^0.19.2"
Expand Down
585 changes: 301 additions & 284 deletions composer.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
"timeout": 15,
"logs": {
"text": "infectionlog.txt"
}
},
"minMsi": 93.0,
"minCoveredMsi": 94.0
}
18 changes: 10 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./vendor/autoload.php"
colors="true"
verbose="true"
beStrictAboutTodoAnnotatedTests="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutResourceUsageDuringSmallTests="true"
beStrictAboutCoversAnnotation="true">
<coverage includeUncoveredFiles="true">
failOnNotice="true"
failOnWarning="true"
failOnPhpunitDeprecation="true"
failOnDeprecation="true"
failOnEmptyTestSuite="true"
>
<source>
<include>
<directory suffix=".php">./src</directory>
<directory>src</directory>
</include>
</coverage>
</source>

<testsuite name="DoctrineBatchUtils tests">
<directory>./test/DoctrineBatchUtilsTest</directory>
</testsuite>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private function reFetchObject(object $object): object
return $freshValue;
}

/** @param int<0, max> $iteration */
private function clearBatch(int $iteration): void
{
if ($iteration % $this->batchSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ private function reFetchObject(object $object): object
return $freshValue;
}

/** @param int<0, max> $iteration */
private function flushAndClearBatch(int $iteration): void
{
if ($iteration % $this->batchSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
use Doctrine\Persistence\Mapping\ClassMetadata;
use DoctrineBatchUtils\BatchProcessing\Exception\ExceptionInterface;
use DoctrineBatchUtils\BatchProcessing\Exception\MissingBatchItemException;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use stdClass;
use UnexpectedValueException;

use function spl_object_hash;

/** @covers \DoctrineBatchUtils\BatchProcessing\Exception\MissingBatchItemException */
#[CoversClass(MissingBatchItemException::class)]
final class MissingBatchItemExceptionTest extends TestCase
{
public function testFromInvalidReference(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Doctrine\ORM\Mapping\ClassMetadata;
use DoctrineBatchUtils\BatchProcessing\SelectBatchIteratorAggregate;
use DoctrineBatchUtilsTest\MockEntityManager;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use RuntimeException;
Expand All @@ -20,7 +22,7 @@
use function array_fill;
use function count;

/** @covers \DoctrineBatchUtils\BatchProcessing\SelectBatchIteratorAggregate */
#[CoversClass(SelectBatchIteratorAggregate::class)]
final class SelectBatchIteratorAggregateTest extends TestCase
{
/** @var AbstractQuery&MockObject */
Expand Down Expand Up @@ -194,8 +196,8 @@ public function find(string $className, mixed $id, LockMode|int|null $lockMode =
*/
public function testIterationWithSuccessfulReFetchesInNestedIterableResult(): void
{
$originalObjects = [[new stdClass()], [new stdClass()]];
$freshObjects = [new stdClass(), new stdClass()];
$originalObjects = ['aaa' => [new stdClass()], 'bbb' => [new stdClass()]];
$freshObjects = ['aaa' => new stdClass(), 'bbb' => new stdClass()];

$iterator = SelectBatchIteratorAggregate::fromArrayResult($originalObjects, $this->entityManager, 100);

Expand All @@ -204,8 +206,8 @@ public function testIterationWithSuccessfulReFetchesInNestedIterableResult(): vo

public function testIterationWithSuccessfulReFetchesInNestedIterableResultFromQuery(): void
{
$originalObjects = [[new stdClass()], [new stdClass()]];
$freshObjects = [new stdClass(), new stdClass()];
$originalObjects = ['aaa' => [new stdClass()], 'bbb' => [new stdClass()]];
$freshObjects = ['aaa' => new stdClass(), 'bbb' => new stdClass()];

$this->query->method('toIterable')->willReturn(new ArrayIterator($originalObjects));
$iterator = SelectBatchIteratorAggregate::fromQuery($this->query, 100);
Expand All @@ -215,8 +217,8 @@ public function testIterationWithSuccessfulReFetchesInNestedIterableResultFromQu

public function testIterationWithSuccessfulReFetchesInNestedIterableResultFromTraversableResult(): void
{
$originalObjects = [[new stdClass()], [new stdClass()]];
$freshObjects = [new stdClass(), new stdClass()];
$originalObjects = ['aaa' => [new stdClass()], 'bbb' => [new stdClass()]];
$freshObjects = ['aaa' => new stdClass(), 'bbb' => new stdClass()];

$this->query->method('toIterable')->willReturn(new ArrayIterator($originalObjects));
$iterator = SelectBatchIteratorAggregate::fromTraversableResult(new ArrayIterator($originalObjects), $this->entityManager, 100);
Expand All @@ -225,21 +227,21 @@ public function testIterationWithSuccessfulReFetchesInNestedIterableResultFromTr
}

/**
* @param stdClass[][] $originalObjects
* @param stdClass[] $freshObjects
* @param array{aaa: list{stdClass}, bbb: list{stdClass}} $originalObjects
* @param array{aaa: stdClass, bbb: stdClass} $freshObjects
*/
private function assertSuccessfulReFetchesInNestedIterableResult(SelectBatchIteratorAggregate $iterator, array $originalObjects, array $freshObjects): void
{
$this->metadata->method('getIdentifierValues')->willReturnMap(
[
[$originalObjects[0][0], ['id' => 123]],
[$originalObjects[1][0], ['id' => 456]],
[$originalObjects['aaa'][0], ['id' => 123]],
[$originalObjects['bbb'][0], ['id' => 456]],
],
);
$this->entityManager->expects(self::exactly(count($originalObjects)))->method('find')->willReturnMap(
[
[stdClass::class, ['id' => 123], null, null, $freshObjects[0]],
[stdClass::class, ['id' => 456], null, null, $freshObjects[1]],
[stdClass::class, ['id' => 123], null, null, $freshObjects['aaa']],
[stdClass::class, ['id' => 456], null, null, $freshObjects['bbb']],
],
);
$this->entityManager->expects(self::once())->method('clear');
Expand All @@ -250,7 +252,13 @@ private function assertSuccessfulReFetchesInNestedIterableResult(SelectBatchIter
$iteratedObjects[$key] = $value;
}

$this->assertSame([$freshObjects[0], $freshObjects[1]], $iteratedObjects);
$this->assertSame(
[
'aaa' => $freshObjects['aaa'],
'bbb' => $freshObjects['bbb'],
],
$iteratedObjects,
);
}

/**
Expand Down Expand Up @@ -284,6 +292,7 @@ public function testWillNotReFetchEntitiesInNonIterableAlikeResult(): void
*
* @dataProvider iterationClearsProvider
*/
#[DataProvider('iterationClearsProvider')]
public function testIterationClearsAtGivenBatchSizes(int $resultItemsCount, int $batchSize, int $expectedClearsCount): void
{
$object = new stdClass();
Expand All @@ -308,7 +317,7 @@ public function testIterationClearsAtGivenBatchSizes(int $resultItemsCount, int
}

/** @return non-empty-list<array{int<1, max>, int<1, max>, int<1, max>}> */
public function iterationClearsProvider(): array
public static function iterationClearsProvider(): array
{
return [
[10, 5, 3],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use DoctrineBatchUtils\BatchProcessing\Exception\MissingBatchItemException;
use DoctrineBatchUtils\BatchProcessing\SimpleBatchIteratorAggregate;
use DoctrineBatchUtilsTest\MockEntityManager;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use stdClass;
Expand All @@ -19,7 +21,7 @@
use function array_fill;
use function count;

/** @covers \DoctrineBatchUtils\BatchProcessing\SimpleBatchIteratorAggregate */
#[CoversClass(SimpleBatchIteratorAggregate::class)]
final class SimpleBatchIteratorAggregateTest extends TestCase
{
/** @var AbstractQuery&MockObject */
Expand All @@ -38,8 +40,6 @@ protected function setUp(): void
$this->entityManager = $this->getMockBuilder(MockEntityManager::class)
->disableOriginalConstructor()
->disableOriginalClone()
->disableArgumentCloning()
->disallowMockingUnknownTypes()
->onlyMethods(['getClassMetadata', 'find'])
->getMock();

Expand Down Expand Up @@ -90,7 +90,6 @@ public function testIterationWithEmptySet(): void
}
}

/** @uses \DoctrineBatchUtils\BatchProcessing\Exception\MissingBatchItemException */
public function testIterationRollsBackOnMissingItems(): void
{
$iterator = SimpleBatchIteratorAggregate::fromArrayResult([new stdClass()], $this->entityManager, 100);
Expand Down Expand Up @@ -156,8 +155,8 @@ public function testIterationWithSuccessfulReFetches(): void
*/
public function testIterationWithSuccessfulReFetchesInNestedIterableResult(): void
{
$originalObjects = [[new stdClass()], [new stdClass()]];
$freshObjects = [new stdClass(), new stdClass()];
$originalObjects = ['aaa' => [new stdClass()], 'bbb' => [new stdClass()]];
$freshObjects = ['aaa' => new stdClass(), 'bbb' => new stdClass()];

$iterator = SimpleBatchIteratorAggregate::fromArrayResult($originalObjects, $this->entityManager, 100);

Expand All @@ -166,8 +165,8 @@ public function testIterationWithSuccessfulReFetchesInNestedIterableResult(): vo

public function testIterationWithSuccessfulReFetchesInNestedIterableResultFromQuery(): void
{
$originalObjects = [[new stdClass()], [new stdClass()]];
$freshObjects = [new stdClass(), new stdClass()];
$originalObjects = ['aaa' => [new stdClass()], 'bbb' => [new stdClass()]];
$freshObjects = ['aaa' => new stdClass(), 'bbb' => new stdClass()];

$this->query->method('toIterable')->willReturn(new ArrayIterator($originalObjects));
$iterator = SimpleBatchIteratorAggregate::fromQuery($this->query, 100);
Expand All @@ -177,8 +176,8 @@ public function testIterationWithSuccessfulReFetchesInNestedIterableResultFromQu

public function testIterationWithSuccessfulReFetchesInNestedIterableResultFromTraversableResult(): void
{
$originalObjects = [[new stdClass()], [new stdClass()]];
$freshObjects = [new stdClass(), new stdClass()];
$originalObjects = ['aaa' => [new stdClass()], 'bbb' => [new stdClass()]];
$freshObjects = ['aaa' => new stdClass(), 'bbb' => new stdClass()];

$this->query->method('toIterable')->willReturn(new ArrayIterator($originalObjects));
$iterator = SimpleBatchIteratorAggregate::fromTraversableResult(new ArrayIterator($originalObjects), $this->entityManager, 100);
Expand All @@ -187,21 +186,21 @@ public function testIterationWithSuccessfulReFetchesInNestedIterableResultFromTr
}

/**
* @param stdClass[][] $originalObjects
* @param stdClass[] $freshObjects
* @param array{aaa: list{stdClass}, bbb: list{stdClass}} $originalObjects
* @param array{aaa: stdClass, bbb: stdClass} $freshObjects
*/
private function assertSuccessfulReFetchesInNestedIterableResult(SimpleBatchIteratorAggregate $iterator, array $originalObjects, array $freshObjects): void
{
$this->metadata->method('getIdentifierValues')->willReturnMap(
[
[$originalObjects[0][0], ['id' => 123]],
[$originalObjects[1][0], ['id' => 456]],
[$originalObjects['aaa'][0], ['id' => 123]],
[$originalObjects['bbb'][0], ['id' => 456]],
],
);
$this->entityManager->expects(self::exactly(count($originalObjects)))->method('find')->willReturnMap(
[
[stdClass::class, ['id' => 123], null, null, $freshObjects[0]],
[stdClass::class, ['id' => 456], null, null, $freshObjects[1]],
[stdClass::class, ['id' => 123], null, null, $freshObjects['aaa']],
[stdClass::class, ['id' => 456], null, null, $freshObjects['bbb']],
],
);

Expand All @@ -213,7 +212,13 @@ private function assertSuccessfulReFetchesInNestedIterableResult(SimpleBatchIter
$iteratedObjects[$key] = $value;
}

$this->assertSame([$freshObjects[0], $freshObjects[1]], $iteratedObjects);
$this->assertSame(
[
'aaa' => $freshObjects['aaa'],
'bbb' => $freshObjects['bbb'],
],
$iteratedObjects,
);
}

/**
Expand Down Expand Up @@ -247,6 +252,7 @@ public function testWillNotReFetchEntitiesInNonIterableAlikeResult(): void
*
* @dataProvider iterationFlushesProvider
*/
#[DataProvider('iterationFlushesProvider')]
public function testIterationFlushesAtGivenBatchSizes(int $resultItemsCount, int $batchSize, string $expectOutputString): void
{
$object = new stdClass();
Expand All @@ -272,7 +278,7 @@ public function testIterationFlushesAtGivenBatchSizes(int $resultItemsCount, int
}

/** @return non-empty-list<array{int<1, max>, int<1, max>, non-empty-string}> */
public function iterationFlushesProvider(): array
public static function iterationFlushesProvider(): array
{
return [
[10, 5, "beginTransaction\nflush\nclear\nflush\nclear\nflush\nclear\ncommit\n"],
Expand Down

0 comments on commit 35b164e

Please sign in to comment.