Test enhancement (#18)

Wow! Thank you very much for fixing all this.

Cheers!
This commit is contained in:
Chun-Sheng, Li
2019-10-22 20:06:37 +08:00
committed by Milos Stojanovic
parent c7d88635b4
commit ea6933883f
18 changed files with 134 additions and 124 deletions

View File

@@ -13,7 +13,6 @@ namespace Tests\Unit;
use Filegator\Kernel\Request;
use Filegator\Kernel\Response;
use Filegator\Services\Auth\AuthInterface;
use Filegator\Services\Session\Session;
use Filegator\Services\Session\SessionStorageInterface;
use Tests\TestCase;
@@ -55,7 +54,7 @@ class AppTest extends TestCase
$config = $this->getMockConfig();
$app1 = $this->bootFreshApp($config, $request1, null, true);
$this->bootFreshApp($config, $request1, null, true);
$prev_session = $request1->getSession();
// another request with previous session

View File

@@ -21,7 +21,7 @@ class AuthTest extends TestCase
{
public function testSuccessfulLogin()
{
$ret = $this->sendRequest('POST', '/login', [
$this->sendRequest('POST', '/login', [
'username' => 'john@example.com',
'password' => 'john123',
]);

View File

@@ -11,6 +11,7 @@
namespace Tests\Feature;
use Tests\TestCase;
use Exception;
/**
* @internal
@@ -19,14 +20,14 @@ class FilesTest extends TestCase
{
protected $timestamp;
public function setUp(): void
protected function setUp(): void
{
$this->resetTempDir();
$this->timestamp = time();
}
public function tearDown(): void
protected function tearDown(): void
{
$this->resetTempDir();
}
@@ -234,7 +235,7 @@ class FilesTest extends TestCase
$username = 'john@example.com';
$this->signIn($username, 'john123');
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$this->sendRequest('POST', '/renameitem', [
'from' => 'missing.txt',
@@ -256,7 +257,7 @@ class FilesTest extends TestCase
],
];
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$this->sendRequest('POST', '/deleteitems', [
'items' => $items,
@@ -351,7 +352,7 @@ class FilesTest extends TestCase
],
];
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$this->sendRequest('POST', '/copyitems', [
'items' => $items,

View File

@@ -18,7 +18,7 @@ use Tests\TestCase;
*/
class UploadTest extends TestCase
{
public function setUp(): void
protected function setUp(): void
{
$this->resetTempDir();

View File

@@ -75,7 +75,7 @@ trait TestResponse
$constraint = new ArraySubset($subset, $checkForObjectIdentity);
static::assertThat($array, $constraint, $message);
self::assertThat($array, $constraint, $message);
}
public function getStatusCode()

View File

@@ -13,6 +13,8 @@ namespace Tests\Unit;
use Filegator\Services\Archiver\Adapters\ZipArchiver;
use Filegator\Services\Storage\Filesystem;
use Filegator\Services\Tmpfs\Adapters\Tmpfs;
use League\Flysystem\Memory\MemoryAdapter;
use League\Flysystem\Adapter\NullAdapter;
use Tests\TestCase;
/**
@@ -22,7 +24,7 @@ class ArchiverTest extends TestCase
{
protected $archiver;
public function setUp(): void
protected function setUp(): void
{
$tmpfs = new Tmpfs();
$tmpfs->init([
@@ -42,7 +44,7 @@ class ArchiverTest extends TestCase
$storage->init([
'separator' => '/',
'adapter' => function () {
return new \League\Flysystem\Adapter\NullAdapter();
return new NullAdapter();
},
]);
@@ -58,7 +60,7 @@ class ArchiverTest extends TestCase
$storage->init([
'separator' => '/',
'adapter' => function () {
return new \League\Flysystem\Memory\MemoryAdapter();
return new MemoryAdapter();
},
]);
@@ -80,7 +82,7 @@ class ArchiverTest extends TestCase
$storage->init([
'separator' => '/',
'adapter' => function () {
return new \League\Flysystem\Memory\MemoryAdapter();
return new MemoryAdapter();
},
]);
@@ -102,7 +104,7 @@ class ArchiverTest extends TestCase
$storage->init([
'separator' => '/',
'adapter' => function () {
return new \League\Flysystem\Memory\MemoryAdapter();
return new MemoryAdapter();
},
]);
@@ -114,7 +116,7 @@ class ArchiverTest extends TestCase
$this->archiver->uncompress('/testarchive.zip', '/result', $storage);
$this->assertStringContainsString('testarchive', (json_encode($storage->getDirectoryCollection('/'))));
$this->assertStringContainsString('onetwo', (json_encode($storage->getDirectoryCollection('/result'))));
$this->assertStringContainsString('testarchive', json_encode($storage->getDirectoryCollection('/')));
$this->assertStringContainsString('onetwo', json_encode($storage->getDirectoryCollection('/result')));
}
}

View File

@@ -13,7 +13,9 @@ namespace Tests\Unit\Auth;
use Filegator\Kernel\Request;
use Filegator\Services\Auth\User;
use Filegator\Services\Session\Adapters\SessionStorage;
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage;
use Tests\TestCase;
use Exception;
abstract class AuthTest extends TestCase
{
@@ -21,12 +23,12 @@ abstract class AuthTest extends TestCase
protected $session;
public function setUp(): void
protected function setUp(): void
{
$this->session = new SessionStorage(new Request());
$this->session->init([
'handler' => function () {
return new \Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage();
return new MockFileSessionStorage();
},
]);
@@ -72,7 +74,7 @@ abstract class AuthTest extends TestCase
public function testWeCanFindAUser()
{
$admin = $this->addAdmin();
$this->addAdmin();
$user = $this->auth->find('admin@example.com');
@@ -84,7 +86,7 @@ abstract class AuthTest extends TestCase
$mike = $this->addMike();
$user = $this->auth->find('mike@example.com');
$this->assertEquals($user, $mike);
$this->assertEquals($mike, $user);
}
public function testWeCanUpdateExistingUser()
@@ -100,9 +102,9 @@ abstract class AuthTest extends TestCase
$updated_user = $this->auth->update('admin@example.com', $user);
$this->assertEquals($updated_user->getName(), 'Jonny B');
$this->assertEquals($updated_user->getHomeDir(), '/jonnyshome');
$this->assertEquals($updated_user->getUsername(), 'jonny@example.com');
$this->assertEquals('Jonny B', $updated_user->getName());
$this->assertEquals('/jonnyshome', $updated_user->getHomeDir());
$this->assertEquals('jonny@example.com', $updated_user->getUsername());
$this->assertTrue($updated_user->isUser());
}
@@ -110,7 +112,7 @@ abstract class AuthTest extends TestCase
{
$admin = $this->addAdmin('test123');
$auth_attempt1 = $this->auth->authenticate('admin@example.com', 'test123');
$this->auth->authenticate('admin@example.com', 'test123');
$auth_user = $this->auth->user();
$this->assertEquals($auth_user->getUsername(), $admin->getUsername());
@@ -123,12 +125,12 @@ abstract class AuthTest extends TestCase
$this->auth->authenticate('admin@example.com', 'test123');
$auth_user = $this->auth->user();
$this->assertEquals($auth_user->getUsername(), $admin->getUsername());
$this->assertEquals($admin->getUsername(), $auth_user->getUsername());
$this->auth->forget();
$auth_user = $this->auth->user();
$this->assertEquals($auth_user, null);
$this->assertNull($auth_user);
}
public function testWeCanUpdateUsersPassword()
@@ -139,10 +141,10 @@ abstract class AuthTest extends TestCase
$this->assertFalse($this->auth->authenticate('test123@example.com', 'test123'));
$auth_attempt1 = $this->auth->authenticate('admin@example.com', 'newpassword');
$this->auth->authenticate('admin@example.com', 'newpassword');
$auth_user = $this->auth->user();
$this->assertEquals($auth_user->getUsername(), $admin->getUsername());
$this->assertEquals($admin->getUsername(), $auth_user->getUsername());
}
public function testWeCanDeleteUser()
@@ -158,7 +160,7 @@ abstract class AuthTest extends TestCase
public function testWeCannotUpdateNonExistingUser()
{
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$user = new User();
$user->setRole('user');
@@ -177,7 +179,7 @@ abstract class AuthTest extends TestCase
$user->setUsername('tim@example.com');
$user->setName('Tim');
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$this->auth->delete($user);
}
@@ -192,9 +194,9 @@ abstract class AuthTest extends TestCase
$second_admin->setUsername('admin@example.com');
$second_admin->setName('Admin2');
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$updated_user = $this->auth->add($second_admin, 'pass444');
$this->auth->add($second_admin, 'pass444');
}
public function testWeCannotEditUserAndSetUsernameThatIsAlreadyTaken()
@@ -209,14 +211,14 @@ abstract class AuthTest extends TestCase
$user->setUsername('admin@example.com');
$user->setRole('user');
$this->expectException(\Exception::class);
$updated_user = $this->auth->update('mike@example.com', $user);
$this->expectException(Exception::class);
$this->auth->update('mike@example.com', $user);
}
public function testNoGuestException()
{
$this->expectException(\Exception::class);
$guest = $this->auth->getGuest();
$this->expectException(Exception::class);
$this->auth->getGuest();
}
public function testGetGuest()
@@ -232,6 +234,6 @@ abstract class AuthTest extends TestCase
$this->addAdmin();
$this->addMike();
$this->assertEquals($this->auth->allUsers()->length(), 2);
$this->assertEquals(2, $this->auth->allUsers()->length());
}
}

View File

@@ -41,6 +41,6 @@ class DatabaseAuthTest extends AuthTest
[password] VARCHAR(255) NOT NULL
)');
$ret = $this->conn->fetch('SELECT * FROM users WHERE username = ?', 'admin');
$this->conn->fetch('SELECT * FROM users WHERE username = ?', 'admin');
}
}

View File

@@ -19,7 +19,7 @@ class JsonFileTest extends AuthTest
{
private $mock_file = TEST_DIR.'/mockusers.json';
public function tearDown(): void
protected function tearDown(): void
{
@unlink($this->mock_file);
@unlink($this->mock_file.'.blank');

View File

@@ -15,6 +15,7 @@ use Filegator\Services\Auth\UsersCollection;
use Filegator\Services\Storage\DirectoryCollection;
use Filegator\Utils\Collection;
use Tests\TestCase;
use Exception;
/**
* @internal
@@ -27,7 +28,7 @@ class CollectionTest extends TestCase
$mock->add('one');
$mock->add('two');
$this->assertEquals($mock->length(), 2);
$this->assertEquals(2, $mock->length());
}
public function testDeleteFromCollection()
@@ -36,7 +37,7 @@ class CollectionTest extends TestCase
$mock->add('one');
$mock->delete('one');
$this->assertEquals($mock->length(), 0);
$this->assertEquals(0, $mock->length());
}
public function testSort()
@@ -46,15 +47,15 @@ class CollectionTest extends TestCase
$mock->add(['val' => 'a']);
$mock->add(['val' => 'c']);
$this->assertEquals($mock->all()[0]['val'], 'b');
$this->assertEquals('b', $mock->all()[0]['val']);
$mock->sortByValue('val');
$this->assertEquals($mock->all()[0]['val'], 'a');
$this->assertEquals('a', $mock->all()[0]['val']);
$mock->sortByValue('val', true);
$this->assertEquals($mock->all()[0]['val'], 'c');
$this->assertEquals('c', $mock->all()[0]['val']);
}
public function testUsersCollection()
@@ -69,7 +70,7 @@ class CollectionTest extends TestCase
$mock->addUser($user2);
$mock->addUser($user3);
$this->assertEquals($mock->length(), 3);
$this->assertEquals(3, $mock->length());
}
public function testUserSerialization()
@@ -81,7 +82,7 @@ class CollectionTest extends TestCase
$json = json_encode($mock);
$this->assertEquals($json, '[{"val":"b"},{"val":"a"},{"val":"c"}]');
$this->assertEquals('[{"val":"b"},{"val":"a"},{"val":"c"}]', $json);
}
public function testDirectoryCollection()
@@ -95,9 +96,9 @@ class CollectionTest extends TestCase
$json = json_encode($dir);
$this->assertEquals($json, '{"location":"\/sub1\/sub2","files":[{"type":"back","path":"\/sub1","name":"..","size":0,"time":1558942228},{"type":"dir","path":"\/sub1\/sub2\/sub3","name":"sub3","size":0,"time":1558942228},{"type":"file","path":"\/sub1\/sub2\/test.txt","name":"test.txt","size":30000,"time":1558942228},{"type":"file","path":"\/sub1\/sub2\/test2.txt","name":"test.txt","size":30000,"time":1558942228}]}');
$this->assertEquals('{"location":"\/sub1\/sub2","files":[{"type":"back","path":"\/sub1","name":"..","size":0,"time":1558942228},{"type":"dir","path":"\/sub1\/sub2\/sub3","name":"sub3","size":0,"time":1558942228},{"type":"file","path":"\/sub1\/sub2\/test.txt","name":"test.txt","size":30000,"time":1558942228},{"type":"file","path":"\/sub1\/sub2\/test2.txt","name":"test.txt","size":30000,"time":1558942228}]}', $json);
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$dir->addFile('badType', 'aaa', 'aa', 0, 1558942228);
}
@@ -110,6 +111,6 @@ class CollectionTest extends TestCase
$json = json_encode($user);
$this->assertEquals($json, '[{"role":"guest","permissions":[],"homedir":"","username":"","name":""},{"role":"guest","permissions":[],"homedir":"","username":"","name":""}]');
$this->assertEquals('[{"role":"guest","permissions":[],"homedir":"","username":"","name":""},{"role":"guest","permissions":[],"homedir":"","username":"","name":""}]', $json);
}
}

View File

@@ -34,12 +34,12 @@ class ConfigTest extends TestCase
$config = new Config($sample);
$this->assertEquals($config->get(), $sample);
$this->assertEquals($config->get('test'), 'something');
$this->assertEquals($config->get('test2.deep'), 123);
$this->assertEquals($config->get('test3.sub.subsub'), 2);
$this->assertEquals($config->get('not-found'), null);
$this->assertEquals($config->get('not-found', 'default'), 'default');
$this->assertEquals($config->get('not.found', 'default'), 'default');
$this->assertEquals($sample, $config->get());
$this->assertEquals('something', $config->get('test'));
$this->assertEquals(123, $config->get('test2.deep'));
$this->assertEquals(2, $config->get('test3.sub.subsub'));
$this->assertNull($config->get('not-found'));
$this->assertEquals('default', $config->get('not-found', 'default'));
$this->assertEquals('default', $config->get('not.found', 'default'));
}
}

View File

@@ -11,7 +11,9 @@
namespace Tests\Unit;
use Filegator\Services\Storage\Filesystem;
use League\Flysystem\Adapter\Local;
use Tests\TestCase;
use Exception;
/**
* @internal
@@ -24,7 +26,7 @@ class FilesystemTest extends TestCase
protected $separator = '/';
public function setUp(): void
protected function setUp(): void
{
$this->resetTempDir();
@@ -34,19 +36,19 @@ class FilesystemTest extends TestCase
$this->storage->init([
'separator' => '/',
'adapter' => function () {
return new \League\Flysystem\Adapter\Local(
return new Local(
TEST_REPOSITORY
);
},
]);
}
public function tearDown(): void
protected function tearDown(): void
{
$this->resetTempDir();
}
public function testGetDirectyoryFileCount()
public function testGetDirectoryFileCount()
{
$this->storage->createFile('/', '1.txt');
$this->storage->createFile('/', '2.txt');
@@ -114,7 +116,7 @@ class FilesystemTest extends TestCase
$ret = $this->storage->getDirectoryCollection('/john/johnsub');
$ret->resetTimestamps();
$this->assertJsonStringEqualsJsonString(json_encode($ret), json_encode([
$this->assertJsonStringEqualsJsonString(json_encode([
'location' => '/john/johnsub',
'files' => [
0 => [
@@ -132,7 +134,7 @@ class FilesystemTest extends TestCase
'time' => 0,
],
],
]));
]), json_encode($ret));
}
public function testHomeDirContentsUsingPathPrefix()
@@ -144,7 +146,7 @@ class FilesystemTest extends TestCase
$ret = $this->storage->getDirectoryCollection('/');
$ret->resetTimestamps(-1);
$this->assertJsonStringEqualsJsonString(json_encode($ret), json_encode([
$this->assertJsonStringEqualsJsonString(json_encode([
'location' => '/',
'files' => [
0 => [
@@ -162,7 +164,7 @@ class FilesystemTest extends TestCase
'time' => -1,
],
],
]));
]), json_encode($ret));
}
public function testSubDirContentsUsingPathPrefix()
@@ -175,7 +177,7 @@ class FilesystemTest extends TestCase
$ret->resetTimestamps();
$this->assertJsonStringEqualsJsonString(json_encode($ret), json_encode([
$this->assertJsonStringEqualsJsonString(json_encode([
'location' => '/johnsub',
'files' => [
0 => [
@@ -193,7 +195,7 @@ class FilesystemTest extends TestCase
'time' => 0,
],
],
]));
]), json_encode($ret));
}
public function testStoringFileToRoot()
@@ -256,11 +258,11 @@ class FilesystemTest extends TestCase
// first file is not overwritten
$ret = $this->storage->readStream('singletone.txt');
$this->assertEquals(stream_get_contents($ret['stream']), 'lorem ipsum');
$this->assertEquals('lorem ipsum', stream_get_contents($ret['stream']));
// second file is also here but with upcounted name
$ret = $this->storage->readStream('singletone (1).txt');
$this->assertEquals(stream_get_contents($ret['stream']), 'croissant');
$this->assertEquals('croissant', stream_get_contents($ret['stream']));
}
public function testCreatingFileWithTheSameNameUpcountsFilenameRecursively()
@@ -350,16 +352,16 @@ class FilesystemTest extends TestCase
public function testGetPathPrefix()
{
$this->storage->setPathPrefix('/john/');
$this->assertEquals($this->storage->getPathPrefix(), '/john/');
$this->assertEquals('/john/', $this->storage->getPathPrefix());
$this->storage->setPathPrefix('/john');
$this->assertEquals($this->storage->getPathPrefix(), '/john/');
$this->assertEquals('/john/', $this->storage->getPathPrefix());
$this->storage->setPathPrefix('john/');
$this->assertEquals($this->storage->getPathPrefix(), '/john/');
$this->assertEquals('/john/', $this->storage->getPathPrefix());
$this->storage->setPathPrefix('john');
$this->assertEquals($this->storage->getPathPrefix(), '/john/');
$this->assertEquals('/john/', $this->storage->getPathPrefix());
}
public function testApplyPathPrefix()
@@ -471,12 +473,12 @@ class FilesystemTest extends TestCase
$ret = $this->storage->readStream('a.txt');
$this->assertEquals($ret['filename'], 'a.txt');
$this->assertTrue(is_resource($ret['stream']));
$this->assertIsResource($ret['stream']);
}
public function testReadFileStreamMissingFileThrowsException()
{
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$this->storage->readStream('missing');
}
@@ -485,7 +487,7 @@ class FilesystemTest extends TestCase
{
$this->storage->createDir('/', 'sub');
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$this->storage->readStream('sub');
}
@@ -557,7 +559,7 @@ class FilesystemTest extends TestCase
public function testRenameNonexistingFileThrowsException()
{
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$this->storage->move('/', 'nonexisting.txt', 'a1.txt');
}
@@ -629,7 +631,7 @@ class FilesystemTest extends TestCase
{
$this->storage->createDir('/', 'tmp');
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$this->storage->copyFile('/missing.txt', '/tmp/');
}

View File

@@ -34,8 +34,8 @@ class MainTest extends TestCase
$app = new App($config, $request, $response, $sresponse, $container);
$this->assertEquals($app->resolve(Config::class), $config);
$this->assertEquals($app->resolve(Request::class), $request);
$this->assertEquals($config, $app->resolve(Config::class));
$this->assertEquals($request, $app->resolve(Request::class));
$this->assertInstanceOf(Response::class, $app->resolve(Response::class));
}
}

View File

@@ -25,15 +25,15 @@ class RequestTest extends TestCase
'GET'
);
$this->assertEquals($request->all(), [
$this->assertEquals([
'r' => '/test',
'a' => '1',
'b' => '2',
]);
], $request->all());
$this->assertEquals($request->input('r'), '/test');
$this->assertEquals($request->input('a'), '1');
$this->assertEquals($request->input('b'), '2');
$this->assertEquals('/test', $request->input('r'));
$this->assertEquals('1', $request->input('a'));
$this->assertEquals('2', $request->input('b'));
}
public function testPostRequest()
@@ -44,13 +44,13 @@ class RequestTest extends TestCase
['param1' => '1', 'param2' => '2']
);
$this->assertEquals($request->all(), [
$this->assertEquals([
'param1' => '1',
'param2' => '2',
]);
], $request->all());
$this->assertEquals($request->input('param1'), '1');
$this->assertEquals($request->input('param2'), '2');
$this->assertEquals('1', $request->input('param1'));
$this->assertEquals('2', $request->input('param2'));
}
public function testJsonRequest()
@@ -65,11 +65,11 @@ class RequestTest extends TestCase
json_encode(['sample' => 'content'])
);
$this->assertEquals($request->all(), [
$this->assertEquals([
'sample' => 'content',
]);
], $request->all());
$this->assertEquals($request->input('sample'), 'content');
$this->assertEquals('content', $request->input('sample'));
}
public function testGetAndJsonParametersTogether()
@@ -84,15 +84,15 @@ class RequestTest extends TestCase
json_encode(['sample' => 'content', 'more' => '1'])
);
$this->assertEquals($request->all(), [
$this->assertEquals([
'priority' => '1',
'sample' => 'content',
'more' => '1',
]);
], $request->all());
$this->assertEquals($request->input('priority'), '1');
$this->assertEquals($request->input('sample'), 'content');
$this->assertEquals($request->input('more'), '1');
$this->assertEquals('1', $request->input('priority'));
$this->assertEquals('content', $request->input('sample'));
$this->assertEquals('1', $request->input('more'));
}
public function testGetPostParametersTogether()
@@ -103,15 +103,15 @@ class RequestTest extends TestCase
['param' => 'param1', 'priority' => 5]
);
$this->assertEquals($request->all(), [
$this->assertEquals([
'priority' => '10',
'something' => 'else',
'param' => 'param1',
]);
], $request->all());
$this->assertEquals($request->input('priority'), '10');
$this->assertEquals($request->input('something'), 'else');
$this->assertEquals($request->input('param'), 'param1');
$this->assertEquals('10', $request->input('priority'));
$this->assertEquals('else', $request->input('something'));
$this->assertEquals('param1', $request->input('param'));
}
public function testGetPostAndJsonParametersTogether()
@@ -126,16 +126,16 @@ class RequestTest extends TestCase
json_encode(['sample' => 'content', 'priority' => '2'])
);
$this->assertEquals($request->all(), [
$this->assertEquals([
'priority' => '10',
'something' => 'else',
'param' => 'param1',
'sample' => 'content',
]);
], $request->all());
$this->assertEquals($request->input('priority'), '10');
$this->assertEquals($request->input('something'), 'else');
$this->assertEquals($request->input('param'), 'param1');
$this->assertEquals($request->input('sample'), 'content');
$this->assertEquals('10', $request->input('priority'));
$this->assertEquals('else', $request->input('something'));
$this->assertEquals('param1', $request->input('param'));
$this->assertEquals('content', $request->input('sample'));
}
}

View File

@@ -24,7 +24,7 @@ class RouterTest extends TestCase
{
private $config_stub;
public function setUp(): void
protected function setUp(): void
{
$this->config_stub = [
'query_param' => 'r',
@@ -46,7 +46,7 @@ class RouterTest extends TestCase
->with(['\Filegator\Controllers\ViewController', 'index'], [])
;
$router = $this->getRouter($request, $user, $container);
$this->getRouter($request, $user, $container);
}
public function testPostToLogin()
@@ -61,7 +61,7 @@ class RouterTest extends TestCase
->with(['\Filegator\Controllers\AuthController', 'login'], [])
;
$router = $this->getRouter($request, $user, $container);
$this->getRouter($request, $user, $container);
}
public function testRouteNotFound()
@@ -76,7 +76,7 @@ class RouterTest extends TestCase
->with(['\Filegator\Controllers\ErrorController', 'notFound'], [])
;
$router = $this->getRouter($request, $user, $container);
$this->getRouter($request, $user, $container);
}
public function testMethodNotAllowed()
@@ -91,7 +91,7 @@ class RouterTest extends TestCase
->with(['\Filegator\Controllers\ErrorController', 'methodNotAllowed'], [])
;
$router = $this->getRouter($request, $user, $container);
$this->getRouter($request, $user, $container);
}
public function testRouteIsProtectedFromGuests()
@@ -106,7 +106,7 @@ class RouterTest extends TestCase
->with(['\Filegator\Controllers\ErrorController', 'notFound'], [])
;
$router = $this->getRouter($request, $user, $container);
$this->getRouter($request, $user, $container);
}
public function testRouteIsAllowedForUser()
@@ -122,7 +122,7 @@ class RouterTest extends TestCase
->with(['ProtectedController', 'protectedMethod'], [])
;
$router = $this->getRouter($request, $user, $container);
$this->getRouter($request, $user, $container);
}
public function testRouteIsProtectedFromUsers()
@@ -138,7 +138,7 @@ class RouterTest extends TestCase
->with(['\Filegator\Controllers\ErrorController', 'notFound'], [])
;
$router = $this->getRouter($request, $user, $container);
$this->getRouter($request, $user, $container);
}
public function testRouteIsAllowedForAdmin()
@@ -154,7 +154,7 @@ class RouterTest extends TestCase
->with(['AdminController', 'adminOnlyMethod'], [])
;
$router = $this->getRouter($request, $user, $container);
$this->getRouter($request, $user, $container);
}
private function getRouter(Request $request, User $user, Container $container)

View File

@@ -21,7 +21,7 @@ class SessionStorageTest extends TestCase
{
protected $session_service;
public function setUp(): void
protected function setUp(): void
{
$this->session_service = new SessionStorage(new Request());
$this->session_service->init([
@@ -53,7 +53,7 @@ class SessionStorageTest extends TestCase
$this->session_service->set('test2', 999);
$this->session_service->save();
$this->assertEquals($this->session_service->get('test2'), 999);
$this->assertEquals(999, $this->session_service->get('test2'));
$this->assertNull($this->session_service->get('test1'));
}
}

View File

@@ -20,7 +20,7 @@ class TmpfsTest extends TestCase
{
protected $service;
public function setUp(): void
protected function setUp(): void
{
$this->resetTempDir();
rmdir(TEST_TMP_PATH);
@@ -56,7 +56,7 @@ class TmpfsTest extends TestCase
$contents = $this->service->read('a.txt');
$this->assertEquals($contents, 'lorem');
$this->assertEquals('lorem', $contents);
}
public function testReadingTmpFileContentsUsingStream()
@@ -67,7 +67,7 @@ class TmpfsTest extends TestCase
$this->assertEquals($ret['filename'], 'a.txt');
$contents = stream_get_contents($ret['stream']);
$this->assertEquals($contents, 'lorem');
$this->assertEquals('lorem', $contents);
}
public function testRemovingTmpFile()

View File

@@ -8,8 +8,11 @@
* For the full copyright and license information, please view the LICENSE file
*/
namespace Tests\Unit;
use Filegator\Services\Auth\User;
use Tests\TestCase;
use Exception;
/**
* @internal
@@ -68,7 +71,7 @@ class UserTest extends TestCase
{
$user = new User();
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$user->setRole('nonexistent');
}
@@ -77,7 +80,7 @@ class UserTest extends TestCase
{
$user = new User();
$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$user->setPermissions(['read', 'write', 'nonexistent']);
}