Skip to content

Commit 445a7c2

Browse files
authored
Add basic infrastructure for functional tests (#61)
1 parent bd78fd9 commit 445a7c2

File tree

15 files changed

+263
-108
lines changed

15 files changed

+263
-108
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ vendor/
22
.php-cs-fixer.cache
33
composer.lock
44
.phpunit.result.cache
5+
tests/Fixtures/var

composer.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
"doctrine/persistence": "^2.1|^3.0",
2222
"psr/container": "^1.0",
2323
"psr/log": "^1|^2|^3",
24-
"symfony/config": "^5.4|^6.4|^7.0",
24+
"symfony/config": "^6.4|^7.0",
2525
"symfony/service-contracts": "^2.5|^3.0",
26-
"symfony/dependency-injection": "^5.4|^6.4|^7.0",
27-
"symfony/filesystem": "^5.4|^6.4|^7.0",
28-
"symfony/finder": "^5.4|^6.4|^7.0",
29-
"symfony/http-foundation": "^5.4|^6.4|^7.0",
26+
"symfony/dependency-injection": "^6.4|^7.0",
27+
"symfony/filesystem": "^6.4|^7.0",
28+
"symfony/finder": "^6.4|^7.0",
29+
"symfony/http-foundation": "^6.4|^7.0",
3030
"symfony/http-kernel": "^6.4|^7.0",
31-
"symfony/lock": "^5.4|^6.4|^7.0",
32-
"symfony/twig-bundle": "^5.4|^6.4|^7.0",
31+
"symfony/lock": "^6.4|^7.0",
32+
"symfony/twig-bundle": "^6.4|^7.0",
3333
"twig/twig": "^2.0|^3.0"
3434
},
3535

@@ -38,7 +38,12 @@
3838
},
3939

4040
"require-dev": {
41-
"phpunit/phpunit": "^10.5.59"
41+
"doctrine/doctrine-bundle": "^2.12",
42+
"phpunit/phpunit": "^10.5.59",
43+
"symfony/error-handler": "^6.4|^7.0",
44+
"symfony/framework-bundle": "^6.4|^7.0",
45+
"symfony/twig-bundle": "^6.4|^7.0",
46+
"symfony/yaml": "^6.4|^7.0"
4247
},
4348

4449
"autoload": {

phpunit.xml.dist

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
<phpunit
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
5-
bootstrap="vendor/autoload.php"
5+
bootstrap="tests/bootstrap.php"
66
displayDetailsOnTestsThatTriggerDeprecations="true"
77
displayDetailsOnPhpunitDeprecations="true"
88
>
9+
<php>
10+
<env name="KERNEL_CLASS" value="\Webfactory\Bundle\WfdMetaBundle\Tests\Fixtures\TestKernel" />
11+
</php>
912
<source ignoreSuppressionOfDeprecations="true">
1013
<include>
1114
<directory>src</directory>

src/Resources/config/cache_busting.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Resources/config/orm.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
44

55
use function Symfony\Component\DependencyInjection\Loader\Configurator\expr;
6+
use function Symfony\Component\DependencyInjection\Loader\Configurator\inline_service;
67
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
78

89
return static function (ContainerConfigurator $container) {
@@ -15,7 +16,7 @@
1516
->autoconfigure();
1617

1718
$services->set(\Webfactory\Bundle\WfdMetaBundle\DoctrineMetadataHelper::class)
18-
->args([expr('
19-
service("doctrine.orm.entity_manager").getMetadataFactory()
20-
')]);
19+
->args([
20+
inline_service()->factory([service('doctrine.orm.default_entity_manager'), 'getMetadataFactory']),
21+
]);
2122
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Webfactory\Bundle\WfdMetaBundle\Tests\Fixtures;
4+
5+
use Doctrine\DBAL\Connection;
6+
7+
class CreateSchemaHelper
8+
{
9+
public static function createSchema(Connection $connection): void
10+
{
11+
$connection->executeStatement(<<<SQL
12+
CREATE TABLE `wfd_meta` (
13+
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
14+
`wfd_table_id` INTEGER NOT NULL DEFAULT 0,
15+
`data_id` INTEGER NOT NULL DEFAULT 0,
16+
`wfd_recordtype_id` INTEGER DEFAULT NULL,
17+
`created_wfd_user_id` INTEGER DEFAULT NULL,
18+
`created_timestamp` TEXT DEFAULT NULL,
19+
`lastmod_wfd_user_id` INTEGER DEFAULT NULL,
20+
`lastmod_timestamp` TEXT DEFAULT NULL,
21+
`deleted_wfd_user_id` INTEGER DEFAULT NULL,
22+
`deleted_timestamp` TEXT DEFAULT NULL,
23+
`last_touched` TEXT DEFAULT NULL,
24+
`doc_descr` TEXT DEFAULT NULL,
25+
UNIQUE (`wfd_table_id`, `data_id`)
26+
);
27+
SQL);
28+
29+
$connection->executeStatement(<<<SQL
30+
CREATE INDEX `idx_last_touched` ON `wfd_meta` (`last_touched`);
31+
SQL);
32+
$connection->executeStatement(<<<SQL
33+
CREATE INDEX `idx_touched_table` ON `wfd_meta` (`wfd_table_id`, `last_touched`);
34+
SQL);
35+
$connection->executeStatement(<<<SQL
36+
CREATE TABLE `wfd_table` (
37+
`id` smallint unsigned NOT NULL,
38+
`name` varchar(100) NOT NULL DEFAULT '',
39+
`tablename` varchar(100) NOT NULL DEFAULT '',
40+
`_comment` varchar(100) DEFAULT NULL,
41+
PRIMARY KEY (`id`)
42+
)
43+
SQL);
44+
}
45+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Webfactory\Bundle\WfdMetaBundle\Tests\Fixtures\Entity;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
7+
#[ORM\Entity]
8+
#[ORM\Table(name: 'test_table')]
9+
class TestEntity
10+
{
11+
#[ORM\Id]
12+
#[ORM\Column]
13+
private int $id;
14+
}

tests/Fixtures/TestKernel.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Webfactory\Bundle\WfdMetaBundle\Tests\Fixtures;
4+
5+
use Symfony\Component\Config\Loader\LoaderInterface;
6+
use Symfony\Component\HttpKernel\Kernel;
7+
8+
class TestKernel extends Kernel
9+
{
10+
public function registerBundles(): iterable
11+
{
12+
return [
13+
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
14+
new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
15+
new \Symfony\Bundle\TwigBundle\TwigBundle(),
16+
new \Webfactory\Bundle\WfdMetaBundle\WebfactoryWfdMetaBundle(),
17+
];
18+
}
19+
20+
public function registerContainerConfiguration(LoaderInterface $loader): void
21+
{
22+
$loader->load(__DIR__.'/config/config.yml');
23+
}
24+
25+
public function getProjectDir(): string
26+
{
27+
return __DIR__;
28+
}
29+
}

tests/Fixtures/bin/console

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use Symfony\Component\ErrorHandler\Debug;
5+
use Symfony\Bundle\FrameworkBundle\Console\Application;
6+
use Symfony\Component\Console\Input\ArgvInput;
7+
8+
set_time_limit(0);
9+
10+
require dirname(__DIR__).'/../../vendor/autoload.php';
11+
12+
Debug::enable();
13+
14+
$kernel = new \Webfactory\Bundle\WfdMetaBundle\Tests\Fixtures\TestKernel('test', true);
15+
$application = new Application($kernel);
16+
$application->run(new ArgvInput());

tests/Fixtures/config/config.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
framework:
2+
secret: dont-tell-mum
3+
test: true
4+
annotations: false
5+
http_method_override: false
6+
handle_all_throwables: true
7+
php_errors:
8+
log: true
9+
10+
doctrine:
11+
dbal:
12+
driver: pdo_sqlite
13+
memory: true
14+
orm:
15+
controller_resolver:
16+
auto_mapping: false
17+
mappings:
18+
Webfactory\Bundle\WfdMetaBundle\Tests\Fixtures\Entity:
19+
type: attribute
20+
dir: '%kernel.project_dir%/Entity'
21+
is_bundle: false
22+
prefix: Webfactory\Bundle\WfdMetaBundle\Tests\Fixtures\Entity

0 commit comments

Comments
 (0)