BaseRepositoryTest::getMockObject()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 1
c 0
b 0
f 0
1
<?php
2
3
namespace Bludata\Lumen\Tests\Repositories;
4
5
use Bludata\Lumen\Tests\BaseTest;
6
7
abstract class BaseRepositoryTest extends BaseTest
8
{
9
    abstract public function getRepository();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
10
11
    abstract public function getMockObject(array $except = []);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
12
13
    public function getFlushedMockObject(array $except = [])
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
14
    {
15
        $entity = $this->getMockObject($except);
16
17
        $this->getRepository()
18
             ->save($entity)
19
             ->flush($entity);
20
21
        return $entity;
22
    }
23
24
    public function getMockArray(array $except = [])
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
25
    {
26
        return $this->getMockObject($except)->toArray();
27
    }
28
29
    public function getFlushedMockArray(array $except = [])
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
30
    {
31
        return $this->getFlushedMockObject($except)->toArray();
32
    }
33
34 View Code Duplication
    public function testFindAll()
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...
35
    {
36
        $entity = $this->getFlushedMockObject();
0 ignored issues
show
Unused Code introduced by
$entity is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
37
38
        $findAll = $this->getRepository()->findAll()->getResult();
39
40
        $this->assertGreaterThan(0, count($findAll));
41
        $this->assertInstanceOf($this->getRepository()->getEntityName(), $findAll[0]);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 86 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
42
    }
43
44
    public function testFindBy()
45
    {
46
        $entity = $this->getFlushedMockObject();
47
48
        $repository = $this->getRepository();
49
50
        $findBy = $repository->findBy(['id' => $entity->getId()]);
51
52
        $this->assertGreaterThan(0, count($findBy));
53
        $this->assertInstanceOf($repository->getEntityName(), $findBy[0]);
54
    }
55
56 View Code Duplication
    public function testFindOneBy()
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...
57
    {
58
        $entity = $this->getFlushedMockObject();
59
60
        $repository = $this->getRepository();
61
62
        $findOneBy = $repository->findOneBy(['id' => $entity->getId()]);
63
64
        $this->assertInstanceOf($repository->getEntityName(), $findOneBy);
65
        $this->assertEquals($entity->getId(), $findOneBy->getId());
66
    }
67
68 View Code Duplication
    public function testFind()
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...
69
    {
70
        $entity = $this->getFlushedMockObject();
71
72
        $repository = $this->getRepository();
73
74
        $find = $repository->find($entity->getId());
75
76
        $this->assertInstanceOf($repository->getEntityName(), $find);
77
        $this->assertEquals($entity->getId(), $find->getId());
78
    }
79
80
    /**
81
     * @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 86 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
82
     */
83
    public function testRemove()
84
    {
85
        $repository = $this->getRepository();
86
87
        $entity = $this->getFlushedMockObject();
88
89
        $repository->remove($entity)
90
                   ->flush($entity);
91
92
        $repository->find($entity->getId());
93
    }
94
}
95