Skip to content

Commit

Permalink
bot: fix cs [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
nikophil authored and kbond committed Oct 23, 2024
1 parent df568da commit 68b807b
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/Mongo/MongoPersistenceStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\MappingException as MongoMappingException;
use Doctrine\Persistence\Mapping\MappingException;
use Symfony\Component\HttpKernel\KernelInterface;
use Zenstruck\Foundry\Persistence\PersistenceStrategy;

/**
Expand Down
9 changes: 9 additions & 0 deletions src/Mongo/MongoResetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

declare(strict_types=1);

/*
* This file is part of the zenstruck/foundry package.
*
* (c) Kevin Bond <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zenstruck\Foundry\Mongo;

use Zenstruck\Foundry\Persistence\ResetDatabase\BeforeEachTestResetter;
Expand Down
9 changes: 9 additions & 0 deletions src/Mongo/MongoSchemaResetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

declare(strict_types=1);

/*
* This file is part of the zenstruck/foundry package.
*
* (c) Kevin Bond <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zenstruck\Foundry\Mongo;

use Symfony\Component\HttpKernel\KernelInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/AbstractORMPersistenceStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final public function hasChanges(object $object): bool
// cannot use UOW::recomputeSingleEntityChangeSet() here as it wrongly computes embedded objects as changed
$em->getUnitOfWork()->computeChangeSet($em->getClassMetadata($object::class), $object);

return (bool)$em->getUnitOfWork()->getEntityChangeSet($object);
return (bool) $em->getUnitOfWork()->getEntityChangeSet($object);
}

final public function truncate(string $class): void
Expand Down
9 changes: 9 additions & 0 deletions src/ORM/ResetDatabase/DamaDatabaseResetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

declare(strict_types=1);

/*
* This file is part of the zenstruck/foundry package.
*
* (c) Kevin Bond <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zenstruck\Foundry\ORM\ResetDatabase;

use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver;
Expand Down
11 changes: 10 additions & 1 deletion src/ORM/ResetDatabase/OrmResetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

declare(strict_types=1);

/*
* This file is part of the zenstruck/foundry package.
*
* (c) Kevin Bond <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zenstruck\Foundry\ORM\ResetDatabase;

use Zenstruck\Foundry\Persistence\ResetDatabase\BeforeFirstTestResetter;
use Zenstruck\Foundry\Persistence\ResetDatabase\BeforeEachTestResetter;
use Zenstruck\Foundry\Persistence\ResetDatabase\BeforeFirstTestResetter;

/**
* @author Nicolas PHILIPPE <[email protected]>
Expand Down
13 changes: 11 additions & 2 deletions src/ORM/ResetDatabase/SchemaDatabaseResetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

declare(strict_types=1);

/*
* This file is part of the zenstruck/foundry package.
*
* (c) Kevin Bond <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zenstruck\Foundry\ORM\ResetDatabase;

use Symfony\Bundle\FrameworkBundle\Console\Application;
Expand All @@ -13,15 +22,15 @@
*/
final class SchemaDatabaseResetter extends BaseOrmResetter implements OrmResetter
{
final public function resetBeforeFirstTest(KernelInterface $kernel): void
public function resetBeforeFirstTest(KernelInterface $kernel): void
{
$application = self::application($kernel);

$this->dropAndResetDatabase($application);
$this->createSchema($application);
}

final public function resetBeforeEachTest(KernelInterface $kernel): void
public function resetBeforeEachTest(KernelInterface $kernel): void
{
$application = self::application($kernel);

Expand Down
8 changes: 4 additions & 4 deletions src/Persistence/PersistenceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public function embeddablePropertiesFor(object $object, string $owner): ?array
public function hasPersistenceFor(object $object): bool
{
try {
return (bool)$this->strategyFor($object::class);
return (bool) $this->strategyFor($object::class);
} catch (NoPersistenceStrategy) {
return false;
}
Expand All @@ -284,14 +284,14 @@ public static function isOrmOnly(): bool
{
static $isOrmOnly = null;

return $isOrmOnly ??= (static function (): bool {
return $isOrmOnly ??= (static function(): bool {
try {
$strategies = iterator_to_array(Configuration::instance()->persistence()->strategies);
$strategies = \iterator_to_array(Configuration::instance()->persistence()->strategies);
} catch (PersistenceNotAvailable) {
$strategies = [];
}

return count($strategies) === 1 && $strategies[0] instanceof AbstractORMPersistenceStrategy;
return 1 === \count($strategies) && $strategies[0] instanceof AbstractORMPersistenceStrategy;
})();
}

Expand Down
9 changes: 9 additions & 0 deletions src/Persistence/ResetDatabase/BeforeEachTestResetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

declare(strict_types=1);

/*
* This file is part of the zenstruck/foundry package.
*
* (c) Kevin Bond <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zenstruck\Foundry\Persistence\ResetDatabase;

use Symfony\Component\HttpKernel\KernelInterface;
Expand Down
9 changes: 9 additions & 0 deletions src/Persistence/ResetDatabase/BeforeFirstTestResetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

declare(strict_types=1);

/*
* This file is part of the zenstruck/foundry package.
*
* (c) Kevin Bond <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zenstruck\Foundry\Persistence\ResetDatabase;

use Symfony\Component\HttpKernel\KernelInterface;
Expand Down
25 changes: 17 additions & 8 deletions src/Persistence/ResetDatabase/ResetDatabaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

declare(strict_types=1);

/*
* This file is part of the zenstruck/foundry package.
*
* (c) Kevin Bond <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zenstruck\Foundry\Persistence\ResetDatabase;

use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver;
Expand All @@ -21,17 +30,17 @@ final class ResetDatabaseManager

/**
* @param iterable<BeforeFirstTestResetter> $beforeFirstTestResetters
* @param iterable<BeforeEachTestResetter> $beforeEachTestResetter
* @param iterable<BeforeEachTestResetter> $beforeEachTestResetter
*/
public function __construct(
private iterable $beforeFirstTestResetters,
private iterable $beforeEachTestResetter
private iterable $beforeEachTestResetter,
) {
}

/**
* @param callable():KernelInterface $createKernel
* @param callable():void $shutdownKernel
* @param callable():void $shutdownKernel
*/
public static function resetBeforeFirstTest(callable $createKernel, callable $shutdownKernel): void
{
Expand Down Expand Up @@ -64,7 +73,7 @@ public static function resetBeforeFirstTest(callable $createKernel, callable $sh

/**
* @param callable():KernelInterface $createKernel
* @param callable():void $shutdownKernel
* @param callable():void $shutdownKernel
*/
public static function resetBeforeEachTest(callable $createKernel, callable $shutdownKernel): void
{
Expand Down Expand Up @@ -96,13 +105,13 @@ public static function resetBeforeEachTest(callable $createKernel, callable $shu
$shutdownKernel();
}

private static function canSkipSchemaReset(): bool
public static function isDAMADoctrineTestBundleEnabled(): bool
{
return PersistenceManager::isOrmOnly() && self::isDAMADoctrineTestBundleEnabled();
return \class_exists(StaticDriver::class) && StaticDriver::isKeepStaticConnections();
}

public static function isDAMADoctrineTestBundleEnabled(): bool
private static function canSkipSchemaReset(): bool
{
return \class_exists(StaticDriver::class) && StaticDriver::isKeepStaticConnections();
return PersistenceManager::isOrmOnly() && self::isDAMADoctrineTestBundleEnabled();
}
}
9 changes: 9 additions & 0 deletions src/Persistence/SymfonyCommandRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

declare(strict_types=1);

/*
* This file is part of the zenstruck/foundry package.
*
* (c) Kevin Bond <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zenstruck\Foundry\Persistence;

use Symfony\Bundle\FrameworkBundle\Console\Application;
Expand Down
3 changes: 1 addition & 2 deletions src/Test/ResetDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\Attributes\BeforeClass;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Zenstruck\Foundry\Persistence\PersistenceManager;

use Zenstruck\Foundry\Persistence\ResetDatabase\ResetDatabaseManager;

use function Zenstruck\Foundry\restorePhpUnitErrorHandler;

/**
Expand Down
6 changes: 3 additions & 3 deletions src/ZenstruckFoundryBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ public function loadExtension(array $config, ContainerConfigurator $configurator

/** @var ResetDatabaseMode $resetMode */
$resetMode = $config['orm']['reset']['mode'];
$toRemove = $resetMode === ResetDatabaseMode::SCHEMA ? ResetDatabaseMode::MIGRATE->value : ResetDatabaseMode::SCHEMA->value;
$toRemove = ResetDatabaseMode::SCHEMA === $resetMode ? ResetDatabaseMode::MIGRATE->value : ResetDatabaseMode::SCHEMA->value;

$container->removeDefinition(".zenstruck_foundry.persistence.database_resetter.orm.$toRemove.dama");
$container->removeDefinition(".zenstruck_foundry.persistence.database_resetter.orm.$toRemove");
$container->removeDefinition(".zenstruck_foundry.persistence.database_resetter.orm.{$toRemove}.dama");
$container->removeDefinition(".zenstruck_foundry.persistence.database_resetter.orm.{$toRemove}");

$container->setAlias(OrmResetter::class, ".zenstruck_foundry.persistence.database_resetter.orm.{$resetMode->value}");
}
Expand Down
1 change: 0 additions & 1 deletion tests/Fixture/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use Zenstruck\Foundry\ORM\AbstractORMPersistenceStrategy;
use Zenstruck\Foundry\ORM\ResetDatabase\ResetDatabaseMode;
use Zenstruck\Foundry\Tests\Fixture\Factories\ArrayFactory;
use Zenstruck\Foundry\Tests\Fixture\Factories\Object1Factory;
Expand Down

0 comments on commit 68b807b

Please sign in to comment.