Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore(CI): Only strict is beautiful
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Mar 24, 2023
commit 3b07ac7b1f60bbea4f30b470d43d99589d358ddb
39 changes: 21 additions & 18 deletions tests/Unit/StorageWrapperTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2016 Joas Schilling <[email protected]>
*
Expand All @@ -21,18 +23,19 @@

namespace OCA\FilesAccessControl\Tests\Unit;

use OCA\FilesAccessControl\Operation;
use OCA\FilesAccessControl\StorageWrapper;
use OCP\Files\ForbiddenException;
use Test\TestCase;
use OCP\Files\Storage\IStorage;
use OCA\FilesAccessControl\Operation;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class StorageWrapperTest extends TestCase {

/** @var \OCP\Files\Storage\IStorage|\PHPUnit_Framework_MockObject_MockObject */
/** @var IStorage|MockObject */
protected $storage;

/** @var \OCA\FilesAccessControl\Operation|\PHPUnit_Framework_MockObject_MockObject */
/** @var Operation|MockObject */
protected $operation;

protected function setUp(): void {
Expand All @@ -56,7 +59,7 @@ protected function getInstance(array $methods = []) {
->getMock();
}

public function dataCheckFileAccess() {
public function dataCheckFileAccess(): array {
return [
['path1'],
['path2'],
Expand All @@ -67,23 +70,23 @@ public function dataCheckFileAccess() {
* @dataProvider dataCheckFileAccess
* @param string $path
*/
public function testCheckFileAccess($path) {
public function testCheckFileAccess(string $path): void {
$storage = $this->getInstance();

$this->operation->expects($this->once())
->method('checkFileAccess')
->with($storage, $path);

$this->invokePrivate($storage, 'checkFileAccess', [$path]);
self::invokePrivate($storage, 'checkFileAccess', [$path]);
}

public function dataSinglePath() {
public function dataSinglePath(): array {
$methods = ['mkdir', 'rmdir', 'file_get_contents', 'unlink', 'getDirectDownload'];

$tests = [];
foreach ($methods as $method) {
$tests[] = [$method, 'path1', true, true];
$tests[] = [$method, 'path2', false, true];
$tests[] = [$method, 'path1', true, null];
$tests[] = [$method, 'path2', false, null];
$tests[] = [$method, 'path3', true, new ForbiddenException('Access denied', false)];
$tests[] = [$method, 'path4', false, new ForbiddenException('Access denied', false)];
}
Expand All @@ -95,13 +98,13 @@ public function dataSinglePath() {
* @param string $method
* @param string $path
* @param bool $return
* @param bool|\Exception $expected
* @param null|\Exception $expected
*/
public function testSinglePath($method, $path, $return, $expected) {
public function testSinglePath(string $method, string $path, bool $return, ?\Exception $expected): void {
$storage = $this->getInstance(['checkFileAccess']);


if (is_bool($expected)) {
if (is_null($expected)) {
$storage->expects($this->once())
->method('checkFileAccess')
->with($path);
Expand All @@ -111,7 +114,7 @@ public function testSinglePath($method, $path, $return, $expected) {
->with($path)
->willReturn($return);

$this->assertSame($return, $this->invokePrivate($storage, $method, [$path]));
$this->assertSame($return, self::invokePrivate($storage, $method, [$path]));
} else {
$storage->expects($this->once())
->method('checkFileAccess')
Expand All @@ -124,15 +127,15 @@ public function testSinglePath($method, $path, $return, $expected) {
->willReturn($return);

try {
$this->invokePrivate($storage, $method, [$path]);
self::invokePrivate($storage, $method, [$path]);
$this->fail('Should throw an exception before this');
} catch (\Exception $e) {
$this->assertSame($expected, $e);
}
}
}

public function dataSinglePathOverWritten() {
public function dataSinglePathOverWritten(): array {
$methods = ['isCreatable', 'isReadable', 'isUpdatable', 'isDeletable'];

$tests = [];
Expand All @@ -153,7 +156,7 @@ public function dataSinglePathOverWritten() {
* @param null|\Exception $checkAccess
* @param bool $expected
*/
public function testSinglePathOverWritten($method, $path, $return, $checkAccess, $expected) {
public function testSinglePathOverWritten(string $method, string $path, bool $return, ?\Exception $checkAccess, bool $expected): void {
$storage = $this->getInstance(['checkFileAccess']);


Expand All @@ -178,6 +181,6 @@ public function testSinglePathOverWritten($method, $path, $return, $checkAccess,
->willReturn($return);
}

$this->assertSame($expected, $this->invokePrivate($storage, $method, [$path]));
$this->assertSame($expected, self::invokePrivate($storage, $method, [$path]));
}
}