Completed
Pull Request — master (#11)
by
unknown
04:13
created

StateDocumentRepositoryTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 33.78 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 25
loc 74
c 0
b 0
f 0
wmc 6
lcom 1
cbo 7
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A tearDown() 0 4 1
A testFetchingNonExistingStateDocumentThrowsException() 0 9 1
A testCreatedStateDocumentCanBeRetrievedByOriginal() 13 13 1
A testDeletedStatementIsDeleted() 12 12 1
A getStateDocument() 0 4 1
createStateDocumentRepositoryInterface() 0 1 ?
cleanDatabase() 0 1 ?

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\DataFixtures\ActivityFixtures;
15
use Xabbuh\XApi\DataFixtures\ActorFixtures;
16
use Xabbuh\XApi\DataFixtures\DocumentFixtures;
17
use Xabbuh\XApi\Model\StateDocument;
18
use Xabbuh\XApi\Model\StateDocumentsFilter;
19
use XApi\Repository\Api\StateDocumentRepositoryInterface;
20
21
/**
22
 * @author Jérôme Parmentier <[email protected]>
23
 */
24
abstract class StateDocumentRepositoryTest extends \PHPUnit_Framework_TestCase
25
{
26
    /**
27
     * @var StateDocumentRepositoryInterface
28
     */
29
    private $stateDocumentRepository;
30
31
    protected function setUp()
32
    {
33
        $this->stateDocumentRepository = $this->createStateDocumentRepositoryInterface();
34
        $this->cleanDatabase();
35
    }
36
37
    protected function tearDown()
38
    {
39
        $this->cleanDatabase();
40
    }
41
42
    /**
43
     * @expectedException \Xabbuh\XApi\Common\Exception\NotFoundException
44
     */
45
    public function testFetchingNonExistingStateDocumentThrowsException()
46
    {
47
        $criteria = new StateDocumentsFilter();
48
        $criteria
49
            ->byActivity(ActivityFixtures::getIdActivity())
50
            ->byAgent(ActorFixtures::getTypicalAgent());
51
52
        $this->stateDocumentRepository->find('unknown-state-id', $criteria);
53
    }
54
55
    /**
56
     * @dataProvider getStateDocument
57
     */
58 View Code Duplication
    public function testCreatedStateDocumentCanBeRetrievedByOriginal(StateDocument $stateDocument)
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...
59
    {
60
        $this->stateDocumentRepository->save($stateDocument);
61
62
        $criteria = new StateDocumentsFilter();
63
        $criteria
64
            ->byActivity($stateDocument->getState()->getActivity())
65
            ->byAgent($stateDocument->getState()->getActor());
66
67
        $fetchedStateDocument = $this->stateDocumentRepository->find($stateDocument->getState()->getStateId(), $criteria);
68
69
        $this->assertTrue($stateDocument->equals($fetchedStateDocument));
0 ignored issues
show
Bug introduced by
The method equals() does not seem to exist on object<Xabbuh\XApi\Model\StateDocument>.

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...
70
    }
71
72
    /**
73
     * @dataProvider getStateDocument
74
     * @expectedException \Xabbuh\XApi\Common\Exception\NotFoundException
75
     */
76 View Code Duplication
    public function testDeletedStatementIsDeleted(StateDocument $stateDocument)
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...
77
    {
78
        $this->stateDocumentRepository->save($stateDocument);
79
        $this->stateDocumentRepository->delete($stateDocument);
80
81
        $criteria = new StateDocumentsFilter();
82
        $criteria
83
            ->byActivity($stateDocument->getState()->getActivity())
84
            ->byAgent($stateDocument->getState()->getActor());
85
86
        $this->stateDocumentRepository->find($stateDocument->getState()->getStateId(), $criteria);
87
    }
88
89
    public function getStateDocument()
90
    {
91
        return array(DocumentFixtures::getStateDocument());
92
    }
93
94
    abstract protected function createStateDocumentRepositoryInterface();
95
96
    abstract protected function cleanDatabase();
97
}
98