Skip to content

Commit f77d4d7

Browse files
committed
Fixing tests and deprecations
1 parent 630449b commit f77d4d7

File tree

7 files changed

+77
-34
lines changed

7 files changed

+77
-34
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"symfony/serializer": "^3.4 || ^4.1"
2121
},
2222
"require-dev": {
23-
"doctrine/doctrine-bundle": "^1.6",
23+
"doctrine/doctrine-bundle": "^1.8",
2424
"symfony/finder": "^3.4 || ^4.1",
2525
"symfony/framework-bundle": "^3.4 || ^4.1",
2626
"symfony/phpunit-bridge": "^4.3"

phpunit.xml.dist

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<ini name="error_reporting" value="-1" />
1010
<server name="KERNEL_DIR" value="tests/Fixtures" />
1111
<server name="KERNEL_CLASS" value="AppKernel" />
12+
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0" />
1213
</php>
1314

1415
<testsuites>

tests/AbstractKernelTestCase.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* (c) Kévin Dunglas <[email protected]>
5+
*
6+
* This source file is subject to the MIT license that is bundled
7+
* with this source code in the file LICENSE.
8+
*/
9+
10+
namespace Dunglas\DoctrineJsonOdm\Tests;
11+
12+
use Symfony\Bundle\FrameworkBundle\Console\Application;
13+
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
14+
15+
abstract class AbstractKernelTestCase extends KernelTestCase
16+
{
17+
/**
18+
* @var Application
19+
*/
20+
protected $application;
21+
22+
protected function setUp()
23+
{
24+
$this->bootKernel();
25+
26+
$this->application = new Application(self::$kernel);
27+
$this->application->setAutoExit(false);
28+
}
29+
}

tests/Fixtures/AppKernel.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
1111
use Dunglas\DoctrineJsonOdm\Bundle\DunglasDoctrineJsonOdmBundle;
12+
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\DependencyInjection\MakeServicesPublicPass;
1213
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\TestBundle;
1314
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
1415
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
@@ -40,15 +41,15 @@ protected function configureRoutes(RouteCollectionBuilder $routes)
4041
{
4142
}
4243

43-
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
44+
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
4445
{
45-
$c->loadFromExtension('framework', [
46+
$container->loadFromExtension('framework', [
4647
'secret' => 'jsonodm',
4748
'test' => null,
4849
]);
4950

5051
$db = getenv('DB');
51-
$c->loadFromExtension('doctrine', [
52+
$container->loadFromExtension('doctrine', [
5253
'dbal' => [
5354
'driver' => 'MYSQL' === $db ? 'pdo_mysql' : 'pdo_pgsql',
5455
'host' => getenv("{$db}_HOST"),
@@ -62,5 +63,8 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
6263
'auto_mapping' => true,
6364
],
6465
]);
66+
67+
// Make a few services public until we depend on Symfony 4.1+ and can use the new test container
68+
$container->addCompilerPass(new MakeServicesPublicPass());
6569
}
6670
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* (c) Kévin Dunglas <[email protected]>
5+
*
6+
* This source file is subject to the MIT license that is bundled
7+
* with this source code in the file LICENSE.
8+
*/
9+
10+
namespace Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\DependencyInjection;
11+
12+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13+
use Symfony\Component\DependencyInjection\ContainerBuilder;
14+
15+
class MakeServicesPublicPass implements CompilerPassInterface
16+
{
17+
public function process(ContainerBuilder $container): void
18+
{
19+
static $services = [
20+
'doctrine.orm.default_entity_manager',
21+
'doctrine.dbal.default_connection',
22+
'doctrine',
23+
];
24+
25+
foreach ($services as $service) {
26+
if (!$container->hasDefinition($service)) {
27+
continue;
28+
}
29+
30+
$definition = $container->getDefinition($service);
31+
$definition->setPublic(true);
32+
}
33+
}
34+
}

tests/FunctionalTest.php

+3-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* with this source code in the file LICENSE.
88
*/
99

10-
namespace Dunglas\DoctrineJsonOdm\tests;
10+
namespace Dunglas\DoctrineJsonOdm\Tests;
1111

1212
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\Entity\Attribute;
1313
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\Entity\Attributes;
@@ -16,26 +16,16 @@
1616
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\Entity\Foo;
1717
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\Entity\Product;
1818
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\Entity\ScalarValue;
19-
use Symfony\Bundle\FrameworkBundle\Console\Application;
20-
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
2119
use Symfony\Component\Console\Input\StringInput;
2220

2321
/**
2422
* @author Kévin Dunglas <[email protected]>
2523
*/
26-
class FunctionalTest extends KernelTestCase
24+
class FunctionalTest extends AbstractKernelTestCase
2725
{
28-
/**
29-
* @var Application
30-
*/
31-
private $application;
32-
3326
protected function setUp()
3427
{
35-
$this->bootKernel();
36-
37-
$this->application = new Application(self::$kernel);
38-
$this->application->setAutoExit(false);
28+
parent::setUp();
3929

4030
$this->runCommand('doctrine:schema:drop --force');
4131
$this->runCommand('doctrine:schema:create');

tests/SerializerTest.php

+2-17
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,20 @@
77
* with this source code in the file LICENSE.
88
*/
99

10-
namespace Dunglas\DoctrineJsonOdm\tests;
10+
namespace Dunglas\DoctrineJsonOdm\Tests;
1111

1212
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\Entity\Attribute;
1313
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\Entity\Attributes;
1414
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\Entity\Bar;
1515
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\Entity\Baz;
1616
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\Entity\Foo;
1717
use Dunglas\DoctrineJsonOdm\Tests\Fixtures\TestBundle\Entity\ScalarValue;
18-
use Symfony\Bundle\FrameworkBundle\Console\Application;
19-
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
2018

2119
/**
2220
* @author Kévin Dunglas <[email protected]>
2321
*/
24-
class SerializerTest extends KernelTestCase
22+
class SerializerTest extends AbstractKernelTestCase
2523
{
26-
/**
27-
* @var Application
28-
*/
29-
private $application;
30-
31-
protected function setUp()
32-
{
33-
$this->bootKernel();
34-
35-
$this->application = new Application(self::$kernel);
36-
$this->application->setAutoExit(false);
37-
}
38-
3924
public function testStoreAndRetrieveDocument()
4025
{
4126
$attribute1 = new Attribute();

0 commit comments

Comments
 (0)