Skip to content

Commit

Permalink
Demonstrate that listener is called
Browse files Browse the repository at this point in the history
For now, that test only works with DBAL 3, but hopefully that's only
because of the test mocking system rather than the code.
  • Loading branch information
greg0ire committed Apr 30, 2024
1 parent 382da88 commit 3e7771e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/Tests/ORM/Tools/SchemaToolTest.php
Expand Up @@ -4,6 +4,8 @@

namespace Doctrine\Tests\ORM\Tools;

use Composer\InstalledVersions;
use Composer\Semver\VersionParser;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\Column;
Expand All @@ -20,6 +22,7 @@
use Doctrine\ORM\Mapping\UniqueConstraint;
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
use Doctrine\ORM\Tools\Event\GenerateSchemaTableEventArgs;
use Doctrine\ORM\Tools\Event\SchemaChangedEventArgs;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\Tools\ToolEvents;
use Doctrine\Persistence\Mapping\Driver\StaticPHPDriver;
Expand Down Expand Up @@ -172,6 +175,30 @@ public function testPostGenerateEvents(): void
self::assertTrue($listener->schemaCalled);
}

public function testSchemaChangedEvent(): void
{
if (InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '^3.0')) {
self::markTestSkipped('This test is not compatible with DBAL 3');
}

$em = $this->getTestEntityManager();

$schemaTool = new SchemaTool($em);

$listener = new class ()
{
public bool $called = false;

public function postSchemaChanged(SchemaChangedEventArgs $eventArgs): void
{
$this->called = true;
}
};
$em->getEventManager()->addEventListener(ToolEvents::postSchemaChanged, $listener);
$schemaTool->updateSchema([]);
self::assertTrue($listener->called);
}

public function testNullDefaultNotAddedToPlatformOptions(): void
{
$em = $this->getTestEntityManager();
Expand Down

0 comments on commit 3e7771e

Please sign in to comment.