Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various (minor) issues #192

Merged
merged 11 commits into from
Dec 19, 2021
4 changes: 4 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
)
->append([
__DIR__.'/.php_cs.dist',
__DIR__.'/bin/console',
__DIR__.'/bin/doctrine_purge',
__DIR__.'/bin/eloquent_migrate',
__DIR__.'/bin/eloquent_rollback',
])
;

Expand Down
18 changes: 10 additions & 8 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,34 @@ use Symfony\Component\HttpKernel\KernelInterface;

$serverArgs = &$_SERVER['argv'];
$kernelInput = 'NakedKernel';

foreach ($serverArgs as $index => $arg) {
if ('-k' === $arg || '--kernel' === $arg) {
$kernelInput = $serverArgs[$index + 1];
unset($serverArgs[$index]);
unset($serverArgs[$index + 1]);
unset($serverArgs[$index], $serverArgs[$index + 1]);

break;
}

if ('-k=' === substr($arg, 0, 3)) {
$kernelInput = substr($serverArgs[$index], 3);
if (str_starts_with($arg, '-k=')) {
$kernelInput = substr($arg, 3);
unset($serverArgs[$index]);
break;
}

if ('--kernel=' === substr($arg, 0, 9)) {
$kernelInput = substr($serverArgs[$index], 9);
if (str_starts_with($arg, '--kernel=')) {
$kernelInput = substr($arg, 9);
unset($serverArgs[$index]);
break;
}
}

$serverArgs = array_values($serverArgs);
$kernelClass = 'Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp\\'.$kernelInput;

$input = new ArgvInput();
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: uniqid());
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod';
$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: bin2hex(random_bytes(6)));
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod';

if ($debug) {
Debug::enable();
Expand Down
2 changes: 2 additions & 0 deletions fixtures/Bridge/Eloquent/MigratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
use Fidry\AliceDataFixtures\Bridge\Eloquent\Migration\FakeMigrationRepository;
use Illuminate\Database\Migrations\Migrator;
use Illuminate\Filesystem\Filesystem;
use JetBrains\PhpStorm\Pure;

class MigratorFactory
{
#[Pure]
public static function create(): Migrator
{
return new Migrator(
Expand Down
9 changes: 0 additions & 9 deletions fixtures/Bridge/Eloquent/Model/AnotherDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,14 @@

class AnotherDummy extends Model
{
/**
* @inheritdoc
*/
protected $table = 'another_dummies';

/**
* @inheritdoc
*/
protected $fillable = [
'id',
'address',
'dummy',
];

/**
* @inheritdoc
*/
public $timestamps = false;

public function dummy(): BelongsTo
Expand Down
2 changes: 2 additions & 0 deletions fixtures/Bridge/Symfony/Entity/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use JetBrains\PhpStorm\Pure;

class Group
{
Expand All @@ -25,6 +26,7 @@ class Group
*/
private Collection $users;

#[Pure]
public function __construct()
{
$this->users = new ArrayCollection();
Expand Down
2 changes: 2 additions & 0 deletions fixtures/Bridge/Symfony/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use JetBrains\PhpStorm\Pure;

class User
{
Expand All @@ -25,6 +26,7 @@ class User
*/
private Collection $groups;

#[Pure]
public function __construct()
{
$this->groups = new ArrayCollection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class DoctrineBundle extends Bundle
{
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

class DoctrineConnectionlessPass implements CompilerPassInterface
{
/**
* @inheritdoc
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
try {
$proxyCacheWarmerDefinition = $container->findDefinition('doctrine.orm.proxy_cache_warmer');
Expand Down
2 changes: 2 additions & 0 deletions fixtures/Bridge/Symfony/SymfonyApp/InvalidKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
namespace Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp;

use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle;
use JetBrains\PhpStorm\Pure;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;

class InvalidKernel extends IsolatedKernel
{
#[Pure]
public function registerBundles(): array
{
return [
Expand Down
10 changes: 6 additions & 4 deletions fixtures/Bridge/Symfony/SymfonyApp/IsolatedKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp;

use function bin2hex;
use function random_bytes;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
Expand All @@ -27,24 +29,24 @@ abstract class IsolatedKernel extends Kernel
*/
public static function create()
{
return new static(uniqid(), true);
return new static(bin2hex(random_bytes(6)), true);
}

public function build(ContainerBuilder $container): void
{
$container->addCompilerPass(
new class() implements CompilerPassInterface {
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
foreach ($container->getDefinitions() as $id => $definition) {
if (strpos($id, 'fidry_alice_data_fixtures') !== 0) {
if (!str_starts_with($id, 'fidry_alice_data_fixtures')) {
continue;
}

$definition->setPublic(true);
}
foreach ($container->getAliases() as $id => $definition) {
if (strpos($id, 'fidry_alice_data_fixtures') !== 0) {
if (!str_starts_with($id, 'fidry_alice_data_fixtures')) {
continue;
}

Expand Down
2 changes: 2 additions & 0 deletions fixtures/Bridge/Symfony/SymfonyApp/NakedKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
namespace Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp;

use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle;
use JetBrains\PhpStorm\Pure;
use Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;

class NakedKernel extends IsolatedKernel
{
#[Pure]
public function registerBundles(): array
{
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Fidry\AliceDataFixtures\Bridge\Symfony\DependencyInjection\Compiler;

use JetBrains\PhpStorm\Pure;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

Expand All @@ -25,6 +26,7 @@ final class RegisterTagServicesPass implements CompilerPassInterface
private string $tagName;
private TaggedDefinitionsLocator $taggedDefinitionsLocator;

#[Pure]
public function __construct(string $registry, string $tagName)
{
$this->registry = $registry;
Expand Down
3 changes: 0 additions & 3 deletions src/Bridge/Symfony/FidryAliceDataFixturesBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@

final class FidryAliceDataFixturesBundle extends Bundle
{
/**
* @inheritdoc
*/
public function build(ContainerBuilder $container): void
{
parent::build($container);
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/MaxPassReachedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Fidry\AliceDataFixtures\Loader\ErrorTracker;
use Fidry\AliceDataFixtures\Loader\FileTracker;
use JetBrains\PhpStorm\Pure;
use Nelmio\Alice\Throwable\LoadingThrowable;
use RuntimeException;
use Throwable;
Expand All @@ -29,6 +30,7 @@ class MaxPassReachedException extends RuntimeException implements LoadingThrowab
*/
private array $stack = [];

#[Pure]
public function __construct($message, $code = 0, Throwable $previous = null, ErrorTracker $errorTracker = null)
{
parent::__construct($message, $code, $previous);
Expand Down
2 changes: 2 additions & 0 deletions src/Loader/FileResolverLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Fidry\AliceDataFixtures\Persistence\PersisterAwareInterface;
use Fidry\AliceDataFixtures\Persistence\PersisterInterface;
use Fidry\AliceDataFixtures\Persistence\PurgeMode;
use JetBrains\PhpStorm\Pure;
use Nelmio\Alice\IsAServiceTrait;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
Expand All @@ -35,6 +36,7 @@
private FileResolverInterface $fileResolver;
private LoggerInterface $logger;

#[Pure]
public function __construct(
LoaderInterface $decoratedLoader,
FileResolverInterface $fileResolver,
Expand Down
2 changes: 2 additions & 0 deletions src/Loader/PersisterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Fidry\AliceDataFixtures\Persistence\PersisterInterface;
use Fidry\AliceDataFixtures\Persistence\PurgeMode;
use Fidry\AliceDataFixtures\ProcessorInterface;
use JetBrains\PhpStorm\Pure;
use Nelmio\Alice\IsAServiceTrait;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
Expand All @@ -42,6 +43,7 @@
/**
* @param ProcessorInterface[] $processors
*/
#[Pure]
public function __construct(
LoaderInterface $decoratedLoader,
PersisterInterface $persister,
Expand Down
2 changes: 2 additions & 0 deletions src/Loader/SimpleLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Fidry\AliceDataFixtures\LoaderInterface;
use Fidry\AliceDataFixtures\Persistence\PurgeMode;
use JetBrains\PhpStorm\Pure;
use Nelmio\Alice\FilesLoaderInterface;
use Nelmio\Alice\IsAServiceTrait;
use Psr\Log\LoggerInterface;
Expand All @@ -35,6 +36,7 @@
private FilesLoaderInterface $filesLoader;
private LoggerInterface $logger;

#[Pure]
public function __construct(FilesLoaderInterface $fileLoader, LoggerInterface $logger = null)
{
$this->filesLoader = $fileLoader;
Expand Down
30 changes: 15 additions & 15 deletions tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public function tearDown(): void

public function testIsAPersister(): void
{
$this->assertTrue(is_a(ObjectManagerPersister::class, PersisterInterface::class, true));
self::assertTrue(is_a(ObjectManagerPersister::class, PersisterInterface::class, true));
}

public function testIsNotClonable(): void
{
$this->assertFalse((new ReflectionClass(ObjectManagerPersister::class))->isCloneable());
self::assertFalse((new ReflectionClass(ObjectManagerPersister::class))->isCloneable());
}

/**
Expand All @@ -75,10 +75,10 @@ public function testCanPersistAnEntity($entity, bool $exact = false): void

$result = $this->entityManager->getRepository(get_class($entity))->findAll();

$this->assertEquals(1, count($result));
self::assertCount(1, $result);

if ($exact) {
$this->assertEquals($originalEntity, $result[0]);
self::assertEquals($originalEntity, $result[0]);
}
}

Expand All @@ -98,12 +98,12 @@ public function testCanPersistAnEntityWithRelationsAndExplicitIds(): void
$this->entityManager->clear();

$result = $this->entityManager->getRepository(DummyWithIdentifier::class)->findOneBy(['id' => 100]);
$this->assertInstanceOf(DummyWithIdentifier::class, $result);
$this->assertEquals($result->id, $dummy->id);
self::assertInstanceOf(DummyWithIdentifier::class, $result);
self::assertEquals($result->id, $dummy->id);

$result = $this->entityManager->getRepository(DummyWithRelation::class)->findOneBy(['id' => 200]);
$this->assertInstanceOf(DummyWithRelation::class, $result);
$this->assertEquals($result->id, $dummyWithRelation->id);
self::assertInstanceOf(DummyWithRelation::class, $result);
self::assertEquals($result->id, $dummyWithRelation->id);
}

public function testCanPersistMultipleEntitiesWithExplicitIdentifierSet(): void
Expand All @@ -118,7 +118,7 @@ public function testCanPersistMultipleEntitiesWithExplicitIdentifierSet(): void

$classMetadata = $this->entityManager->getClassMetadata(DummyWithIdentifier::class);

$this->assertEquals(
self::assertEquals(
IdGenerator::class,
get_class($classMetadata->idGenerator),
'ID generator should be changed.'
Expand All @@ -128,14 +128,14 @@ public function testCanPersistMultipleEntitiesWithExplicitIdentifierSet(): void

$classMetadata = $this->entityManager->getClassMetadata(DummyWithIdentifier::class);

$this->assertNotEquals(
self::assertNotEquals(
IdGenerator::class,
get_class($classMetadata->idGenerator),
'ID generator should be restored after flush.'
);

$entity = $this->entityManager->getRepository(DummyWithIdentifier::class)->find(200);
$this->assertInstanceOf(DummyWithIdentifier::class, $entity);
self::assertInstanceOf(DummyWithIdentifier::class, $entity);
}

public function testCanPersistEntitiesWithoutExplicitIdentifierSetEvenWhenExistingEntitiesHaveOne(): void
Expand Down Expand Up @@ -171,10 +171,10 @@ public function testCanPersistEntitiesWithoutExplicitIdentifierSetEvenWhenExisti
$this->persister->flush();

$entity = $this->entityManager->getRepository(Dummy::class)->find($dummy1->id);
$this->assertInstanceOf(Dummy::class, $entity);
self::assertInstanceOf(Dummy::class, $entity);

$entity = $this->entityManager->getRepository(Dummy::class)->find($dummy2->id);
$this->assertInstanceOf(Dummy::class, $entity);
self::assertInstanceOf(Dummy::class, $entity);
}

public function testPersistingMultipleEntitiesWithAndWithoutExplicitIdentifierSetWillNotThrowORMException(): void
Expand Down Expand Up @@ -210,7 +210,7 @@ public function testDoesNotPersistEmbeddables($dummy): void
$this->persister->persist($dummy);
$this->persister->flush();

$this->assertTrue(true, 'Everything is fine.');
self::assertTrue(true, 'Everything is fine.');
}

public static function provideEntities(): iterable
Expand Down Expand Up @@ -238,7 +238,7 @@ public static function provideEntities(): iterable
];

yield 'entity with explicit ID' => [
(function () {
(static function () {
$dummy = new DummyWithIdentifier();
$dummy->id = 300;

Expand Down
Loading