Skip to content

Commit

Permalink
Merge pull request #36586 from owncloud/phpunit-php7.4-stuff
Browse files Browse the repository at this point in the history
php unit test changes to address issues that php7.4 will report
  • Loading branch information
phil-davis authored Apr 7, 2020
2 parents 6504861 + 0434cca commit dfb9985
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ public function reflect($object, $method) {
// over phpdoc annotations
if (\method_exists($param, 'getType')) {
$type = $param->getType();
'@phan-var \ReflectionNamedType $type';
if ($type !== null) {
$this->types[$param->getName()] = (string) $type;
$this->types[$param->getName()] = $type->getName();
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function getNumericStorageId() {
* get the stored metadata of a file or folder
*
* @param string | int $file either the path of a file or folder or the file id for a file or folder
* @return ICacheEntry|false the cache entry as array of false if the file is not found in the cache
* @return ICacheEntry|false the cache entry as array or false if the file is not found in the cache
*/
public function get($file) {
if (\is_string($file) or $file == '') {
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Cache/FileCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ protected function setUp(): void {
}

protected function tearDown(): void {
if ($this->instance) {
$this->instance->remove('hack', 'hack');
if ($this->instance->get('hack') !== null) {
$this->instance->remove('hack');
}

parent::tearDown();
Expand Down
12 changes: 6 additions & 6 deletions tests/lib/Command/Integrity/SignAppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,23 +221,23 @@ public function testExecute() {
->expects($this->at(1))
->method('getOption')
->with('privateKey')
->will($this->returnValue('privateKey'));
->will($this->returnValue(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'));
$inputInterface
->expects($this->at(2))
->method('getOption')
->with('certificate')
->will($this->returnValue('certificate'));
->will($this->returnValue(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'));

$this->fileAccessHelper
->expects($this->at(0))
->method('file_get_contents')
->with('privateKey')
->will($this->returnValue(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'));
->with(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')
->will($this->returnValue(\file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')));
$this->fileAccessHelper
->expects($this->at(1))
->method('file_get_contents')
->with('certificate')
->will($this->returnValue(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'));
->with(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt')
->will($this->returnValue(\file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt')));

$this->checker
->expects($this->once())
Expand Down
12 changes: 6 additions & 6 deletions tests/lib/Command/Integrity/SignCoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ public function testExecute() {
->expects($this->at(0))
->method('getOption')
->with('privateKey')
->will($this->returnValue('privateKey'));
->will($this->returnValue(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'));
$inputInterface
->expects($this->at(1))
->method('getOption')
->with('certificate')
->will($this->returnValue('certificate'));
->will($this->returnValue(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'));
$inputInterface
->expects($this->at(2))
->method('getOption')
Expand All @@ -187,13 +187,13 @@ public function testExecute() {
$this->fileAccessHelper
->expects($this->at(0))
->method('file_get_contents')
->with('privateKey')
->will($this->returnValue(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'));
->with(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')
->will($this->returnValue(\file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')));
$this->fileAccessHelper
->expects($this->at(1))
->method('file_get_contents')
->with('certificate')
->will($this->returnValue(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'));
->with(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt')
->will($this->returnValue(\file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt')));

$this->checker
->expects($this->once())
Expand Down
8 changes: 6 additions & 2 deletions tests/lib/Files/Cache/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,12 @@ public function testRootFolderSizeForNonHomeStorage() {

// clean up
$this->cache->remove('');
$this->cache->remove($dir1);
$this->cache->remove($dir2);
if ($this->cache->get($dir1)) {
$this->cache->remove($dir1);
}
if ($this->cache->get($dir2)) {
$this->cache->remove($dir2);
}

$this->assertFalse($this->cache->inCache($dir1));
$this->assertFalse($this->cache->inCache($dir2));
Expand Down
16 changes: 12 additions & 4 deletions tests/lib/Files/Cache/HomeCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,15 @@ public function testRootFolderSizeIgnoresUnknownUpdate() {

// clean up
$this->cache->remove('');
$this->cache->remove('files');
$this->cache->remove($dir1);
$this->cache->remove($dir2);
if ($this->cache->get('files')) {
$this->cache->remove('files');
}
if ($this->cache->get($dir1)) {
$this->cache->remove($dir1);
}
if ($this->cache->get($dir2)) {
$this->cache->remove($dir2);
}

$this->assertFalse($this->cache->inCache('files'));
$this->assertFalse($this->cache->inCache($dir1));
Expand Down Expand Up @@ -132,7 +138,9 @@ public function testRootFolderSizeIsFilesSize() {

// clean up
$this->cache->remove('');
$this->cache->remove($dir1);
if ($this->cache->get($dir1)) {
$this->cache->remove($dir1);
}

$this->assertFalse($this->cache->inCache($dir1));
}
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/Files/Cache/Wrapper/CacheJailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public function setUp(): void {
$this->cache = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, 'foo');
}

protected function tearDown(): void {
if ($this->sourceCache) {
$this->sourceCache->clear();
}
}

public function testSearchOutsideJail() {
$file1 = 'foo/foobar';
$file2 = 'folder/foobar';
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Util/User/MemoryAccountMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function search($fieldName, $pattern, $limit, $offset) {
return self::$accounts;
}
$match = \array_filter(self::$accounts, function (Account $a) use ($pattern) {
return \stripos($a->getUserId(), $pattern);
return \stripos($a->getUserId(), (string) $pattern);
});

return $match;
Expand Down

0 comments on commit dfb9985

Please sign in to comment.