Skip to content

Commit

Permalink
Fix Dropbox tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianfeldmann committed Nov 15, 2024
1 parent 73ac8c4 commit 22da16d
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions tests/phpbu/Backup/Sync/DropboxTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php
namespace phpbu\App\Backup\Sync;

use Kunnu\Dropbox\Models\FileMetadata;
use Kunnu\Dropbox\Models\MetadataCollection;
use phpbu\App\Backup\Target;
use phpbu\App\BaseMockery;
use phpbu\App\Result;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -27,6 +31,8 @@ public function testSetUpOk()
$dropbox = new Dropbox();
$dropbox->setup([
'token' => 'this-is-no-token',
'appKey' => 'this-is-no-key',
'appSecret' => 'this-is-no-secret',
'path' => '/'
]);

Expand All @@ -44,16 +50,18 @@ public function testSlasherizePath()

$dropbox = new Dropbox();
$dropbox->setup([
'token' => 'this-is-no-token',
'path' => 'foo'
'token' => 'this-is-no-token',
'appKey' => 'this-is-no-key',
'appSecret' => 'this-is-no-secret',
'path' => 'foo'
]);

$resultStub = $this->createMock(\phpbu\App\Result::class);
$resultStub = $this->createMock(Result::class);
$resultStub->expects($this->once())
->method('debug')
->with($this->equalTo($msg));

$targetStub = $this->createMock(\phpbu\App\Backup\Target::class);
$targetStub = $this->createMock(Target::class);

$dropbox->simulate($targetStub, $resultStub);
}
Expand All @@ -64,10 +72,10 @@ public function testSlasherizePath()
public function testSync()
{
$target = $this->createTargetMock('foo.txt', 'foo.txt.gz');
$result = $this->createMock(\phpbu\App\Result::class);
$result = $this->createMock(Result::class);
$result->expects($this->once())->method('debug');

$metaMock = $this->createMock(\Kunnu\Dropbox\Models\FileMetadata::class);
$metaMock = $this->createMock(FileMetadata::class);
$metaMock->expects($this->once())->method('getSize')->willReturn(12345678);

$clientMock = $this->createMock(\Kunnu\Dropbox\Dropbox::class);
Expand All @@ -77,8 +85,10 @@ public function testSync()
$dropbox->method('createClient')->willReturn($clientMock);

$dropbox->setup([
'token' => 'this-is-no-token',
'path' => '/'
'token' => 'this-is-no-token',
'appKey' => 'this-is-no-key',
'appSecret' => 'this-is-no-secret',
'path' => '/'
]);

$dropbox->sync($target, $result);
Expand All @@ -90,13 +100,13 @@ public function testSync()
public function testSyncWithCleanup()
{
$target = $this->createTargetMock('foo.txt', 'foo.txt.gz');
$result = $this->createMock(\phpbu\App\Result::class);
$result = $this->createMock(Result::class);
$result->expects($this->exactly(2))->method('debug');

$metaMock = $this->createMock(\Kunnu\Dropbox\Models\FileMetadata::class);
$metaMock = $this->createMock(FileMetadata::class);
$metaMock->expects($this->once())->method('getSize')->willReturn(12345678);

$metaCollectionMock = $this->createMock(\Kunnu\Dropbox\Models\MetadataCollection::class);
$metaCollectionMock = $this->createMock(MetadataCollection::class);
$metaCollectionMock->expects($this->once())->method('getItems')->willReturn([]);

$clientMock = $this->createMock(\Kunnu\Dropbox\Dropbox::class);
Expand All @@ -108,6 +118,8 @@ public function testSyncWithCleanup()

$dropbox->setup([
'token' => 'this-is-no-token',
'appKey' => 'this-is-no-key',
'appSecret' => 'this-is-no-secret',
'path' => '/',
'cleanup.type' => 'quantity',
'cleanup.amount' => 99
Expand All @@ -123,7 +135,7 @@ public function testSyncFail()
{
$this->expectException('phpbu\App\Exception');
$target = $this->createTargetMock('foo.txt', 'foo.txt.gz');
$result = $this->createMock(\phpbu\App\Result::class);
$result = $this->createMock(Result::class);

$clientMock = $this->createMock(\Kunnu\Dropbox\Dropbox::class);
$clientMock->expects($this->once())->method('upload')->will($this->throwException(new \Exception));
Expand All @@ -132,8 +144,10 @@ public function testSyncFail()
$dropbox->method('createClient')->willReturn($clientMock);

$dropbox->setup([
'token' => 'this-is-no-token',
'path' => '/'
'token' => 'this-is-no-token',
'appKey' => 'this-is-no-key',
'appSecret' => 'this-is-no-secret',
'path' => '/'
]);

$dropbox->sync($target, $result);
Expand All @@ -146,15 +160,17 @@ public function testSimulate()
{
$dropbox = new Dropbox();
$dropbox->setup([
'token' => 'this-is-no-token',
'path' => '/'
'token' => 'this-is-no-token',
'appKey' => 'this-is-no-key',
'appSecret' => 'this-is-no-secret',
'path' => '/'
]);

$resultStub = $this->createMock(\phpbu\App\Result::class);
$resultStub = $this->createMock(Result::class);
$resultStub->expects($this->once())
->method('debug');

$targetStub = $this->createMock(\phpbu\App\Backup\Target::class);
$targetStub = $this->createMock(Target::class);

$dropbox->simulate($targetStub, $resultStub);
}
Expand All @@ -176,6 +192,12 @@ public function testSetUpNoPath()
{
$this->expectException('phpbu\App\Backup\Sync\Exception');
$dropbox = new Dropbox();
$dropbox->setup(['token' => 'this-is-no-token']);
$dropbox->setup(
[
'token' => 'this-is-no-token',
'appKey' => 'this-is-no-key',
'appSecret' => 'this-is-no-secret'
]
);
}
}

0 comments on commit 22da16d

Please sign in to comment.