Completed
Push — master ( d286f2...718990 )
by Christian
01:57
created

testActivitiesCanBeRetrievedById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
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