public function testPersistentTemplateConfigGenerationOverwriteSuccess() { $dirs = $this->setUpDirs(); $schema = $this->getSchema(); $schemaWriter = new ezcPersistentObjectTemplateSchemaWriter(new ezcPersistentObjectTemplateSchemaWriterOptions(array('overwrite' => true, 'classPrefix' => 'test', 'templatePath' => $dirs['tplDir'], 'templateCompilePath' => $dirs['tmpDir']))); $d = dir($this->dataDir . '/template_config_prefix'); while (($entry = $d->read()) !== false) { if ($entry[0] === '.') { continue; } if (!touch($dirs['configDir'] . '/' . $entry, 12345)) { $this->markTestIncomplete("Could not touch '{$entry}' in config dir '{$dirs['configDir']}.'"); } } $schemaWriter->write($schema, 'definition_template.ezt', $dirs['configDir']); clearstatcache(); $d = dir($dirs['configDir']); while (($entry = $d->read()) !== false) { if ($entry[0] === '.') { continue; } $this->assertGreaterThan(12345, filemtime($dirs['configDir'] . '/' . $entry)); } }
/** * Writes classes or configuration using a template. * * This method uses the given $tpl file to output $schema to $dir. $tpl is * either a template for PersistentObject definition files or * PersistentObject class stubs. * * @param string $dir * @param ezcDbSchema $schema * @param string $tpl */ private function writeFromTemplate($dir, $schema, $tpl) { $writer = new ezcPersistentObjectTemplateSchemaWriter(); if (($tplPath = $this->input->getOption('template-path')->value) !== false) { $writer->options->templatePath = $tplPath; } if (($prefix = $this->input->getOption('prefix')->value) !== false) { $writer->options->classPrefix = $prefix; } if (($overwrite = $this->input->getOption('overwrite')->value) !== false) { $writer->options->overwrite = $overwrite; } $writer->write($schema, $tpl, $dir); }