Skip to content

Instantly share code, notes, and snippets.

@tarlepp
Created June 25, 2019 16:01
Show Gist options
  • Save tarlepp/c98f3ce78784d908f944072be84b0cf4 to your computer and use it in GitHub Desktop.
Save tarlepp/c98f3ce78784d908f944072be84b0cf4 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types = 1);
namespace App\Tests\Integration;
use Doctrine\ORM\Tools\SchemaValidator;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use function array_walk;
use function implode;
class SchemaTest extends KernelTestCase
{
private $validator;
public function testThatMappingsAreValid(): void
{
$errors = $this->validator->validateMapping();
$messages = [];
$formatter = static function ($errors, $className) use (&$messages) {
$messages[] = $className . ': ' . implode(', ', $errors);
};
array_walk($errors, $formatter);
static::assertEmpty($errors, implode("\n", $messages));
unset($errors, $messages);
}
public function testThatSchemaInSyncWithMetadata(): void
{
static::assertTrue(
$this->validator->schemaInSyncWithMetadata(),
'The database schema is not in sync with the current mapping file.'
);
}
protected function setUp(): void
{
parent::setUp();
static::bootKernel();
$em = static::$kernel->getContainer()
->get('doctrine')
->getManager();
$this->validator = new SchemaValidator($em);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment