/** * Stores mappings into filesystem * * @param BackupJob $job * @param JobStats $jobStats * @param OutputInterface $output * @author Daniel Wendlandt */ private function storeMappings(BackupJob $job, JobStats $jobStats, OutputInterface $output) { $memoryAtSection = memory_get_usage(); $timeStartSection = microtime(true); $mappingFilesCreated = $this->filesystem->storeMappings($job->getPath(), $job->getMappings()); $jobStats->setStoreMappings(microtime(true) - $timeStartSection, memory_get_usage(), memory_get_usage() - $memoryAtSection, array('mappingFilesCreated' => $mappingFilesCreated)); $output->writeln('<info>*** Stored ' . $mappingFilesCreated . ' mapping files ***</info>' . PHP_EOL); /** @var Index $index */ foreach ($job->getMappings()->getIndices() as $index) { /** @var Type $type */ foreach ($index->getTypes() as $type) { $output->writeln('<comment> - ' . $index->getName() . DIRECTORY_SEPARATOR . $type->getName() . FilesystemRepository::FILE_EXTENSION . '</comment>'); } } $output->writeln(''); }
public function testStoreMappings() { $path = '/tmp/test-path'; $mappings = new Mappings(); $type1 = new Mappings\Type(); $type1->setName('type1'); $type1->setSchema(array('properties' => array())); $type2 = new Mappings\Type(); $type2->setName('type2'); $type2->setSchema(array('properties' => array())); $index1 = new Mappings\Index(); $index1->setName('index1'); $index1->addType($type1); $index1->addType($type2); $mappings->addIndex($index1); $folderPath = $path . DIRECTORY_SEPARATOR . FilesystemRepositoryInterface::DIR_SCHEMA . DIRECTORY_SEPARATOR . $index1->getName(); $schemaPath1 = $folderPath . DIRECTORY_SEPARATOR . $type1->getName() . FilesystemRepositoryInterface::FILE_EXTENSION; $schemaPath2 = $folderPath . DIRECTORY_SEPARATOR . $type2->getName() . FilesystemRepositoryInterface::FILE_EXTENSION; $this->filesystem->expects($this->once())->method('mkdir')->with($folderPath); $this->filesystem->expects($this->exactly(2))->method('dumpFile')->withConsecutive(array($schemaPath1, json_encode($type1->getSchema())), array($schemaPath2, json_encode($type2->getSchema()))); $createdFiles = $this->filesystemRepository->storeMappings($path, $mappings); $this->assertSame(2, $createdFiles); }