mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-09 16:53:11 +08:00
Updated CreateDatabaseCommand to create the empty database if it does not exist
This commit is contained in:
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Common;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
return [
|
||||
@@ -18,6 +19,7 @@ return [
|
||||
'dependencies' => [
|
||||
'factories' => [
|
||||
EntityManager::class => Doctrine\EntityManagerFactory::class,
|
||||
Connection::class => Doctrine\ConnectionFactory::class,
|
||||
],
|
||||
'aliases' => [
|
||||
'em' => EntityManager::class,
|
||||
|
||||
17
module/Common/src/Doctrine/ConnectionFactory.php
Normal file
17
module/Common/src/Doctrine/ConnectionFactory.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Common\Doctrine;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class ConnectionFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container): Connection
|
||||
{
|
||||
$em = $container->get(EntityManager::class);
|
||||
return $em->getConnection();
|
||||
}
|
||||
}
|
||||
44
module/Common/test/Doctrine/ConnectionFactoryTest.php
Normal file
44
module/Common/test/Doctrine/ConnectionFactoryTest.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Common\Doctrine;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Shlinkio\Shlink\Common\Doctrine\ConnectionFactory;
|
||||
|
||||
class ConnectionFactoryTest extends TestCase
|
||||
{
|
||||
/** @var ConnectionFactory */
|
||||
private $factory;
|
||||
/** @var ObjectProphecy */
|
||||
private $container;
|
||||
/** @var ObjectProphecy */
|
||||
private $em;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->container = $this->prophesize(ContainerInterface::class);
|
||||
$this->em = $this->prophesize(EntityManagerInterface::class);
|
||||
$this->container->get(EntityManager::class)->willReturn($this->em->reveal());
|
||||
|
||||
$this->factory = new ConnectionFactory();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function properServiceFallbackOccursWhenInvoked(): void
|
||||
{
|
||||
$connection = $this->prophesize(Connection::class)->reveal();
|
||||
$getConnection = $this->em->getConnection()->willReturn($connection);
|
||||
|
||||
$result = ($this->factory)($this->container->reveal());
|
||||
|
||||
$this->assertSame($connection, $result);
|
||||
$getConnection->shouldHaveBeenCalledOnce();
|
||||
$this->container->get(EntityManager::class)->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user