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\Api\Test\Functional; |
13
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
use Xabbuh\XApi\Model\Activity; |
16
|
|
|
use Xabbuh\XApi\Model\IRI; |
17
|
|
|
use XApi\Repository\Api\ActivityRepositoryInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Jérôme Parmentier <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
abstract class ActivityRepositoryTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var ActivityRepositoryInterface |
26
|
|
|
*/ |
27
|
|
|
private $activityRepository; |
28
|
|
|
|
29
|
|
|
protected function setUp() |
30
|
|
|
{ |
31
|
|
|
$this->activityRepository = $this->createActivityRepository(); |
32
|
|
|
$this->cleanDatabase(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function tearDown() |
36
|
|
|
{ |
37
|
|
|
$this->cleanDatabase(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @expectedException \Xabbuh\XApi\Common\Exception\NotFoundException |
42
|
|
|
*/ |
43
|
|
|
public function testFetchingNonExistingActivityThrowsException() |
44
|
|
|
{ |
45
|
|
|
$this->activityRepository->findActivityById(IRI::fromString('not-existing')); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @dataProvider getStatementsWithId |
50
|
|
|
*/ |
51
|
|
|
public function testActivitiesCanBeRetrievedById(Activity $activity) |
52
|
|
|
{ |
53
|
|
|
$fetchedActivity = $this->activityRepository->findActivityById($activity->getId()); |
54
|
|
|
|
55
|
|
|
$this->assertTrue($activity->equals($fetchedActivity)); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getActivitiesWithId() |
59
|
|
|
{ |
60
|
|
|
$fixtures = array(); |
61
|
|
|
|
62
|
|
|
foreach (get_class_methods('Xabbuh\XApi\DataFixtures\ActivityFixtures') as $method) { |
63
|
|
|
$activity = call_user_func(array('Xabbuh\XApi\DataFixtures\ActivityFixtures', $method)); |
64
|
|
|
|
65
|
|
|
if ($activity instanceof Activity) { |
66
|
|
|
$fixtures[$method] = array($activity); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $fixtures; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
abstract protected function createActivityRepository(); |
74
|
|
|
|
75
|
|
|
abstract protected function cleanDatabase(); |
76
|
|
|
} |
77
|
|
|
|