forked from rwincewicz/php_listeners
-
Notifications
You must be signed in to change notification settings - Fork 8
/
FedoraMock.php
69 lines (52 loc) · 1.62 KB
/
FedoraMock.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
<?php
require_once 'PHPUnit/Autoload.php';
require_once 'FedoraConnect.php';
function getFedoraMock($test_case) {
$fedora_mock = $test_case->getMock('FedoraConnection', array(
'getDatastream'
));
$repo_mock = getRepoMock($test_case);
$fedora_mock->expects($test_case->any())
->method('__get')
->with($test_case->equalTo('repository'))
->will($test_case->returnValue($repo_mock));
$fedora_mock->expects($test_case->any())
->method('getDatastream')
->with($test_case->equalTo('islandora:313'),
$test_case->equalTo('TEST_TXT'))
->will($test_case->returnValue((object)array(
'content' => "test text"
)));
return $fedora_mock;
}
function getRepoMock($test_case) {
$repo_mock = $test_case->getMockBuilder('FedoraRepository')
->disableOriginalConstructor()
->getMock();
$fedora_objects = array(
'islandora:313' => getMockFedoraObject($test_case, array(
'TEST_TXT' => 'test text'
))
);
$islandora313 = $test_case->getMockBuilder('FedoraObject')
->disableOriginalConstructor()
->getMock();
$repo_mock->expects($test_case->any())
->method('getObject')
->with($test_case->equalTo("islandora:313"))
->will($test_case->returnValue($islandora313));
return $repo_mock;
}
function getMockFedoraObject($test_case, $datastreams) {
$object = $test_case->getMockBuilder('FedoraObject')
->disableOriginalConstructor()
->getMock();
foreach ($datastreams as $dsid => $content) {
$object->expects($test_case->any())
->method('getDatastream')
->with($test_case->equalTo($dsid))
->will($test_case->returnValue($content));
}
return $object;
}
?>