Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ vendor/
.php-cs-fixer.cache
composer.lock
.phpunit.result.cache
tests/Fixtures/var
21 changes: 13 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
"doctrine/persistence": "^2.1|^3.0",
"psr/container": "^1.0",
"psr/log": "^1|^2|^3",
"symfony/config": "^5.4|^6.4|^7.0",
"symfony/config": "^6.4|^7.0",
"symfony/service-contracts": "^2.5|^3.0",
"symfony/dependency-injection": "^5.4|^6.4|^7.0",
"symfony/filesystem": "^5.4|^6.4|^7.0",
"symfony/finder": "^5.4|^6.4|^7.0",
"symfony/http-foundation": "^5.4|^6.4|^7.0",
"symfony/dependency-injection": "^6.4|^7.0",
"symfony/filesystem": "^6.4|^7.0",
"symfony/finder": "^6.4|^7.0",
"symfony/http-foundation": "^6.4|^7.0",
"symfony/http-kernel": "^6.4|^7.0",
"symfony/lock": "^5.4|^6.4|^7.0",
"symfony/twig-bundle": "^5.4|^6.4|^7.0",
"symfony/lock": "^6.4|^7.0",
"symfony/twig-bundle": "^6.4|^7.0",
"twig/twig": "^2.0|^3.0"
},

Expand All @@ -38,7 +38,12 @@
},

"require-dev": {
"phpunit/phpunit": "^10.5.59"
"doctrine/doctrine-bundle": "^2.12",
"phpunit/phpunit": "^10.5.59",
"symfony/error-handler": "^6.4|^7.0",
"symfony/framework-bundle": "^6.4|^7.0",
"symfony/twig-bundle": "^6.4|^7.0",
"symfony/yaml": "^6.4|^7.0"
},

"autoload": {
Expand Down
5 changes: 4 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
bootstrap="tests/bootstrap.php"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnPhpunitDeprecations="true"
>
<php>
<env name="KERNEL_CLASS" value="\Webfactory\Bundle\WfdMetaBundle\Tests\Fixtures\TestKernel" />
</php>
<source ignoreSuppressionOfDeprecations="true">
<include>
<directory>src</directory>
Expand Down
7 changes: 0 additions & 7 deletions src/Resources/config/cache_busting.yml

This file was deleted.

7 changes: 4 additions & 3 deletions src/Resources/config/orm.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use function Symfony\Component\DependencyInjection\Loader\Configurator\expr;
use function Symfony\Component\DependencyInjection\Loader\Configurator\inline_service;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

return static function (ContainerConfigurator $container) {
Expand All @@ -15,7 +16,7 @@
->autoconfigure();

$services->set(\Webfactory\Bundle\WfdMetaBundle\DoctrineMetadataHelper::class)
->args([expr('
service("doctrine.orm.entity_manager").getMetadataFactory()
')]);
->args([
inline_service()->factory([service('doctrine.orm.default_entity_manager'), 'getMetadataFactory']),
]);
};
45 changes: 45 additions & 0 deletions tests/Fixtures/CreateSchemaHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Webfactory\Bundle\WfdMetaBundle\Tests\Fixtures;

use Doctrine\DBAL\Connection;

class CreateSchemaHelper
{
public static function createSchema(Connection $connection): void
{
$connection->executeStatement(<<<SQL
CREATE TABLE `wfd_meta` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`wfd_table_id` INTEGER NOT NULL DEFAULT 0,
`data_id` INTEGER NOT NULL DEFAULT 0,
`wfd_recordtype_id` INTEGER DEFAULT NULL,
`created_wfd_user_id` INTEGER DEFAULT NULL,
`created_timestamp` TEXT DEFAULT NULL,
`lastmod_wfd_user_id` INTEGER DEFAULT NULL,
`lastmod_timestamp` TEXT DEFAULT NULL,
`deleted_wfd_user_id` INTEGER DEFAULT NULL,
`deleted_timestamp` TEXT DEFAULT NULL,
`last_touched` TEXT DEFAULT NULL,
`doc_descr` TEXT DEFAULT NULL,
UNIQUE (`wfd_table_id`, `data_id`)
);
SQL);

$connection->executeStatement(<<<SQL
CREATE INDEX `idx_last_touched` ON `wfd_meta` (`last_touched`);
SQL);
$connection->executeStatement(<<<SQL
CREATE INDEX `idx_touched_table` ON `wfd_meta` (`wfd_table_id`, `last_touched`);
SQL);
$connection->executeStatement(<<<SQL
CREATE TABLE `wfd_table` (
`id` smallint unsigned NOT NULL,
`name` varchar(100) NOT NULL DEFAULT '',
`tablename` varchar(100) NOT NULL DEFAULT '',
`_comment` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`)
)
SQL);
}
}
14 changes: 14 additions & 0 deletions tests/Fixtures/Entity/TestEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Webfactory\Bundle\WfdMetaBundle\Tests\Fixtures\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'test_table')]
class TestEntity
{
#[ORM\Id]
#[ORM\Column]
private int $id;
}
29 changes: 29 additions & 0 deletions tests/Fixtures/TestKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Webfactory\Bundle\WfdMetaBundle\Tests\Fixtures;

use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;

class TestKernel extends Kernel
{
public function registerBundles(): iterable
{
return [
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new \Symfony\Bundle\TwigBundle\TwigBundle(),
new \Webfactory\Bundle\WfdMetaBundle\WebfactoryWfdMetaBundle(),
];
}

public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(__DIR__.'/config/config.yml');
}

public function getProjectDir(): string
{
return __DIR__;
}
}
16 changes: 16 additions & 0 deletions tests/Fixtures/bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env php
<?php

use Symfony\Component\ErrorHandler\Debug;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;

set_time_limit(0);

require dirname(__DIR__).'/../../vendor/autoload.php';

Debug::enable();

$kernel = new \Webfactory\Bundle\WfdMetaBundle\Tests\Fixtures\TestKernel('test', true);
$application = new Application($kernel);
$application->run(new ArgvInput());
22 changes: 22 additions & 0 deletions tests/Fixtures/config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
framework:
secret: dont-tell-mum
test: true
annotations: false
http_method_override: false
handle_all_throwables: true
php_errors:
log: true

doctrine:
dbal:
driver: pdo_sqlite
memory: true
orm:
controller_resolver:
auto_mapping: false
mappings:
Webfactory\Bundle\WfdMetaBundle\Tests\Fixtures\Entity:
type: attribute
dir: '%kernel.project_dir%/Entity'
is_bundle: false
prefix: Webfactory\Bundle\WfdMetaBundle\Tests\Fixtures\Entity
25 changes: 25 additions & 0 deletions tests/Functional/FunctionalTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Webfactory\Bundle\WfdMetaBundle\Tests\Functional;

use Doctrine\DBAL\Connection;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Webfactory\Bundle\WfdMetaBundle\Tests\Fixtures\CreateSchemaHelper;

class FunctionalTestCase extends KernelTestCase
{
protected readonly ContainerInterface $container;
protected readonly Connection $dbal;

protected function setUp(): void
{
parent::setUp();

$this->container = self::getContainer();
$this->dbal = $this->container->get('doctrine.dbal.default_connection');
CreateSchemaHelper::createSchema($this->dbal);
}
}
37 changes: 37 additions & 0 deletions tests/Functional/MetaQueryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Webfactory\Bundle\WfdMetaBundle\Tests\Functional;

use DateTimeImmutable;
use Doctrine\DBAL\Types\Types;
use PHPUnit\Framework\Attributes\Test;
use Webfactory\Bundle\WfdMetaBundle\MetaQueryFactory;
use Webfactory\Bundle\WfdMetaBundle\Tests\Fixtures\Entity\TestEntity;

class MetaQueryTest extends FunctionalTestCase
{
private readonly MetaQueryFactory $metaQueryFactory;

protected function setUp(): void
{
parent::setUp();

$this->metaQueryFactory = $this->container->get(MetaQueryFactory::class);
}

#[Test]
public function getLastTouched_for_entity_class(): void
{
$time = new DateTimeImmutable();

$this->dbal->insert('wfd_table', ['id' => 42, 'tablename' => 'test_table']);
$this->dbal->insert('wfd_meta', ['data_id' => 1, 'wfd_table_id' => 42, 'last_touched' => $time], ['last_touched' => Types::DATETIME_IMMUTABLE]);

$metaQuery = $this->metaQueryFactory->create();
$metaQuery->addEntityClass(TestEntity::class);

self::assertEquals($time->getTimestamp(), $metaQuery->getLastTouched());
}
}
Loading