Commit f27e61a6 authored by Vincent Petry's avatar Vincent Petry Committed by GitHub
Browse files

Merge pull request #26888 from owncloud/fix-26870

Fix warnings for ExcludeFileByNameFilterIterator test
parents 5a10d044 99e0a5a5
...@@ -58,11 +58,14 @@ class ExcludeFileByNameFilterIterator extends \RecursiveFilterIterator { ...@@ -58,11 +58,14 @@ class ExcludeFileByNameFilterIterator extends \RecursiveFilterIterator {
* @return bool * @return bool
*/ */
public function accept() { public function accept() {
if($this->isDir()) { /** @var \SplFileInfo $current */
$current = $this->current();
if ($current->isDir()) {
return true; return true;
} }
$currentFileName = $this->current()->getFilename(); $currentFileName = $current->getFilename();
if (in_array($currentFileName, $this->excludedFilenames, true)){ if (in_array($currentFileName, $this->excludedFilenames, true)){
return false; return false;
} }
......
...@@ -25,13 +25,14 @@ use \OC\IntegrityCheck\Iterator\ExcludeFileByNameFilterIterator; ...@@ -25,13 +25,14 @@ use \OC\IntegrityCheck\Iterator\ExcludeFileByNameFilterIterator;
use Test\TestCase; use Test\TestCase;
class ExcludeFileByNameFilterIteratorTest extends TestCase { class ExcludeFileByNameFilterIteratorTest extends TestCase {
/** @var ExcludeFileByNameFilterIterator */ /** @var \PHPUnit_Framework_MockObject_MockBuilder */
protected $filter; protected $filter;
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->filter = $this->getMockBuilder(ExcludeFileByNameFilterIterator::class) $this->filter = $this->getMockBuilder(ExcludeFileByNameFilterIterator::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->setMethods(['current'])
->getMock() ->getMock()
; ;
...@@ -54,13 +55,17 @@ class ExcludeFileByNameFilterIteratorTest extends TestCase { ...@@ -54,13 +55,17 @@ class ExcludeFileByNameFilterIteratorTest extends TestCase {
* @param bool $expectedResult * @param bool $expectedResult
*/ */
public function testAcceptForFiles($fileName, $expectedResult){ public function testAcceptForFiles($fileName, $expectedResult){
$iteratorMock = $this->createMock(\DirectoryIterator::class); $iteratorMock = $this->getMockBuilder(\RecursiveDirectoryIterator::class)
->disableOriginalConstructor()
->setMethods(['getFilename', 'isDir'])
->getMock()
;
$iteratorMock->method('getFilename') $iteratorMock->method('getFilename')
->will($this->returnValue($fileName)) ->will($this->returnValue($fileName))
; ;
$iteratorMock->method('isDir')
$this->filter->method('isDir')
->will($this->returnValue(false)); ->will($this->returnValue(false));
$this->filter->method('current') $this->filter->method('current')
->will($this->returnValue($iteratorMock)) ->will($this->returnValue($iteratorMock))
; ;
...@@ -75,18 +80,22 @@ class ExcludeFileByNameFilterIteratorTest extends TestCase { ...@@ -75,18 +80,22 @@ class ExcludeFileByNameFilterIteratorTest extends TestCase {
* @param bool $fakeExpectedResult * @param bool $fakeExpectedResult
*/ */
public function testAcceptForDirs($fileName, $fakeExpectedResult){ public function testAcceptForDirs($fileName, $fakeExpectedResult){
$iteratorMock = $this->createMock(\DirectoryIterator::class); $iteratorMock = $this->getMockBuilder(\RecursiveDirectoryIterator::class)
->disableOriginalConstructor()
->setMethods(['getFilename', 'isDir'])
->getMock()
;
$iteratorMock->method('getFilename') $iteratorMock->method('getFilename')
->will($this->returnValue($fileName)) ->will($this->returnValue($fileName))
; ;
$iteratorMock->method('isDir')
$this->filter->method('isDir')
->will($this->returnValue(true)); ->will($this->returnValue(true));
$this->filter->method('current') $this->filter->method('current')
->will($this->returnValue($iteratorMock)) ->will($this->returnValue($iteratorMock))
; ;
$actualResult = $this->filter->accept(); $actualResult = $this->filter->accept();
$this->assertFalse($actualResult); $this->assertTrue($actualResult);
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment