Make data providers static on AbstractExportTest.php and Write a rector rule to adapt existing

This commit is contained in:
2024-02-16 21:49:27 +01:00
parent b9ae878791
commit 07f03ab715
11 changed files with 489 additions and 11 deletions

View File

@@ -0,0 +1,54 @@
<?php
namespace Chill\PersonBundle\Tests\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ClosingDateAggregator;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
class ClosingDateAggregatorTest extends AbstractAggregatorTest
{
private static ClosingDateAggregator $closingDateAggregator;
private static EntityManagerInterface $entityManager;
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
self::bootKernel();
self::$closingDateAggregator = self::getContainer()->get(ClosingDateAggregator::class);
self::$entityManager = self::getContainer()->get(EntityManagerInterface::class);
}
public function getAggregator()
{
return self::$closingDateAggregator;
}
public static function getFormData(): array
{
yield ['frequency' => 'YYYY'];
yield ['frequency' => 'YYYY-MM'];
yield ['frequency' => 'YYYY-IV'];
}
public static function getQueryBuilders(): iterable
{
self::bootKernel();
self::$entityManager = self::getContainer()->get(EntityManagerInterface::class);
$data = [
self::$entityManager->createQueryBuilder()
->select('count(acp.id)')
->from(AccompanyingPeriod::class, 'acp'),
];
self::ensureKernelShutdown();
return $data;
}
}

View File

@@ -0,0 +1,112 @@
<?php
namespace Chill\PersonBundle\Tests\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ClosingDateAggregator;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
class ClosingDateAggregatorTest extends AbstractAggregatorTest
{
private static ClosingDateAggregator $closingDateAggregator;
private static EntityManagerInterface $entityManager;
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
self::bootKernel();
self::$closingDateAggregator = self::getContainer()->get(ClosingDateAggregator::class);
self::$entityManager = self::getContainer()->get(EntityManagerInterface::class);
}
public function getAggregator()
{
return self::$closingDateAggregator;
}
public function getFormData()
{
yield ['frequency' => 'YYYY'];
yield ['frequency' => 'YYYY-MM'];
yield ['frequency' => 'YYYY-IV'];
}
public function getQueryBuilders()
{
self::bootKernel();
self::$entityManager = self::getContainer()->get(EntityManagerInterface::class);
$data = [
self::$entityManager->createQueryBuilder()
->select('count(acp.id)')
->from(AccompanyingPeriod::class, 'acp'),
];
self::ensureKernelShutdown();
return $data;
}
}
-----
<?php
namespace Chill\PersonBundle\Tests\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ClosingDateAggregator;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
class ClosingDateAggregatorTest extends AbstractAggregatorTest
{
private static ClosingDateAggregator $closingDateAggregator;
private static EntityManagerInterface $entityManager;
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
self::bootKernel();
self::$closingDateAggregator = self::getContainer()->get(ClosingDateAggregator::class);
self::$entityManager = self::getContainer()->get(EntityManagerInterface::class);
}
public function getAggregator()
{
return self::$closingDateAggregator;
}
public static function getFormData(): array
{
yield ['frequency' => 'YYYY'];
yield ['frequency' => 'YYYY-MM'];
yield ['frequency' => 'YYYY-IV'];
}
public static function getQueryBuilders(): iterable
{
self::bootKernel();
self::$entityManager = self::getContainer()->get(EntityManagerInterface::class);
$data = [
self::$entityManager->createQueryBuilder()
->select('count(acp.id)')
->from(AccompanyingPeriod::class, 'acp'),
];
self::ensureKernelShutdown();
return $data;
}
}

View File

@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\Utils\Rector\Tests\ChillBundleMakeDataProviderStaticForAbstractExportTestRectorTest;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
/**
* @internal
*
* @coversNothing
*/
class ChillBundleMakeDataProviderStaticForAbstractExportTestRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData
*/
public function test(string $file): void
{
$this->doTestFile($file);
}
public static function provideData(): \Iterator
{
return self::yieldFilesFromDirectory(__DIR__.'/Fixture');
}
public function provideConfigFilePath(): string
{
return __DIR__.'/config/config.php';
}
}

View File

@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Export\Export;
use Chill\MainBundle\Test\Export\AbstractExportTest;
use Chill\PersonBundle\Export\Export\CountPerson;
use Chill\PersonBundle\Repository\PersonRepository;
/**
* Test CountPerson export.
*
* @internal
*
* @coversNothing
*/
final class CountPersonTest extends AbstractExportTest
{
protected function setUp(): void
{
self::bootKernel();
}
public function getExport()
{
$personRepository = self::getContainer()->get(PersonRepository::class);
yield new CountPerson($personRepository, $this->getParameters(true));
yield new CountPerson($personRepository, $this->getParameters(false));
}
public static function getFormData(): array
{
return [
[],
];
}
public static function getModifiersCombination(): array
{
return [['person']];
}
}

View File

@@ -0,0 +1,103 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Export\Export;
use Chill\MainBundle\Test\Export\AbstractExportTest;
use Chill\PersonBundle\Export\Export\CountPerson;
use Chill\PersonBundle\Repository\PersonRepository;
/**
* Test CountPerson export.
*
* @internal
*
* @coversNothing
*/
final class CountPersonTest extends AbstractExportTest
{
protected function setUp(): void
{
self::bootKernel();
}
public function getExport()
{
$personRepository = self::getContainer()->get(PersonRepository::class);
yield new CountPerson($personRepository, $this->getParameters(true));
yield new CountPerson($personRepository, $this->getParameters(false));
}
public function getFormData()
{
return [
[],
];
}
public function getModifiersCombination()
{
return [['person']];
}
}
-----
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Export\Export;
use Chill\MainBundle\Test\Export\AbstractExportTest;
use Chill\PersonBundle\Export\Export\CountPerson;
use Chill\PersonBundle\Repository\PersonRepository;
/**
* Test CountPerson export.
*
* @internal
*
* @coversNothing
*/
final class CountPersonTest extends AbstractExportTest
{
protected function setUp(): void
{
self::bootKernel();
}
public function getExport()
{
$personRepository = self::getContainer()->get(PersonRepository::class);
yield new CountPerson($personRepository, $this->getParameters(true));
yield new CountPerson($personRepository, $this->getParameters(false));
}
public static function getFormData(): array
{
return [
[],
];
}
public static function getModifiersCombination(): array
{
return [['person']];
}
}

View File

@@ -0,0 +1,5 @@
<?php
class MyException extends \RuntimeException
{
}

View File

@@ -0,0 +1,5 @@
<?php
final readonly class MyClass {
}

View File

@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
return static function (Rector\Config\RectorConfig $rectorConfig): void {
$rectorConfig->rule(Chill\Utils\Rector\Rector\ChillBundleMakeDataProviderStaticForAbstractExportTestRector::class);
};