Completed
Pull Request — master (#3)
by Christian
02:33
created

StatementRepositoryTest::assertMappedStatement()   C

Complexity

Conditions 19
Paths 13

Size

Total Lines 52
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 52
c 0
b 0
f 0
rs 5.8807
cc 19
eloc 26
nc 13
nop 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 Rhumsaa\Uuid\Uuid;
15
use Xabbuh\XApi\DataFixtures\StatementFixtures;
16
use Xabbuh\XApi\DataFixtures\VerbFixtures;
17
use Xabbuh\XApi\Model\StatementId;
18
use Xabbuh\XApi\Model\StatementsFilter;
19
use XApi\Repository\Doctrine\Mapping\Statement as MappedStatement;
20
use XApi\Repository\Doctrine\Repository\StatementRepository;
21
22
/**
23
 * @author Christian Flothmann <[email protected]>
24
 */
25
class StatementRepositoryTest extends \PHPUnit_Framework_TestCase
26
{
27
    /**
28
     * @var \PHPUnit_Framework_MockObject_MockObject|\XApi\Repository\Doctrine\Repository\Mapping\StatementRepository
29
     */
30
    private $mappedStatementRepository;
31
32
    /**
33
     * @var StatementRepository
34
     */
35
    private $statementRepository;
36
37
    protected function setUp()
38
    {
39
        $this->mappedStatementRepository = $this->createMappedStatementRepositoryMock();
40
        $this->statementRepository = new StatementRepository($this->mappedStatementRepository);
41
    }
42
43
    public function testFindStatementById()
44
    {
45
        $statementId = StatementId::fromUuid(Uuid::uuid4());
46
        $this
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<XApi\Repository\D...ng\StatementRepository>.

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...
47
            ->mappedStatementRepository
48
            ->expects($this->once())
49
            ->method('findStatement')
50
            ->with(array('id' => $statementId->getValue()))
51
            ->will($this->returnValue(MappedStatement::fromModel(StatementFixtures::getMinimalStatement())));
52
53
        $this->statementRepository->findStatementById($statementId);
54
    }
55
56
    public function testFindStatementsByCriteria()
57
    {
58
        $verb = VerbFixtures::getTypicalVerb();
59
60
        $this
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<XApi\Repository\D...ng\StatementRepository>.

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...
61
            ->mappedStatementRepository
62
            ->expects($this->once())
63
            ->method('findStatements')
64
            ->with($this->equalTo(array('verb' => $verb->getId()->getValue())))
65
            ->will($this->returnValue(array()));
66
67
        $filter = new StatementsFilter();
68
        $filter->byVerb($verb);
69
        $this->statementRepository->findStatementsBy($filter);
70
    }
71
72 View Code Duplication
    public function testSave()
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...
73
    {
74
        $statement = StatementFixtures::getMinimalStatement();
75
        $this
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<XApi\Repository\D...ng\StatementRepository>.

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...
76
            ->mappedStatementRepository
77
            ->expects($this->once())
78
            ->method('storeStatement')
79
            ->with(
80
                $this->callback(function (MappedStatement $mappedStatement) use ($statement) {
81
                    $expected = MappedStatement::fromModel($statement);
82
                    $actual = clone $mappedStatement;
83
                    $actual->stored = null;
84
85
                    return $expected == $actual;
86
                }),
87
                true
88
            );
89
90
        $this->statementRepository->storeStatement($statement);
91
    }
92
93 View Code Duplication
    public function testSaveWithoutFlush()
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...
94
    {
95
        $statement = StatementFixtures::getMinimalStatement();
96
        $this
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<XApi\Repository\D...ng\StatementRepository>.

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...
97
            ->mappedStatementRepository
98
            ->expects($this->once())
99
            ->method('storeStatement')
100
            ->with(
101
                $this->callback(function (MappedStatement $mappedStatement) use ($statement) {
102
                    $expected = MappedStatement::fromModel($statement);
103
                    $actual = clone $mappedStatement;
104
                    $actual->stored = null;
105
106
                    return $expected == $actual;
107
                }),
108
                false
109
            );
110
111
        $this->statementRepository->storeStatement($statement, false);
112
    }
113
114
    /**
115
     * @return \PHPUnit_Framework_MockObject_MockObject|\XApi\Repository\Doctrine\Repository\Mapping\StatementRepository
116
     */
117
    protected function createMappedStatementRepositoryMock()
118
    {
119
        return $this->getMock('\XApi\Repository\Doctrine\Repository\Mapping\StatementRepository');
120
    }
121
}
122