-
Notifications
You must be signed in to change notification settings - Fork 0
/
PublicUrlPluginTest.php
73 lines (58 loc) · 2.44 KB
/
PublicUrlPluginTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace Thib\FlysystemPublicUrlPluginTest;
use Aws\S3\S3Client;
use Exception;
use League\Flysystem\Adapter\Local;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Filesystem;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Thib\FlysystemPublicUrlPlugin\Adapter\LocalUrlAdapter;
use Thib\FlysystemPublicUrlPlugin\PublicUrlPlugin;
use Thib\FlysystemPublicUrlPluginTest\Support\DummyAdapter;
use Thib\FlysystemPublicUrlPluginTest\Support\DummyPublicUrlAdapter;
class PublicUrlPluginTest extends TestCase
{
/**
* @throws Exception
*/
public function testAttachesToFilesystemInstance() {
$adapter = new DummyAdapter();
$filesystem = new Filesystem($adapter);
$plugin = $this->createPlugin($filesystem);
$filesystem->addPlugin($plugin);
$plugin->addAdapter(DummyAdapter::class, DummyPublicUrlAdapter::class);
$this->assertEquals($filesystem->getPublicUrl("/path/to/file"), "/path/to/file");
}
public function testCallsAwsS3Adapter() {
$s3ClientProphecy = $this->prophesize(S3Client::class);
// Method `getObjectUrl` on S3Client will return bucket and path concatenated
$s3ClientProphecy->getObjectUrl(Argument::cetera())->will(function($args) {
return $args[0] . $args[1];
});
$adapter = new AwsS3Adapter($s3ClientProphecy->reveal(), 'BUCKET');
$filesystem = new Filesystem($adapter);
$plugin = $this->createPlugin($filesystem);
$this->assertEquals($plugin->handle("/path/to/file"), "BUCKET/path/to/file");
}
public function testCallsLocalUrlAdapter() {
// Create a simple empty mock
$adapter = $this->createMock(Local::class);
$filesystem = new Filesystem($adapter);
$plugin = $this->createPlugin($filesystem);
$plugin->addAdapter(get_class($adapter), LocalUrlAdapter::class, ["/root/folder"]);
$this->assertEquals($plugin->handle("/path/to/file"), "/root/folder/path/to/file");
}
public function testReturnsNullWithUnsupportedAdapter() {
$filesystem = new Filesystem(new DummyAdapter());
$plugin = $this->createPlugin($filesystem);
$this->assertNull($plugin->handle("/path/to/file"));
}
private function createPlugin(?Filesystem $filesystem = null) {
$plugin = new PublicUrlPlugin();
if ($filesystem) {
$plugin->setFilesystem($filesystem);
}
return $plugin;
}
}