forked from Potherca/flysystem-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGithubAdapterTest.php
More file actions
92 lines (80 loc) · 3.39 KB
/
GithubAdapterTest.php
File metadata and controls
92 lines (80 loc) · 3.39 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace Potherca\Flysystem\Github;
use PHPUnit_Framework_MockObject_Matcher_Parameters;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
/**
* Tests for the GithubAdapter class
*
* @coversDefaultClass \Potherca\Flysystem\Github\GithubAdapter
* @covers ::<!public>
* @covers ::__construct
* @covers ::getApi
*/
class GithubAdapterTest extends \PHPUnit_Framework_TestCase
{
////////////////////////////////// FIXTURES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
const MOCK_FILE_PATH = '/path/to/mock/file';
const MOCK_FOLDER_PATH = 'a-directory';
/** @var GithubAdapter */
private $adapter;
/** @var ApiInterface|MockObject */
private $mockClient;
/**
*
*/
protected function setup()
{
$this->mockClient = $this->getMock(ApiInterface::class);
$this->adapter = new GithubAdapter($this->mockClient);
}
/////////////////////////////////// TESTS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/**
* @covers ::has
* @covers ::read
* @covers ::listContents
* @covers ::getMetadata
* @covers ::getSize
* @covers ::getMimetype
* @covers ::getTimestamp
* @covers ::getVisibility
*
* @dataProvider provideReadMethods
*
* @param $method
* @param $apiMethod
* @param $parameters
* @param mixed $returnValue
*/
final public function testAdapterShouldPassParameterToClient($method, $apiMethod, $parameters, $returnValue = null)
{
if (is_string($returnValue) && is_file(sprintf('%s/../fixtures/%s.json', __DIR__, $returnValue))) {
$fixturePath = sprintf('%s/../fixtures/%s.json', __DIR__, $returnValue);
$fixture = json_decode(file_get_contents($fixturePath), true);
$returnValue = $fixture['tree'];
}
$mocker = $this->mockClient->expects(self::exactly(1))
->method($apiMethod)
->willReturn($returnValue)
;
$mocker->getMatcher()->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_Parameters($parameters);
call_user_func_array([$this->adapter, $method], $parameters);
}
////////////////////////////// MOCKS AND STUBS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/////////////////////////////// DATAPROVIDERS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
final public function provideReadMethods()
{
return [
'has' => ['has', 'exists', [self::MOCK_FILE_PATH]],
'read' => ['read', 'getFileContents', [self::MOCK_FILE_PATH]],
'listContents - File' => ['listContents', 'getTreeMetadata', [self::MOCK_FILE_PATH, false]],
'listContents - File - recursive' => ['listContents', 'getTreeMetadata', [self::MOCK_FILE_PATH, true]],
'listContents - Folder' => ['listContents', 'getTreeMetadata', [self::MOCK_FOLDER_PATH, false], ''],
'listContents - Folder - recursive' => ['listContents', 'getTreeMetadata', [self::MOCK_FOLDER_PATH, true], 'listContents-folder-recursive'],
'getMetadata' => ['getMetadata', 'getMetadata', [self::MOCK_FILE_PATH]],
'getSize' => ['getSize', 'getMetadata', [self::MOCK_FILE_PATH]],
'getMimetype' => ['getMimetype', 'guessMimeType', [self::MOCK_FILE_PATH]],
'getTimestamp' => ['getTimestamp', 'getLastUpdatedTimestamp', [self::MOCK_FILE_PATH]],
'getVisibility' => ['getVisibility', 'getTreeMetadata', [self::MOCK_FILE_PATH]],
];
}
}