Completed
Pull Request — master (#8)
by
unknown
04:37
created

ActivityRepositoryTest::createObjectStorageMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
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\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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
44
    {
45
        $activityId = IRI::fromString('http://tincanapi.com/conformancetest/activityid');
46
47
        $this
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<XApi\Repository\D...\Storage\ObjectStorage>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<XApi\Repository\D...\Storage\ObjectStorage>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
84
    {
85
        $activityId = IRI::fromString('http://tincanapi.com/conformancetest/activityid');
86
87
        $this
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<XApi\Repository\D...\Storage\ObjectStorage>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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