Completed
Pull Request — master (#10)
by
unknown
03:39
created

ActivityRepositoryTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
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 Xabbuh\XApi\Model\Activity;
15
use Xabbuh\XApi\Model\IRI;
16
use XApi\Repository\Api\ActivityRepositoryInterface;
17
18
/**
19
 * @author Jérôme Parmentier <[email protected]>
20
 */
21
abstract class ActivityRepositoryTest extends \PHPUnit_Framework_TestCase
22
{
23
    const UUID_REGEXP = '/^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i';
24
25
    /**
26
     * @var ActivityRepositoryInterface
27
     */
28
    private $activityRepository;
29
30
    protected function setUp()
31
    {
32
        $this->activityRepository = $this->createActivityRepository();
33
        $this->cleanDatabase();
34
    }
35
36
    protected function tearDown()
37
    {
38
        $this->cleanDatabase();
39
    }
40
41
    /**
42
     * @expectedException \Xabbuh\XApi\Common\Exception\NotFoundException
43
     */
44
    public function testFetchingNonExistingActivityThrowsException()
45
    {
46
        $this->activityRepository->findActivityById(IRI::fromString('not-existing'));
47
    }
48
49
    /**
50
     * @dataProvider getStatementsWithId
51
     */
52
    public function testActivitiesCanBeRetrievedById(Activity $activity)
53
    {
54
        $fetchedActivity = $this->activityRepository->findActivityById($activity->getId());
55
56
        $this->assertTrue($activity->equals($fetchedActivity));
57
    }
58
59
    public function getActivitiesWithId()
60
    {
61
        $fixtures = array();
62
63
        foreach (get_class_methods('Xabbuh\XApi\DataFixtures\ActivityFixtures') as $method) {
64
            $activity = call_user_func(array('Xabbuh\XApi\DataFixtures\ActivityFixtures', $method));
65
66
            if ($activity instanceof Activity) {
67
                $fixtures[$method] = array($activity);
68
            }
69
        }
70
71
        return $fixtures;
72
    }
73
74
    abstract protected function createActivityRepository();
75
76
    abstract protected function cleanDatabase();
77
}
78