1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the xAPI package. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace XApi\Repository\Doctrine\Tests\Unit\Repository; |
13
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
use Xabbuh\XApi\DataFixtures\ActivityFixtures; |
16
|
|
|
use Xabbuh\XApi\DataFixtures\ActorFixtures; |
17
|
|
|
use Xabbuh\XApi\Model\IRI; |
18
|
|
|
use XApi\Repository\Doctrine\Mapping\Object as MappedObject; |
19
|
|
|
use XApi\Repository\Doctrine\Repository\ActivityRepository; |
20
|
|
|
use XApi\Repository\Doctrine\Storage\ObjectStorage; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author Jérôme Parmentier <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class ActivityRepositoryTest extends TestCase |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|ObjectStorage |
29
|
|
|
*/ |
30
|
|
|
private $objectStorage; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var ActivityRepository |
34
|
|
|
*/ |
35
|
|
|
private $activityRepository; |
36
|
|
|
|
37
|
|
|
protected function setUp() |
38
|
|
|
{ |
39
|
|
|
$this->objectStorage = $this->createObjectStorageMock(); |
40
|
|
|
$this->activityRepository = new ActivityRepository($this->objectStorage); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
View Code Duplication |
public function testFindActivityById() |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$activityId = IRI::fromString('http://tincanapi.com/conformancetest/activityid'); |
46
|
|
|
|
47
|
|
|
$this |
|
|
|
|
48
|
|
|
->objectStorage |
49
|
|
|
->expects($this->once()) |
50
|
|
|
->method('findObject') |
51
|
|
|
->with(array( |
52
|
|
|
'type' => 'activity', |
53
|
|
|
'activityId' => $activityId->getValue(), |
54
|
|
|
)) |
55
|
|
|
->will($this->returnValue(MappedObject::fromModel(ActivityFixtures::getIdActivity()))); |
56
|
|
|
|
57
|
|
|
$this->activityRepository->findActivityById($activityId); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @expectedException \Xabbuh\XApi\Common\Exception\NotFoundException |
62
|
|
|
*/ |
63
|
|
|
public function testNotFoundObject() |
64
|
|
|
{ |
65
|
|
|
$activityId = IRI::fromString('http://tincanapi.com/conformancetest/activityid'); |
66
|
|
|
|
67
|
|
|
$this |
|
|
|
|
68
|
|
|
->objectStorage |
69
|
|
|
->expects($this->once()) |
70
|
|
|
->method('findObject') |
71
|
|
|
->with(array( |
72
|
|
|
'type' => 'activity', |
73
|
|
|
'activityId' => $activityId->getValue(), |
74
|
|
|
)) |
75
|
|
|
->will($this->returnValue(null)); |
76
|
|
|
|
77
|
|
|
$this->activityRepository->findActivityById($activityId); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @expectedException \Xabbuh\XApi\Common\Exception\NotFoundException |
82
|
|
|
*/ |
83
|
|
View Code Duplication |
public function testObjectIsNotAnActivity() |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
$activityId = IRI::fromString('http://tincanapi.com/conformancetest/activityid'); |
86
|
|
|
|
87
|
|
|
$this |
|
|
|
|
88
|
|
|
->objectStorage |
89
|
|
|
->expects($this->once()) |
90
|
|
|
->method('findObject') |
91
|
|
|
->with(array( |
92
|
|
|
'type' => 'activity', |
93
|
|
|
'activityId' => $activityId->getValue(), |
94
|
|
|
)) |
95
|
|
|
->will($this->returnValue(MappedObject::fromModel(ActorFixtures::getMboxAgent()))); |
96
|
|
|
|
97
|
|
|
$this->activityRepository->findActivityById($activityId); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ObjectStorage |
102
|
|
|
*/ |
103
|
|
|
protected function createObjectStorageMock() |
104
|
|
|
{ |
105
|
|
|
return $this |
106
|
|
|
->getMockBuilder('\XApi\Repository\Doctrine\Storage\ObjectStorage') |
107
|
|
|
->getMock(); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.