public function testTagVersion() { $tagger = new tagger\engine($adapter = new atoum\test\adapter()); $adapter->is_dir = true; $adapter->mkdir = function () { }; $this->assert->exception(function () use($tagger) { $tagger->tagVersion(uniqid()); })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Unable to tag, src directory is undefined'); $tagger->setSrcDirectory($srcDirectory = uniqid()); $this->assert->exception(function () use($tagger) { $tagger->tagVersion(uniqid()); })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Unable to tag, version is undefined'); $tagger->setVersion($version = uniqid())->setSrcIteratorInjector(function ($directory) { }); $this->assert->exception(function () use($tagger) { $tagger->tagVersion(uniqid()); })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Unable to tag, src iterator injector does not return an iterator'); $srcIterator = new \arrayIterator(array($file1 = $srcDirectory . \DIRECTORY_SEPARATOR . ($basename1 = uniqid()), $file2 = $srcDirectory . \DIRECTORY_SEPARATOR . ($basename2 = uniqid()), $file3 = $srcDirectory . \DIRECTORY_SEPARATOR . ($basename3 = uniqid()))); $tagger->setSrcIteratorInjector(function ($directory) use($srcIterator) { return $srcIterator; }); $adapter->file_get_contents[1] = ($file1Part1 = uniqid()) . '\'$Rev: ' . rand(1, PHP_INT_MAX) . ' $\'' . ($file1Part2 = uniqid()); $adapter->file_get_contents[2] = $contentOfFile2 = uniqid(); $adapter->file_get_contents[3] = ($file3Part1 = uniqid()) . '"$Rev: ' . rand(1, PHP_INT_MAX) . ' $"' . ($file3Part2 = uniqid()); $adapter->file_put_contents = function () { }; $this->assert->object($tagger->tagVersion())->isIdenticalTo($tagger)->adapter($adapter)->call('file_get_contents')->withArguments($file1)->once()->call('file_put_contents')->withArguments($file1, $file1Part1 . '\'' . $version . '\'' . $file1Part2, \LOCK_EX)->once()->call('file_get_contents')->withArguments($file2)->once()->call('file_put_contents')->withArguments($file2, $contentOfFile2, \LOCK_EX)->once()->call('file_get_contents')->withArguments($file3)->once()->call('file_put_contents')->withArguments($file3, $file3Part1 . '"' . $version . '"' . $file3Part2, \LOCK_EX)->once(); $adapter->resetCalls()->file_get_contents[2] = false; $this->assert->exception(function () use($tagger) { $tagger->tagVersion(uniqid()); })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Unable to tag, path \'' . $file2 . '\' is unreadable'); $adapter->resetCalls(); $adapter->file_get_contents[2] = $contentOfFile2; $adapter->file_put_contents[2] = false; $this->assert->exception(function () use($tagger) { $tagger->tagVersion(uniqid()); })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Unable to tag, path \'' . $file2 . '\' is unwritable'); $adapter->resetCalls(); unset($adapter->file_put_contents[2]); $tagger->setDestinationDirectory($destinationDirectory = uniqid()); $this->assert->object($tagger->tagVersion())->isIdenticalTo($tagger)->adapter($adapter)->call('is_dir')->withArguments($destinationDirectory)->exactly(3)->call('mkdir')->never()->call('file_get_contents')->withArguments($file1)->once()->call('file_put_contents')->withArguments($destinationDirectory . \DIRECTORY_SEPARATOR . $basename1, $file1Part1 . '\'' . $version . '\'' . $file1Part2, \LOCK_EX)->once()->call('file_get_contents')->withArguments($file2)->once()->call('file_put_contents')->withArguments($destinationDirectory . \DIRECTORY_SEPARATOR . $basename2, $contentOfFile2, \LOCK_EX)->once()->call('file_get_contents')->withArguments($file3)->once()->call('file_put_contents')->withArguments($destinationDirectory . \DIRECTORY_SEPARATOR . $basename3, $file3Part1 . '"' . $version . '"' . $file3Part2, \LOCK_EX)->once(); $adapter->resetCalls()->is_dir = false; $this->assert->object($tagger->tagVersion())->isIdenticalTo($tagger)->adapter($adapter)->call('is_dir')->withArguments($destinationDirectory)->exactly(3)->call('mkdir')->withArguments($destinationDirectory, 0777, true)->exactly(3)->call('file_get_contents')->withArguments($file1)->once()->call('file_put_contents')->withArguments($destinationDirectory . \DIRECTORY_SEPARATOR . $basename1, $file1Part1 . '\'' . $version . '\'' . $file1Part2, \LOCK_EX)->once()->call('file_get_contents')->withArguments($file2)->once()->call('file_put_contents')->withArguments($destinationDirectory . \DIRECTORY_SEPARATOR . $basename2, $contentOfFile2, \LOCK_EX)->once()->call('file_get_contents')->withArguments($file3)->once()->call('file_put_contents')->withArguments($destinationDirectory . \DIRECTORY_SEPARATOR . $basename3, $file3Part1 . '"' . $version . '"' . $file3Part2, \LOCK_EX)->once(); }