Skip to content

Commit c3f52c3

Browse files
committed
Adds tests for the GithubAdapter class.
1 parent e32b673 commit c3f52c3

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

tests/GithubAdapterTest.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
4+
namespace Potherca\Flysystem\Github;
5+
6+
/**
7+
* Tests for the GithubAdapter class
8+
*
9+
* @coversDefaultClass \Potherca\Flysystem\Github\GithubAdapter
10+
* @covers ::<!public>
11+
* @covers ::__construct
12+
* @covers ::getClient
13+
*/
14+
class GithubAdapterTest extends \PHPUnit_Framework_TestCase
15+
{
16+
////////////////////////////////// FIXTURES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
17+
const MOCK_FILE_PATH = '/path/to/mock/file';
18+
19+
/** @var GithubAdapter */
20+
private $adapter;
21+
/** @var ClientInterface|\PHPUnit_Framework_MockObject_MockObject */
22+
private $mockClient;
23+
24+
/**
25+
*
26+
*/
27+
protected function setup()
28+
{
29+
$this->mockClient = $this->getMock(ClientInterface::class);
30+
$this->adapter = new GithubAdapter($this->mockClient);
31+
}
32+
33+
/////////////////////////////////// TESTS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
34+
/**
35+
* @covers ::has
36+
* @covers ::read
37+
* @covers ::listContents
38+
* @covers ::getMetadata
39+
* @covers ::getSize
40+
* @covers ::getMimetype
41+
* @covers ::getTimestamp
42+
* @covers ::getVisibility
43+
*
44+
* @dataProvider provideReadMethods
45+
*
46+
* @param $method
47+
* @param $clientMethod
48+
* @param $parameters
49+
*/
50+
final public function testAdapterShouldPassParameterToClient($method, $clientMethod, $parameters)
51+
{
52+
$mocker = $this->mockClient->expects($this->exactly(1))
53+
->method($clientMethod);
54+
55+
$mocker->getMatcher()->parametersMatcher = new \PHPUnit_Framework_MockObject_Matcher_Parameters($parameters);
56+
57+
call_user_func_array([$this->adapter, $method], $parameters);
58+
}
59+
60+
////////////////////////////// MOCKS AND STUBS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
61+
62+
/////////////////////////////// DATAPROVIDERS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
63+
final public function provideReadMethods()
64+
{
65+
return [
66+
['has', 'exists', [self::MOCK_FILE_PATH]],
67+
['read', 'getFileContents', [self::MOCK_FILE_PATH]],
68+
['listContents', 'getRecursiveMetadata', [self::MOCK_FILE_PATH, true]],
69+
['getMetadata', 'getMetadata', [self::MOCK_FILE_PATH]],
70+
['getSize', 'getMetadata', [self::MOCK_FILE_PATH]],
71+
['getMimetype', 'guessMimeType', [self::MOCK_FILE_PATH]],
72+
['getTimestamp', 'getLastUpdatedTimestamp', [self::MOCK_FILE_PATH]],
73+
['getVisibility', 'getRecursiveMetadata', [self::MOCK_FILE_PATH]],
74+
];
75+
}
76+
}

0 commit comments

Comments
 (0)