Skip to content

Commit 1bc793c

Browse files
committed
Finish fixing tests
1 parent bfe764b commit 1bc793c

File tree

9 files changed

+52
-50
lines changed

9 files changed

+52
-50
lines changed

.github/workflows/php.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,23 @@ jobs:
1111
php-version:
1212
- '7.3'
1313
- '7.4'
14-
- '8.0'
1514
- '8.1'
15+
- '8.2'
16+
- '8.3'
17+
- '8.4'
1618

1719
symfony-version:
18-
- '5.3'
1920
- '5.4'
20-
- '6.0'
21+
- '6.4'
22+
- '7.3'
2123

2224
exclude:
23-
- php-version: 7.3
24-
symfony-version: 6.0
25-
- php-version: 7.4
26-
symfony-version: 6.0
25+
- { php-version: 7.3, symfony-version: 6.0 }
26+
- { php-version: 7.4, symfony-version: 6.0 }
27+
28+
- { php-version: 7.3, symfony-version: 7.3 }
29+
- { php-version: 7.4, symfony-version: 7.3 }
30+
- { php-version: 8.1, symfony-version: 7.3 }
2731

2832
name: PHP ${{ matrix.php-version }} and Symfony ${{ matrix.symfony-version }}
2933
steps:

Resources/config/doctrine/Category.orm.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<mapped-superclass
77
name="Orbitale\Bundle\CmsBundle\Entity\Category"
88
repository-class="Orbitale\Bundle\CmsBundle\Repository\CategoryRepository"
9-
table="orbitale_cms_categories"
109
>
1110
<lifecycle-callbacks>
1211
<lifecycle-callback type="prePersist" method="updateSlug" />

Resources/config/doctrine/Page.orm.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<mapped-superclass
77
name="Orbitale\Bundle\CmsBundle\Entity\Page"
88
repository-class="Orbitale\Bundle\CmsBundle\Repository\PageRepository"
9-
table="orbitale_cms_pages"
109
>
1110
<lifecycle-callbacks>
1211
<lifecycle-callback type="prePersist" method="updateSlug" />
@@ -18,13 +17,15 @@
1817
<lifecycle-callback type="preUpdate" method="updateSlug" />
1918
<lifecycle-callback type="preRemove" method="onRemove" />
2019
</lifecycle-callbacks>
20+
<field name="title" type="string" length="255" nullable="false" />
21+
<field name="slug" type="string" length="255" unique="true" nullable="false" />
2122
<field name="content" type="text" nullable="true" />
22-
<field name="metaDescription" column="meta_description" type="string" length="255" />
23-
<field name="metaTitle" column="meta_title" type="string" length="255" />
24-
<field name="metaKeywords" column="meta_keywords" type="string" length="255" />
23+
<field name="metaDescription" column="meta_description" type="string" length="255" nullable="true" />
24+
<field name="metaTitle" column="meta_title" type="string" length="255" nullable="true" />
25+
<field name="metaKeywords" column="meta_keywords" type="string" length="255" nullable="true" />
2526
<field name="css" type="text" nullable="true" />
2627
<field name="js" type="text" nullable="true" />
27-
<field name="createdAt" column="created_at" type="datetime_immutable" />
28+
<field name="createdAt" column="created_at" type="datetime_immutable" nullable="false" />
2829
<field name="enabled" type="boolean">
2930
<options>
3031
<option name="default">0</option>

Resources/config/services.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ services:
4545
- '%orbitale_cms.page_class%'
4646
- '%orbitale_cms.category_class%'
4747
tags:
48-
- doctrine.event_subscriber
48+
- name: doctrine.event_listener
49+
event: loadClassMetadata
50+
priority: 100
4951

5052
Orbitale\Bundle\CmsBundle\Repository\PageRepository:
5153
factory: ['@doctrine.orm.entity_manager', 'getRepository']

Tests/AbstractTestCase.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,41 @@
1111

1212
namespace Orbitale\Bundle\CmsBundle\Tests;
1313

14-
use Doctrine\DBAL\Connection;
1514
use Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Page;
1615
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
16+
use Symfony\Component\Console\Output\BufferedOutput;
17+
use Symfony\Component\Console\Output\ConsoleOutput;
18+
use Symfony\Component\Console\Output\NullOutput;
19+
use Symfony\Component\Filesystem\Filesystem;
20+
use Symfony\Bundle\FrameworkBundle\Console\Application;
21+
use Symfony\Component\Console\Input\ArrayInput;
1722

1823
class AbstractTestCase extends WebTestCase
1924
{
2025
public function setUp(): void
2126
{
2227
static::bootKernel();
2328

24-
/** @var Connection $c */
25-
$c = self::getContainer()->get(Connection::class);
26-
$method = method_exists($c, 'executeQuery') ? 'executeQuery' : 'query';
27-
$c->$method('delete from orbitale_cms_pages where 1');
28-
$c->$method('delete from orbitale_cms_categories where 1');
29+
$databaseFile = self::$kernel->getContainer()->getParameter('database_path');
30+
31+
$fs = new Filesystem();
32+
33+
if ($fs->exists($databaseFile)) {
34+
$fs->remove($databaseFile);
35+
}
36+
37+
$application = new Application(self::$kernel);
38+
$application->setAutoExit(false);
39+
$out = new BufferedOutput();
40+
$returns = [];
41+
$returns[] = $application->run(new ArrayInput(['command' => 'doctrine:database:create']), $out);
42+
$returns[] = $application->run(new ArrayInput(['command' => 'doctrine:schema:update', '--dump-sql' => true, '--complete' => true]), $out);
43+
$returns[] = $application->run(new ArrayInput(['command' => 'doctrine:schema:create']), $out);
44+
45+
if (\in_array(1, $returns, true)) {
46+
self::fail(\sprintf("A database setup command has failed:\n%s", $out->fetch()));
47+
}
48+
2949
static::ensureKernelShutdown();
3050
}
3151

Tests/Fixtures/App/AppKernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ public function getLogDir(): string
6161

6262
public function getBuildDir(): string
6363
{
64-
return \dirname(__DIR__, 3).'/build/'.$this->getEnvironment();
64+
return \dirname(__DIR__, 3).'/build/';
6565
}
6666
}

Tests/Fixtures/TestBundle/Resources/config/doctrine/Category.orm.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
44
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
55

6-
<entity name="Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Category">
7-
<id name="id" type="string" length="255">
6+
<entity name="Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Category" table="orbitale_cms_categories">
7+
<id name="id" column="id" type="integer" length="255">
88
<generator strategy="AUTO" />
99
</id>
1010
</entity>

Tests/Fixtures/TestBundle/Resources/config/doctrine/Page.orm.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
44
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
55

6-
<entity name="Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Page">
7-
<id name="id" type="string" length="255">
6+
<entity name="Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Page" table="orbitale_cms_pages">
7+
<id name="id" column="id" type="integer" length="255">
88
<generator strategy="AUTO" />
99
</id>
1010
</entity>

Tests/bootstrap.php

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand;
13-
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\CreateSchemaDoctrineCommand;
1412
use Orbitale\Bundle\CmsBundle\Tests\Fixtures\App\AppKernel;
15-
use Symfony\Bundle\FrameworkBundle\Console\Application;
16-
use Symfony\Component\Console\Input\ArrayInput;
17-
use Symfony\Component\Console\Output\ConsoleOutput;
18-
use Symfony\Component\Console\Output\NullOutput;
1913
use Symfony\Component\Filesystem\Filesystem;
2014

2115
$file = __DIR__.'/../vendor/autoload.php';
@@ -29,10 +23,6 @@
2923
(static function(){
3024
$fs = new Filesystem();
3125

32-
putenv('DATABASE_MAPPING_TYPE=attribute');
33-
$_SERVER['DATABASE_MAPPING_TYPE'] = 'attribute';
34-
$_ENV['DATABASE_MAPPING_TYPE'] = 'attribute';
35-
3626
$kernel = new AppKernel('test', true);
3727

3828
// Remove build dir files
@@ -44,20 +34,6 @@
4434
fwrite(STDERR, $e->getMessage());
4535
}
4636
}
47-
48-
$kernel->boot();
49-
50-
$databaseFile = $kernel->getContainer()->getParameter('database_path');
51-
52-
if ($fs->exists($databaseFile)) {
53-
$fs->remove($databaseFile);
54-
}
55-
56-
$application = new Application($kernel);
57-
$application->setAutoExit(false);
58-
$out = new ConsoleOutput();
59-
$application->run(new ArrayInput(['command' => 'doctrine:database:create']), $out);
60-
$application->run(new ArrayInput(['command' => 'doctrine:schema:update', '--dump-sql' => true, '--force' => true, '--complete' => true]), $out);
61-
6237
$kernel->shutdown();
38+
unset($kernel);
6339
})();

0 commit comments

Comments
 (0)