Skip to content

Commit

Permalink
test: fix broken test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
streamtw committed Nov 30, 2023
1 parent 8b190dc commit 89d3d5d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
4 changes: 2 additions & 2 deletions tests/LfmItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class LfmItemTest extends TestCase
private $lfm_path;
private $lfm;

public function setUp()
public function setUp(): void
{
$this->lfm = m::mock(Lfm::class);

Expand All @@ -24,7 +24,7 @@ public function setUp()
->andReturn(['name', 'url', 'time', 'icon', 'is_file', 'is_image', 'thumb_url']);
}

public function tearDown()
public function tearDown(): void
{
m::close();

Expand Down
2 changes: 1 addition & 1 deletion tests/LfmPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class LfmPathTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
m::close();

Expand Down
5 changes: 3 additions & 2 deletions tests/LfmStorageRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class LfmStorageRepositoryTest extends TestCase
{
private $storage;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand All @@ -24,6 +24,7 @@ public function setUp()
$disk->shouldReceive('functionToCall')->with('foo/bar')->andReturn('baz');
$disk->shouldReceive('directories')->with('foo')->andReturn(['foo/bar']);
$disk->shouldReceive('move')->with('foo/bar', 'foo/bar/baz')->andReturn(true);
$disk->shouldReceive('path')->andReturn('foo/bar');

$helper = m::mock(Lfm::class);
$helper->shouldReceive('config')->with('disk')->andReturn('local');
Expand All @@ -33,7 +34,7 @@ public function setUp()
$this->storage = new LfmStorageRepository('foo/bar', $helper);
}

public function tearDown()
public function tearDown(): void
{
m::close();
}
Expand Down
23 changes: 19 additions & 4 deletions tests/LfmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class LfmTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
m::close();

Expand Down Expand Up @@ -50,8 +50,13 @@ public function testAllowFolderType()
$config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(false);
$config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(true);
$config->shouldReceive('get')->with('lfm.allow_shared_folder')->once()->andReturn(false);
$config->shouldReceive('get')->with('lfm.folder_categories')->andReturn([]);
$config->shouldReceive('has')->andReturn(false);

$lfm = new Lfm($config);
$request = m::mock(Request::class);
$request->shouldReceive('input')->with('type')->andReturn('');

$lfm = new Lfm($config, $request);

$this->assertTrue($lfm->allowFolderType('user'));
$this->assertTrue($lfm->allowFolderType('shared'));
Expand Down Expand Up @@ -155,8 +160,13 @@ public function testAllowMultiUser()
{
$config = m::mock(Config::class);
$config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(true);
$config->shouldReceive('get')->with('lfm.folder_categories')->andReturn([]);
$config->shouldReceive('has')->andReturn(false);

$lfm = new Lfm($config);
$request = m::mock(Request::class);
$request->shouldReceive('input')->with('type')->andReturn('');

$lfm = new Lfm($config, $request);

$this->assertTrue($lfm->allowMultiUser());
}
Expand All @@ -167,8 +177,13 @@ public function testAllowShareFolder()
$config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(false);
$config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(true);
$config->shouldReceive('get')->with('lfm.allow_shared_folder')->once()->andReturn(false);
$config->shouldReceive('get')->with('lfm.folder_categories')->andReturn([]);
$config->shouldReceive('has')->andReturn(false);

$lfm = new Lfm($config);
$request = m::mock(Request::class);
$request->shouldReceive('input')->with('type')->andReturn('');

$lfm = new Lfm($config, $request);

$this->assertTrue($lfm->allowShareFolder());
$this->assertFalse($lfm->allowShareFolder());
Expand Down
8 changes: 4 additions & 4 deletions tests/LfmUploadValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ public function testFailsNameIsNotDuplicate()
$validator->nameIsNotDuplicate('new_file_name', $lfm_path);
}

public function testPassesIsNotExcutable()
public function testPassesMimetypeIsNotExcutable()
{
$uploaded_file = m::mock(UploadedFile::class);
$uploaded_file->shouldReceive('getMimeType')->andReturn('image/jpeg');

$validator = new LfmUploadValidator($uploaded_file);

$this->assertEquals($validator->isNotExcutable(), $validator);
$this->assertEquals($validator->mimetypeIsNotExcutable(['text/x-php']), $validator);
}

public function testFailsIsNotExcutable()
public function testFailsMimetypeIsNotExcutable()
{
$uploaded_file = m::mock(UploadedFile::class);
$uploaded_file->shouldReceive('getMimeType')->andReturn('text/x-php');
Expand All @@ -111,7 +111,7 @@ public function testFailsIsNotExcutable()

$this->expectException(ExcutableFileException::class);

$validator->isNotExcutable();
$validator->mimetypeIsNotExcutable(['text/x-php']);
}

public function testPassesMimeTypeIsValid()
Expand Down

0 comments on commit 89d3d5d

Please sign in to comment.