/** * @covers PHPExiftool\Writer::write */ public function testWriteInPlaceErased() { $metadatas = new Driver\Metadata\MetadataBag(); $metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\IPTC\ObjectName(), new Driver\Value\Mono('Beautiful Object'))); $metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\IPTC\ObjectName(), new Driver\Value\Mono('Beautiful Object'))); $metadatas->add(new Driver\Metadata\Metadata(new Driver\Tag\XMPIptcExt\PersonInImage(), new Driver\Value\Multi(array('Romain', 'Nicolas')))); $this->object->erase(true); $changedFiles = $this->object->write($this->inPlace, $metadatas); $this->assertEquals(1, $changedFiles); $reader = new Reader($this->getExiftool(), new RDFParser()); $metadatasRead = $reader->files($this->inPlace)->first()->getMetadatas(); $this->assertLessThan(50, count($metadatasRead)); $this->assertEquals('Beautiful Object', $metadatasRead->get('IPTC:ObjectName')->getValue()->asString()); $this->assertEquals(array('Romain', 'Nicolas'), $metadatasRead->get('XMP-iptcExt:PersonInImage')->getValue()->asArray()); }
/** * Generates a metadatas-free version of the file in the temporary directory * * @return string the path file to the temporary file */ private function getTemporaryEmptyFile() { $tmpFile = tempnam(sys_get_temp_dir(), 'hash'); unlink($tmpFile); try { $this->writer->reset(); $this->writer->erase(true); $this->writer->write($this->file->getPathname(), new MetadataBag(), $tmpFile); } catch (PHPExiftoolExceptionInterface $e) { /** * Some files can not be written by exiftool */ copy($this->file->getPathname(), $tmpFile); } $this->temporaryFiles[] = $tmpFile; return $tmpFile; }