Skip to content

Commit

Permalink
trying to be compatible with new changes in phpunit mocking of native…
Browse files Browse the repository at this point in the history
… File objects, refs #28
  • Loading branch information
digitronac committed Jul 23, 2014
1 parent afe8f6c commit 88c9286
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 45 deletions.
2 changes: 1 addition & 1 deletion apps/backend/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function registerAutoloaders()
'Robinson\Backend\Validator' => __DIR__ . '/validators/',
'Robinson\Backend\Tag' => __DIR__ . '/tags/',
'Robinson\Backend\Filter' => __DIR__ . '/filters/',
'Robinson\Frontend\Filter' => __DIR__ . '/filters/',
'Robinson\Frontend\Filter' => __DIR__ . '/../frontend/filters/',
)
);

Expand Down
28 changes: 11 additions & 17 deletions apps/backend/models/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -653,30 +653,24 @@ public function updateTags(array $tagsData)
*/
protected function removeObsoleteLeftovers()
{
$dir = $this->getDI()->get(
'DirectoryIterator',
array(
$this->getDI()->get('config')->application->packagePdfPath . '/' . $this->getPackageId()
)
);
while ($dir->valid()) {
/** @var \DirectoryIterator $file */
$file = $dir->current();

if ($file->isDot()) {
$dir->next();
continue;
}

/** @var \Symfony\Component\Finder\Finder $finder */
$finder = $this->getDI()->get('Symfony\Component\Finder\Finder');
$finder->files()->in($this->getDI()->get('config')->application->packagePdfPath . '/' . $this->getPackageId());
$finder->ignoreDotFiles(true);
$iterator = $finder->getIterator();
while ($iterator->valid()) {
/** @var \Symfony\Component\Finder\SplFileInfo $file */
$file = $iterator->current();
// original pdf file?
if ($file->getFilename() === $this->getPdf()) {
$dir->next();
$iterator->next();
continue;
}

$filesystem = $this->getDI()->get('Symfony\Component\Filesystem\Filesystem');
$filesystem->remove($file->getPathname());
$dir->next();
$iterator->next();
continue;
}
}
}
43 changes: 21 additions & 22 deletions apps/backend/tests/controllers/PackageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,38 +488,37 @@ public function testUpdatePackageWithUpdatedPdfShouldWorkAsExpectedAndClearObsol
$this->getDI()->set('Imagick', $this->mockWorkingImagick());


// mock directory iterator
$dirIterator = $this->getMockBuilder('DirectoryIterator')
$file = $this->getMockBuilder('Symfony\Component\Finder\SplFileInfo')
->disableOriginalConstructor()
->setMethods(array('valid', 'current'))
->getMock();

$fileIterator = $this->getMockBuilder('DirectoryIterator')
->disableOriginalConstructor()
->setMethods(array('isDot', 'getPathname', 'getFilename'))
->setMethods(array('getPathname', 'getFilename'))
->getMock();
$fileIterator->expects($this->any())
->method('isDot')
->will($this->returnValue(false));

// 1 times, on remove
$fileIterator->expects($this->exactly(1))
$file->expects($this->exactly(1))
->method('getPathname')
->will($this->onConsecutiveCalls('packagepdftest.pdf', 'packagepdftest.html'));


$fileIterator->expects($this->exactly(2))
$file->expects($this->exactly(2))
->method('getFilename')
->will($this->onConsecutiveCalls('packagepdftest.pdf', 'packagepdftest.html'));


$dirIterator->expects($this->any())
$iterator = $this->getMockBuilder('Symfony\Component\Finder\Iterator\PathFilterIterator')
->setMethods(array('valid', 'current'))
->setConstructorArgs(array(new \ArrayIterator(array()), array(), array()))
->getMock();
$iterator->expects($this->any())
->method('current')
->will($this->returnValue($file));
$iterator->expects($this->any())
->method('valid')
->will($this->onConsecutiveCalls(true, true, false));
$dirIterator->expects($this->any())
->method('current')
->will($this->returnValue($fileIterator));
$this->getDI()->set('DirectoryIterator', $dirIterator);

$finder = $this->getMockBuilder('Symfony\Component\Finder\Finder')
->setMethods(array('getIterator'))
->getMock();
$finder->expects($this->once())
->method('getIterator')
->will($this->returnValue($iterator));

$this->getDI()->set('Symfony\Component\Finder\Finder', $finder);

// mock filesystem component
$filesystem = $this->getMockBuilder('Symfony\Component\Filesystem\Filesystem')
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"ext-imagick": "*",
"phalcon/incubator": "1.3.0.x-dev#7e5660c293a3a11dea5ed594f5d73d996117d5ff",
"symfony/filesystem": "2.5.*@dev",
"symfony/finder": "2.5.*@dev",
"judev/php-htmltruncator": "1.0.0",
"zendframework/zend-resources": "2.2.5",
"zendframework/zend-mail": "2.2.5",
Expand Down
61 changes: 56 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 88c9286

Please sign in to comment.