Skip to content

Commit

Permalink
test: Skip database depend tests when no database is available
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Jul 14, 2024
1 parent aec4b49 commit 9b3fb40
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 13 deletions.
7 changes: 3 additions & 4 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function configure(): void
{
$this
->setName('install')
->setDescription('Install Roadiz database, roles, settings and a default translation.');
->setDescription('Perform Doctrine migrations, install default Roadiz roles, settings and translation.');
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down Expand Up @@ -139,11 +139,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/**
* Tell if there is any translation.
*
* @return boolean
* @return bool
*/
public function hasDefaultTranslation(): bool
{
$default = $this->managerRegistry->getRepository(Translation::class)->findOneBy([]);
return $default !== null;
return null !== $this->managerRegistry->getRepository(Translation::class)->findDefault();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use RZ\Roadiz\CoreBundle\DependencyInjection\Configuration;
use RZ\Roadiz\CoreBundle\Entity\NodesSources;
use RZ\Roadiz\CoreBundle\Entity\NodeType;
use Symfony\Component\Stopwatch\Stopwatch;

#[AsDoctrineListener(event: Events::postLoad)]
#[AsDoctrineListener(event: Events::loadClassMetadata)]
Expand All @@ -23,7 +24,8 @@ final class NodesSourcesInheritanceSubscriber
public function __construct(
private readonly NodeTypes $nodeTypes,
private readonly string $inheritanceType,
private readonly LoggerInterface $logger
private readonly LoggerInterface $logger,
private readonly Stopwatch $stopwatch
) {
}

Expand All @@ -45,6 +47,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void
$class = $metadata->getReflectionClass();

if ($class->getName() === NodesSources::class) {
$this->stopwatch->start('NodesSources loadClassMetadata');
try {
/** @var NodeType[] $nodeTypes */
$nodeTypes = $this->nodeTypes->all();
Expand Down Expand Up @@ -114,6 +117,8 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void
* Need Install
*/
}

$this->stopwatch->stop('NodesSources loadClassMetadata');
}
}
}
2 changes: 2 additions & 0 deletions src/EntityHandler/NodeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ public function addNodeForField(Node $node, NodeTypeFieldInterface $field, bool
*
* @param string $fieldName Name of the node-type field
* @return Node[]
* @deprecated
*/
public function getNodesFromFieldName(string $fieldName): array
{
Expand All @@ -220,6 +221,7 @@ public function getNodesFromFieldName(string $fieldName): array
*
* @param string $fieldName Name of the node-type field
* @return Node[]
* @deprecated
*/
public function getReverseNodesFromFieldName(string $fieldName): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/EntityHandler/NodesSourcesHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,8 @@ public function getSEO(): array
* Get nodes linked to current node for a given fieldname.
*
* @param string $fieldName Name of the node-type field
*
* @return array<Node> Collection of nodes
* @deprecated
*/
public function getNodesFromFieldName(string $fieldName): array
{
Expand All @@ -515,8 +515,8 @@ public function getNodesFromFieldName(string $fieldName): array
* Get nodes which own a reference to current node for a given fieldname.
*
* @param string $fieldName Name of the node-type field
*
* @return array<Node> Collection of nodes
* @deprecated
*/
public function getReverseNodesFromFieldName(string $fieldName): array
{
Expand Down
12 changes: 8 additions & 4 deletions src/Node/UniqueNodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
use RZ\Roadiz\CoreBundle\Entity\Tag;
use RZ\Roadiz\CoreBundle\Entity\Translation;
use RZ\Roadiz\CoreBundle\Security\Authorization\Voter\NodeVoter;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Bundle\SecurityBundle\Security;

class UniqueNodeGenerator
{
Expand All @@ -32,21 +32,23 @@ public function __construct(
/**
* Generate a node with a unique name.
*
* This method flush entity-manager.
* This method flush entity-manager by default.
*
* @param NodeType $nodeType
* @param TranslationInterface $translation
* @param Node|null $parent
* @param Tag|null $tag
* @param bool $pushToTop
* @param bool $flush
* @return NodesSources
*/
public function generate(
NodeType $nodeType,
TranslationInterface $translation,
Node $parent = null,
Tag $tag = null,
bool $pushToTop = false
bool $pushToTop = false,
bool $flush = true
): NodesSources {
$name = $nodeType->getDisplayName() . " " . uniqid();
$node = new Node();
Expand Down Expand Up @@ -77,7 +79,9 @@ public function generate(
if (null !== $manager) {
$manager->persist($node);
$manager->persist($source);
$manager->flush();
if ($flush) {
$manager->flush();
}
}

return $source;
Expand Down
6 changes: 4 additions & 2 deletions src/Repository/NodesSourcesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ class NodesSourcesRepository extends StatusAwareRepository
* @param EventDispatcherInterface $dispatcher
* @param Security $security
* @param NodeSourceSearchHandlerInterface|null $nodeSourceSearchHandler
* @param class-string<NodesSources> $entityClass
*/
public function __construct(
ManagerRegistry $registry,
PreviewResolverInterface $previewResolver,
EventDispatcherInterface $dispatcher,
Security $security,
?NodeSourceSearchHandlerInterface $nodeSourceSearchHandler
?NodeSourceSearchHandlerInterface $nodeSourceSearchHandler,
string $entityClass = NodesSources::class
) {
parent::__construct($registry, NodesSources::class, $previewResolver, $dispatcher, $security);
parent::__construct($registry, $entityClass, $previewResolver, $dispatcher, $security);
$this->nodeSourceSearchHandler = $nodeSourceSearchHandler;
}

Expand Down
2 changes: 2 additions & 0 deletions tests/NodeType/ApiResourceGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ protected static function getGeneratedPath(): string

protected function getApiResourceGenerator(): ApiResourceGenerator
{
$this->bootKernel();
$this->assertTrue($this->getContainer()->has(ApiResourceOperationNameGenerator::class));
/** @var ApiResourceOperationNameGenerator $apiResourceOperationNameGenerator */
$apiResourceOperationNameGenerator = $this->getContainer()->get(ApiResourceOperationNameGenerator::class);

Expand Down

0 comments on commit 9b3fb40

Please sign in to comment.