public function testItRemovesAnOldSourceFileBeforeReCompiling()
 {
     $parser = $this->createParser('new Node()');
     // Pre-filling item that should be deleted
     mkdir(Stream::url($this->fileSystem->path() . '/compiled'));
     file_put_contents(Stream::url($this->fileSystem->path() . '/compiled/item_id_item2.php'), '<?php test file');
     // Source contains only one handle, so no additional handles should be created
     $source = $this->createSource(array('item1' => array('node' => array_fill(0, 4, array()))));
     $handleFilePaths = array('item1' => Stream::url($this->fileSystem->path() . '/compiled/item_id_item1.php'), 'item2' => Stream::url($this->fileSystem->path() . '/compiled/item_id_item2.php'));
     $metadata = $this->createMetadata($handleFilePaths, true);
     $newMetadata = $this->createMetadata(array_diff_key($handleFilePaths, array('item2' => null)), true);
     $this->metadataFactory->expects($this->once())->method('createFromSource')->with($this->identicalTo($source), array('item1'))->willReturn($newMetadata);
     $compiler = new Compiler($this->getCompilerOptions() + array('parsers' => array('node' => $parser)));
     $this->assertSame($newMetadata, $compiler->compile($source, $metadata));
     $this->assertStringEqualsFile($handleFilePaths['item1'], "<?php \$this->addItem(new Node());\n\$this->addItem(new Node());\n\$this->addItem(new Node());\n\$this->addItem(new Node());");
     $this->assertFileNotExists($handleFilePaths['item2']);
 }
 /**
  * Sets a save path for a compiled layout files
  *
  * @param string $savePath
  * @return $this
  */
 public function setSavePath($savePath)
 {
     $this->traitSetSavePath($savePath);
     $this->metadataFactory->setSavePath($this->getSavePath());
     return $this;
 }