Ejemplo n.º 1
0
 public function fire(\Doctrine\ORM\EntityManagerInterface $d2em)
 {
     $validator = new SchemaValidator($d2em);
     $exit = 0;
     if ($this->option('skip-mapping')) {
         $this->comment('[Mapping]  Skipped mapping check.');
     } elseif ($errors = $validator->validateMapping()) {
         foreach ($errors as $className => $errorMessages) {
             $this->error("[Mapping]  FAIL - The entity-class '" . $className . "' mapping is invalid:");
             foreach ($errorMessages as $errorMessage) {
                 $this->line('* ' . $errorMessage);
             }
             $this->line();
         }
         $exit += 1;
     } else {
         $this->info("[Mapping]  OK - The mapping files are correct.");
     }
     if ($this->option('skip-sync')) {
         $this->comment("[Database] SKIPPED - The database was not checked for synchronicity.");
     } elseif (!$validator->schemaInSyncWithMetadata()) {
         $this->error("[Database] FAIL - The database schema is not in sync with the current mapping file.");
         $exit += 2;
     } else {
         $this->info("[Database] OK - The database schema is in sync with the mapping files.");
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getHelper('em')->getEntityManager();
     $validator = new SchemaValidator($em);
     $exit = 0;
     if ($input->getOption('skip-mapping')) {
         $output->writeln('<comment>[Mapping]  Skipped mapping check.</comment>');
     } elseif ($errors = $validator->validateMapping()) {
         foreach ($errors as $className => $errorMessages) {
             $output->writeln("<error>[Mapping]  FAIL - The entity-class '" . $className . "' mapping is invalid:</error>");
             foreach ($errorMessages as $errorMessage) {
                 $output->writeln('* ' . $errorMessage);
             }
             $output->writeln('');
         }
         $exit += 1;
     } else {
         $output->writeln('<info>[Mapping]  OK - The mapping files are correct.</info>');
     }
     if ($input->getOption('skip-sync')) {
         $output->writeln('<comment>[Database] SKIPPED - The database was not checked for synchronicity.</comment>');
     } elseif (!$validator->schemaInSyncWithMetadata()) {
         $output->writeln('<error>[Database] FAIL - The database schema is not in sync with the current mapping file.</error>');
         $exit += 2;
     } else {
         $output->writeln('<info>[Database] OK - The database schema is in sync with the mapping files.</info>');
     }
     return $exit;
 }
 /**
  * Execute the console command.
  *
  * @param ManagerRegistry $registry
  */
 public function fire(ManagerRegistry $registry)
 {
     $names = $this->option('em') ? [$this->option('em')] : $registry->getManagerNames();
     foreach ($names as $name) {
         $em = $registry->getManager($name);
         $validator = new SchemaValidator($em);
         $this->comment('');
         $this->message('Validating for <info>' . $name . '</info> entity manager...');
         if ($this->option('skip-mapping')) {
             $this->comment('Mapping]  Skipped mapping check.');
         } elseif ($errors = $validator->validateMapping()) {
             foreach ($errors as $className => $errorMessages) {
                 $this->error("[Mapping]  FAIL - The entity-class '" . $className . "' mapping is invalid:");
                 $this->comment('');
                 foreach ($errorMessages as $errorMessage) {
                     $this->message('* ' . $errorMessage, 'red');
                 }
             }
         } else {
             $this->info('[Mapping]  OK - The mapping files are correct.');
         }
         if ($this->option('skip-sync')) {
             $this->comment('Database] SKIPPED - The database was not checked for synchronicity.');
         } elseif (!$validator->schemaInSyncWithMetadata()) {
             $this->error('[Database] FAIL - The database schema is not in sync with the current mapping file.');
         } else {
             $this->info('[Database] OK - The database schema is in sync with the mapping files.');
         }
     }
 }
Ejemplo n.º 4
0
 public function testSchemaIsValid()
 {
     $this->createClient();
     $validator = new SchemaValidator(self::$kernel->getContainer()->get('doctrine.orm.entity_manager'));
     $errors = $validator->validateMapping();
     $this->assertEmpty($errors, "Validation errors found: \n\n" . var_export($errors, true));
 }
Ejemplo n.º 5
0
 /**
  * Validates the metadata mapping for Doctrine, using the SchemaValidator
  * of Doctrine.
  *
  * @return array
  */
 public function validateMapping()
 {
     try {
         $validator = new SchemaValidator($this->entityManager);
         return $validator->validateMapping();
     } catch (\Exception $exception) {
         return array(array($exception->getMessage()));
     }
 }
Ejemplo n.º 6
0
 public function testMapping()
 {
     /** @var ManagerRegistry $registry */
     $registry = $this->getContainer()->get('doctrine');
     /** @var EntityManager $em */
     foreach ($registry->getManagers() as $em) {
         $validator = new SchemaValidator($em);
         $validateMapping = $validator->validateMapping();
         $this->assertEmpty($validateMapping, implode("\n", $validateMapping));
     }
 }
Ejemplo n.º 7
0
 /**
  * @throws InvalidMappingException
  */
 public function assertSchemaIsValid()
 {
     if ($this->needValidate()) {
         foreach ($this->doctrine->getManagers() as $managerName => $manager) {
             $validator = new SchemaValidator($manager);
             foreach ($validator->validateMapping() as $entity => $errors) {
                 $this->assertAuthorizedMappingErrors($managerName, $entity, $errors);
             }
         }
         $this->saveLastValidateTimestamp();
     }
 }
 /**
  * @see ExtensionInterface
  */
 public function register($provider, $configuration)
 {
     if ($provider->isInitialized('entity.manager')) {
         // Skip the validation if the app didn't connect to the database
         return;
     }
     $validator = new SchemaValidator($provider->lookup('entity.manager'));
     $errors = $validator->validateMapping();
     if (!empty($errors)) {
         throw new ConfigurationException(sprintf('The database schema is not valid: %s', print_r($errors, true)));
     }
 }
Ejemplo n.º 9
0
 /**
  * Doctrine schema validation
  */
 public function testValidateSchema()
 {
     $validator = new SchemaValidator($this->em);
     $errors = $validator->validateMapping();
     if (count($errors) > 0) {
         $message = PHP_EOL;
         foreach ($errors as $class => $classErrors) {
             $message .= "- " . $class . ":" . PHP_EOL . implode(PHP_EOL, $classErrors) . PHP_EOL . PHP_EOL;
         }
         $this->fail($message);
     }
 }
Ejemplo n.º 10
0
 public static function init()
 {
     $zf2ModulePaths = [dirname(dirname(__DIR__))];
     if ($path = static::findParentPath('vendor')) {
         $zf2ModulePaths[] = $path;
     }
     if ($path = static::findParentPath('module')) {
         $zf2ModulePaths[] = $path;
     }
     if (($path = static::findParentPath('src')) !== $zf2ModulePaths[0]) {
         $zf2ModulePaths[] = $path;
     }
     static::initAutoloader();
     $config = (include __DIR__ . '/../config/application.config.php');
     $serviceManager = new ServiceManager(new ServiceManagerConfig());
     $serviceManager->setService('ApplicationConfig', $config);
     $serviceManager->get('ModuleManager')->loadModules();
     static::$serviceManager = $serviceManager;
     if (defined("TEST_SUITE") && constant("TEST_SUITE") == 'full') {
         $entityManager = $serviceManager->get('doctrine.entitymanager.orm_default');
         //Validate the schema;
         $validator = new SchemaValidator($entityManager);
         $errors = $validator->validateMapping();
         if (count($errors) > 0) {
             foreach ($errors as $entity => $errors) {
                 echo "Error in Entity: '" . $entity . "':\n";
                 echo implode("\n", $errors);
                 echo "\n";
             }
             die;
         }
         //Create the schema
         $tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager);
         $mdFactory = $entityManager->getMetadataFactory();
         $mdFactory->getAllMetadata();
         $tool->dropDatabase();
         $tool->createSchema($mdFactory->getAllMetadata());
         $loader = new Loader();
         $loader->addFixture(new \AdminTest\Fixture\LoadAccessData());
         $loader->addFixture(new LoadCountryData());
         $loader->addFixture(new LoadDomainData());
         $loader->addFixture(new LoadProgramData());
         $loader->addFixture(new LoadContactData());
         $loader->addFixture(new LoadContentTypeData());
         $purger = new ORMPurger();
         $executor = new ORMExecutor($entityManager, $purger);
         $executor->execute($loader->getFixtures());
     }
 }
 /**
  * @throws \Doctrine\ORM\Tools\ToolsException
  */
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     static::$kernel = static::createKernel(array());
     static::$kernel->boot();
     $metadata = static::getMetadata();
     $tool = new SchemaTool(static::$em);
     $tool->dropDatabase();
     $tool->createSchema($metadata);
     $validator = new SchemaValidator(static::$em);
     $errors = $validator->validateMapping();
     static::assertCount(0, $errors, implode("\n\n", array_map(function ($l) {
         return implode("\n\n", $l);
     }, $errors)));
 }
Ejemplo n.º 12
0
 /**
  *  Создает схему БД
  *
  * @throws \Doctrine\ORM\Tools\ToolsException
  * @throws \RuntimeException
  */
 public function createSchema()
 {
     $em = $this->getEntityManager();
     //        $em->getConnection()->executeQuery('DROP DATABASE `workflow-doctrine`');
     //        $em->getConnection()->executeQuery('CREATE DATABASE `workflow-doctrine`');
     //        $em->getConnection()->close();
     //        $em->getConnection()->connect();
     $validator = new SchemaValidator($em);
     $errors = $validator->validateMapping();
     $errMsg = [];
     foreach ($errors as $className => $errorMessages) {
         foreach ($errorMessages as $errorMessage) {
             $errMsg[] = $errorMessage;
         }
     }
     if (count($errMsg) > 0) {
         throw new \RuntimeException(implode("\n", $errMsg));
     }
     $tool = new SchemaTool($em);
     $metadata = $em->getMetadataFactory()->getAllMetadata();
     $tool->dropDatabase();
     $tool->createSchema($metadata);
 }
 public function testRoutingModelSet()
 {
     $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths(array(__DIR__ . "/../../Models/Routing"));
     $this->validator->validateMapping();
 }
Ejemplo n.º 14
0
 public function validateTables()
 {
     //Make sure Doctrine is happy with all that
     $validator = new SchemaValidator($this->db->getDoctrine());
     $errors = $validator->validateMapping();
     if (count($errors) > 0) {
         foreach ($errors as $error) {
             if (is_array($error)) {
                 echo implode("<br />", $error);
             } else {
                 echo $error;
             }
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * Método que valida se os mapeamentos estão coerentes
  * com a relação Classes x Tabelas por todo o esquema
  * @return boolean
  */
 public function validarEsquema()
 {
     $sv = new SchemaValidator($this->em);
     return $sv->validateMapping();
 }
Ejemplo n.º 16
0
    /**
     * @test
     */
    public function shouldAllSchemasBeValid()
    {
        $schemaValidator = new SchemaValidator($this->em);

        $this->assertEmpty($schemaValidator->validateMapping());
    }