Skip to content

Commit

Permalink
Merge branch '2.x' into 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Oct 17, 2021
2 parents 838b41c + 20ca9dd commit f565b20
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ jobs:
with:
args: --short --error-format=github
env:
DOCS_DIR: 'docs/'
DOCS_DIR: docs/
30 changes: 22 additions & 8 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,38 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Run PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga:3.0.0
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
args: --ansi --verbose --diff --dry-run
php-version: '8.0'
coverage: none
tools: composer:v2, php-cs-fixer:3
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

composer-normalize:
name: composer-normalize
- name: Lint PHP files
run: make lint-php

composer:
name: Composer

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Run composer-normalize
uses: docker://ergebnis/composer-normalize-action:0.8.0
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
args: --dry-run
php-version: '8.0'
coverage: none
tools: composer:v2, composer-normalize:2
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Lint Composer
run: make lint-composer

yaml-files:
name: YAML files
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ jobs:
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: '8.0'
coverage: none
tools: composer:v2
extensions: mongodb-1.9.0

- name: Install Composer dependencies (highest)
uses: "ramsey/composer-install@v1"
uses: ramsey/composer-install@v1
with:
dependency-versions: "highest"
composer-options: "--prefer-dist --prefer-stable"
dependency-versions: highest
composer-options: --prefer-dist --prefer-stable

- name: PHPStan
run: vendor/bin/phpstan --memory-limit=1G analyse
run: vendor/bin/phpstan --memory-limit=1G analyse --error-format=github
psalm:
name: Psalm

Expand All @@ -49,16 +49,16 @@ jobs:
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: '8.0'
coverage: none
tools: composer:v2
extensions: mongodb-1.9.0

- name: Install Composer dependencies (highest)
uses: "ramsey/composer-install@v1"
uses: ramsey/composer-install@v1
with:
dependency-versions: "highest"
composer-options: "--prefer-dist --prefer-stable"
dependency-versions: highest
composer-options: --prefer-dist --prefer-stable

- name: Psalm
run: vendor/bin/psalm --show-info=false --stats --output-format=github --threads=$(nproc) --shepherd --php-version=8.0
2 changes: 1 addition & 1 deletion .github/workflows/stale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name: Stale

on:
schedule:
- cron: "0 9-18 * * *"
- cron: 0 9-18 * * *

jobs:
stale:
Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- '8.0'
dependencies: [highest]
allowed-to-fail: [false]
symfony-require: [""]
symfony-require: ['']
variant: [normal]
include:
- php-version: '7.3'
Expand All @@ -47,17 +47,17 @@ jobs:
dependencies: highest
allowed-to-fail: false
symfony-require: 4.4.*
variant: 'symfony/symfony:"4.4.*"'
variant: symfony/symfony:"4.4.*"
- php-version: '8.0'
dependencies: highest
allowed-to-fail: false
symfony-require: 5.3.*
variant: 'symfony/symfony:"5.3.*"'
variant: symfony/symfony:"5.3.*"
- php-version: '8.0'
dependencies: highest
allowed-to-fail: false
symfony-require: 5.4.*
variant: 'symfony/symfony:"5.4.*"'
variant: symfony/symfony:"5.4.*"

steps:
- name: Checkout
Expand All @@ -74,9 +74,9 @@ jobs:
- name: Add PHPUnit matcher
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: "Globally install symfony/flex"
- name: Globally install symfony/flex
if: matrix.symfony-require != ''
run: "composer global require --no-progress --no-scripts --no-plugins symfony/flex"
run: composer global require --no-progress --no-scripts --no-plugins symfony/flex

- name: Install variant
if: matrix.variant != 'normal' && !startsWith(matrix.variant, 'symfony/symfony')
Expand All @@ -89,16 +89,16 @@ jobs:
if: matrix.symfony-require == '6.0.*'
run: composer remove vimeo/psalm psalm/plugin-phpunit psalm/plugin-symfony weirdan/doctrine-psalm-plugin --dev --no-update --no-interaction

- name: "Install Composer dependencies (${{ matrix.dependencies }})"
uses: "ramsey/composer-install@v1"
- name: Install Composer dependencies (${{ matrix.dependencies }})
uses: ramsey/composer-install@v1
with:
dependency-versions: "${{ matrix.dependencies }}"
composer-options: "--prefer-dist --prefer-stable"
dependency-versions: ${{ matrix.dependencies }}
composer-options: --prefer-dist --prefer-stable

- name: Run Tests with coverage
run: make coverage

- name: Send coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v2
with:
file: build/logs/clover.xml
9 changes: 3 additions & 6 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@
'@PHPUnit60Migration:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => [
'syntax' => 'short',
],
'array_syntax' => ['syntax' => 'short'],
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'compact_nullable_typehint' => true,
'global_namespace_import' => ['import_classes' => false, 'import_constants' => false, 'import_functions' => false],
'header_comment' => [
'header' => $header,
],
'header_comment' => ['header' => $header],
'list_syntax' => ['syntax' => 'short'],
'logical_operators' => true,
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
Expand All @@ -56,6 +52,7 @@
'static_lambda' => true,
'strict_comparison' => true,
'strict_param' => true,
'types_spaces' => ['space' => 'single'],
'void_return' => false,
];

Expand Down
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ lint: lint-composer lint-yaml lint-xml lint-xliff lint-php
.PHONY: lint

lint-composer:
composer-normalize --dry-run
composer validate
.PHONY: lint-composer

Expand Down Expand Up @@ -46,7 +47,7 @@ lint-php:
php-cs-fixer fix --ansi --verbose --diff --dry-run
.PHONY: lint-php

cs-fix: cs-fix-php cs-fix-xml cs-fix-xliff
cs-fix: cs-fix-php cs-fix-xml cs-fix-xliff cs-fix-composer
.PHONY: cs-fix

cs-fix-php:
Expand All @@ -73,15 +74,19 @@ cs-fix-xliff:
done
.PHONY: cs-fix-xliff

cs-fix-composer:
composer-normalize
.PHONY: cs-fix-composer

build:
mkdir $@

test:
vendor/bin/simple-phpunit -c phpunit.xml.dist
vendor/bin/phpunit -c phpunit.xml.dist
.PHONY: test

coverage:
vendor/bin/simple-phpunit -c phpunit.xml.dist --coverage-clover build/logs/clover.xml
vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover build/logs/clover.xml
.PHONY: coverage

docs:
Expand Down
9 changes: 1 addition & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"phpstan/phpstan-phpunit": "^0.12.18",
"phpstan/phpstan-strict-rules": "^0.12.10",
"phpstan/phpstan-symfony": "^0.12.21",
"phpunit/phpunit": "^9.5",
"propel/propel1": "^1.6",
"psalm/plugin-phpunit": "^0.16",
"psalm/plugin-symfony": "^2.0",
Expand Down Expand Up @@ -69,13 +70,5 @@
"psr-4": {
"Sonata\\Exporter\\Tests\\": "tests/"
}
},
"scripts": {
"post-install-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/simple-phpunit install"
],
"post-update-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/simple-phpunit install"
]
}
}
2 changes: 0 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ includes:

parameters:
level: 2
bootstrapFiles:
- vendor/bin/.phpunit/phpunit/vendor/autoload.php
paths:
- src
- tests
Expand Down
6 changes: 4 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ It's auto-generated by sonata-project/dev-kit package.
</include>
</coverage>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>

<php>
<ini name="precision" value="8" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0" />
<env name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
</php>

</phpunit>
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="8" findUnusedPsalmSuppress="true" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" autoloader="vendor/bin/.phpunit/phpunit/vendor/autoload.php">
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="8" findUnusedPsalmSuppress="true" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
<projectFiles>
<directory name="src"/>
<directory name="tests"/>
Expand Down
13 changes: 11 additions & 2 deletions src/Source/DoctrineODMQuerySourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ final class DoctrineODMQuerySourceIterator extends AbstractPropertySourceIterato
*/
private $query;

/**
* @var int
*/
private $batchSize;

/**
* @param array<string> $fields Fields to export
*/
public function __construct(Query $query, array $fields, string $dateTimeFormat = \DateTimeInterface::ATOM)
public function __construct(Query $query, array $fields, string $dateTimeFormat = \DateTimeInterface::ATOM, int $batchSize = 100)
{
$this->query = clone $query;

$this->batchSize = $batchSize;

parent::__construct($fields, $dateTimeFormat);
}

Expand All @@ -41,7 +48,9 @@ public function current()

$data = $this->getCurrentData($current);

$this->query->getDocumentManager()->clear();
if (0 === ($this->iterator->key() % $this->batchSize)) {
$this->query->getDocumentManager()->clear();
}

return $data;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Source/DoctrineODMQuerySourceIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ public function testHandler(): void
static::assertCount(3, iterator_to_array($iterator));
}

public function testEntityManagerClear(): void
{
$query = $this->dm->createQueryBuilder(Document::class)->getQuery();

$batchSize = 2;
$iterator = new DoctrineODMQuerySourceIterator($query, ['id'], 'r', $batchSize);

foreach ($iterator as $i => $item) {
static::assertSame(0 === $i % $batchSize ? 0 : $i, $this->dm->getUnitOfWork()->size());
}
}

private function createConfiguration(): Configuration
{
$config = new Configuration();
Expand Down

0 comments on commit f565b20

Please sign in to comment.