Skip to content

Commit

Permalink
Merge pull request #47 from szymach/dev
Browse files Browse the repository at this point in the history
Test for doctrine/persistence 3.x
  • Loading branch information
chives authored Oct 30, 2023
2 parents 06a3956 + 81a1dff commit 4a7b219
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 38 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ language: php

dist: focal

addons:
apt:
packages:
- "libonig5"

matrix:
include:
- php: 7.4
Expand Down Expand Up @@ -37,6 +42,7 @@ before_install:
- sudo service elasticsearch restart

before_script:
- echo 'date.timezone = "Europe/Warsaw"' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- phpenv config-rm xdebug.ini
- export PATH="$HOME/bin:$PATH"
- ./install_composer.sh
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"doctrine/dbal": "^3.3",
"doctrine/doctrine-bundle": "^2.8",
"doctrine/orm": "^2.14",
"doctrine/persistence": "^2.3",
"doctrine/persistence": "^2.0|^3.0",
"friendsofsymfony/elastica-bundle": "^6.3",
"fsi/files": "^2.0|>=2.0.2",
"gedmo/doctrine-extensions": "^3.5",
Expand Down
13 changes: 9 additions & 4 deletions tests/Bundle/DataSourceBundle/Fixtures/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ public function registerBundles(): array
];
}

public function getProjectDir(): string
public function getCacheDir(): string
{
return __DIR__;
return "{$this->getProjectDir()}/tests/Bundle/DataSourceBundle/Fixtures/var/cache";
}

public function getLogDir(): string
{
return "{$this->getProjectDir()}/tests/Bundle/DataSourceBundle/Fixtures/var/log";
}

protected function configureRoutes(RouteCollectionBuilder $routes): void
Expand Down Expand Up @@ -83,7 +88,7 @@ protected function configureContainer(ContainerBuilder $configuration, LoaderInt
'driver' => 'pdo_sqlite',
'user' => 'admin',
'charset' => 'UTF8',
'path' => '%kernel.project_dir%/var/data.sqlite',
'path' => '%kernel.project_dir%/tests/Bundle/DataSourceBundle/Fixtures/var/data.sqlite',
'logging' => false
],
'orm' => [
Expand All @@ -93,7 +98,7 @@ protected function configureContainer(ContainerBuilder $configuration, LoaderInt
'datasource_bundle' => [
'mapping' => true,
'type' => 'xml',
'dir' => '%kernel.project_dir%/../../../Component/DataSource/Fixtures/doctrine',
'dir' => '%kernel.project_dir%/tests/Component/DataSource/Fixtures/doctrine',
'prefix' => 'Tests\FSi\Component\DataSource\Fixtures\Entity',
'is_bundle' => false
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function getConnection($name = null): ?\Doctrine\DBAL\Connection

public function getConnections(): array
{
return [$this->connection];
return [$this->getDefaultConnectionName() => $this->connection];
}

public function getConnectionNames(): array
{
return [$this->getDefaultConnectionName()];
return [$this->getDefaultConnectionName() => $this->getDefaultConnectionName()];
}
}
} else {
Expand Down Expand Up @@ -77,12 +77,12 @@ public function getConnection($name = null): ?\Doctrine\DBAL\Driver\Connection

public function getConnections(): array
{
return [$this->connection];
return [$this->getDefaultConnectionName() => $this->connection];
}

public function getConnectionNames(): array
{
return [$this->getDefaultConnectionName()];
return [$this->getDefaultConnectionName() => $this->getDefaultConnectionName()];
}
}
}
48 changes: 22 additions & 26 deletions tests/Component/DataSource/Driver/Doctrine/ORM/ORMDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@

use DateTimeImmutable;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
use Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\Tools\Setup;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\Mapping\Driver\SymfonyFileLocator;
use FSi\Component\DataSource\DataSourceFactory;
use FSi\Component\DataSource\DataSourceInterface;
use FSi\Component\DataSource\Driver\Doctrine\ORM\ORMFactory;
use FSi\Component\DataSource\Driver\Doctrine\ORM\Event\PreGetResult;
use FSi\Component\DataSource\Driver\Doctrine\ORM\FieldType\Boolean;
use FSi\Component\DataSource\Driver\Doctrine\ORM\FieldType\Date;
Expand All @@ -29,6 +27,7 @@
use FSi\Component\DataSource\Driver\Doctrine\ORM\FieldType\Number;
use FSi\Component\DataSource\Driver\Doctrine\ORM\FieldType\Text;
use FSi\Component\DataSource\Driver\Doctrine\ORM\FieldType\Time;
use FSi\Component\DataSource\Driver\Doctrine\ORM\ORMFactory;
use FSi\Component\DataSource\Driver\Doctrine\ORM\ORMResult;
use FSi\Component\DataSource\Driver\DriverFactoryManager;
use FSi\Component\DataSource\Event\PostGetParameters;
Expand All @@ -55,28 +54,6 @@ final class ORMDriverTest extends TestCase
private ?EventDispatcherInterface $eventDispatcher = null;
private ?Storage $orderingStorage = null;

protected function setUp(): void
{
$config = Setup::createConfiguration(true, null, null);
$config->setMetadataDriverImpl(
new XmlDriver(
new SymfonyFileLocator(
[__DIR__ . '/../../../Fixtures/doctrine' => 'Tests\FSi\Component\DataSource\Fixtures\Entity'],
'.orm.xml'
)
)
);
$em = EntityManager::create(['driver' => 'pdo_sqlite', 'memory' => true], $config);
$tool = new SchemaTool($em);
$tool->createSchema([
$em->getClassMetadata(News::class),
$em->getClassMetadata(Category::class),
$em->getClassMetadata(Group::class),
]);
$this->load($em);
$this->em = $em;
}

public function testNumberFieldComparingWithZero(): void
{
$dataSourceFactory = $this->getDataSourceFactory();
Expand Down Expand Up @@ -176,7 +153,7 @@ public function testGeneralDoctrineDriverConfiguration(): void
DataSourceInterface::PARAMETER_FIELDS => [
'author' => 'domain1.com',
'title' => ['title44', 'title58'],
'created' => ['from' => new DateTimeImmutable(date('Y:m:d H:i:s', 35 * 24 * 60 * 60))],
'created' => ['from' => '1970-02-05 01:00:00'],
],
],
];
Expand Down Expand Up @@ -699,6 +676,25 @@ public function testCreateDriverWithoutEntityAndQbOptions(): void
$factory->createDriver([]);
}

protected function setUp(): void
{
$config = Setup::createConfiguration(true, null, null);
$config->setMetadataDriverImpl(
new SimplifiedXmlDriver(
[__DIR__ . '/../../../Fixtures/doctrine' => 'Tests\\FSi\\Component\\DataSource\\Fixtures\\Entity'],
)
);
$em = EntityManager::create(['driver' => 'pdo_sqlite', 'memory' => true], $config);
$tool = new SchemaTool($em);
$tool->createSchema([
$em->getClassMetadata(News::class),
$em->getClassMetadata(Category::class),
$em->getClassMetadata(Group::class),
]);
$this->load($em);
$this->em = $em;
}

protected function tearDown(): void
{
$this->eventDispatcher = null;
Expand Down
3 changes: 0 additions & 3 deletions tests/Component/DataSource/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@

use FSi\Component\DataSource\DataSourceFactory;
use FSi\Component\DataSource\Driver\Collection\CollectionFactory;
use FSi\Component\DataSource\Driver\Collection\FieldType\Text;
use FSi\Component\DataSource\Driver\DriverFactoryManager;
use FSi\Component\DataSource\Exception\DataSourceException;
use PHPUnit\Framework\TestCase;
use Psr\EventDispatcher\EventDispatcherInterface;

use function array_merge;

final class FactoryTest extends TestCase
{
public function testFactoryExceptionOnUnknownDriver(): void
Expand Down

0 comments on commit 4a7b219

Please sign in to comment.