Skip to content

Commit aa7a97b

Browse files
author
Ramesh Mhetre
committed
Configured PHPunit and added first test
1 parent 9abd298 commit aa7a97b

5 files changed

+89
-2
lines changed

phpunit.hhvm.xml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="./phpunit.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="true"
12+
verbose="true"
13+
>
14+
<testsuites>
15+
<testsuite name="flysystem/tests">
16+
<directory suffix=".php">./tests/</directory>
17+
</testsuite>
18+
</testsuites>
19+
<filter>
20+
<whitelist>
21+
<directory suffix=".php">./src/</directory>
22+
</whitelist>
23+
</filter>
24+
</phpunit>

phpunit.php

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
require __DIR__.'/vendor/autoload.php';

phpunit.xml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="./phpunit.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="true"
12+
verbose="true"
13+
>
14+
<testsuites>
15+
<testsuite name="flysystem/tests">
16+
<directory suffix=".php">./tests/</directory>
17+
</testsuite>
18+
</testsuites>
19+
<filter>
20+
<whitelist>
21+
<directory suffix=".php">./src/</directory>
22+
</whitelist>
23+
</filter>
24+
<logging>
25+
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
26+
<log type="coverage-html" target="coverage" showUncoveredFiles="true"/>
27+
<log type="coverage-clover" target="coverage.xml" showUncoveredFiles="true"/>
28+
</logging>
29+
</phpunit>

src/BackblazeAdapter.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,25 @@ public function has($path)
3434
*/
3535
public function write($path, $contents, Config $config)
3636
{
37-
return $this->getClient()->upload([
37+
$file = $this->getClient()->upload([
3838
'BucketName' => $this->bucketName,
3939
'FileName' => $path,
4040
'Body' => $contents
4141
]);
42+
return $this->getFileInfo($file);
4243
}
4344

4445
/**
4546
* {@inheritdoc}
4647
*/
4748
public function writeStream($path, $resource, Config $config)
4849
{
49-
return $this->getClient()->upload([
50+
$file = $this->getClient()->upload([
5051
'BucketName' => $this->bucketName,
5152
'FileName' => $path,
5253
'Body' => $resource
5354
]);
55+
return $this->getFileInfo($file);
5456
}
5557

5658
/**

tests/BackblazeAdapterTests.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use ChrisWhite\B2\Client;
4+
use Mhetreramesh\Flysystem\BackblazeAdapter as Backblaze;
5+
use \ChrisWhite\B2\File;
6+
use \League\Flysystem\Config;
7+
8+
class BackblazeAdapterTests extends PHPUnit_Framework_TestCase
9+
{
10+
public function backblazeProvider()
11+
{
12+
$mock = $this->prophesize('ChrisWhite\B2\Client');
13+
return [
14+
[new Backblaze($mock->reveal(), 'my_bucket'), $mock],
15+
];
16+
}
17+
18+
/**
19+
* @dataProvider backblazeProvider
20+
*/
21+
public function testWrite($adapter, $mock)
22+
{
23+
$mock->upload(["BucketName" => "my_bucket", "FileName" => "something", "Body" => "contents"])->willReturn(new File('something','','','',''), false);
24+
$result = $adapter->write('something', 'contents', new Config());
25+
$this->assertInternalType('array', $result);
26+
$this->assertArrayHasKey('type', $result);
27+
$this->assertEquals('file', $result['type']);
28+
}
29+
}

0 commit comments

Comments
 (0)