Completed
Push — master ( 463d73...47ba96 )
by Gerrit
02:04
created

EntityArgumentTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 32
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 2
dl 32
loc 32
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A shouldResolveEntityArgument() 24 24 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
 * Copyright (C) 2017  Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 * @license GPL-3.0
8
 * @author Gerrit Addiks <[email protected]>
9
 */
10
11
namespace Addiks\SymfonyGenerics\Tests\Unit\Arguments;
12
13
use PHPUnit\Framework\TestCase;
14
use Addiks\SymfonyGenerics\Arguments\EntityArgument;
15
use Addiks\SymfonyGenerics\Arguments\Argument;
16
use stdClass;
17
use Doctrine\Common\Persistence\ObjectManager;
18
19 View Code Duplication
final class EntityArgumentTest extends TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
20
{
21
22
    /**
23
     * @test
24
     */
25
    public function shouldResolveEntityArgument()
26
    {
27
        /** @var ObjectManager $objectManager */
28
        $objectManager = $this->createMock(ObjectManager::class);
29
30
        /** @var Argument $id */
31
        $id = $this->createMock(Argument::class);
32
        $id->method("resolve")->willReturn("some-id");
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\SymfonyGenerics\Arguments\Argument>.

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...
33
34
        /** @var object $expectedEntity */
35
        $expectedEntity = new stdClass();
36
37
        $objectManager->expects($this->once())->method('find')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\Common\Persistence\ObjectManager>.

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...
38
            $this->identicalTo("some-entity-class"),
39
            $this->identicalTo("some-id")
40
        )->willReturn($expectedEntity);
41
42
        $argument = new EntityArgument($objectManager, "some-entity-class", $id);
43
44
        /** @var object $actualEntity */
45
        $actualEntity = $argument->resolve();
46
47
        $this->assertSame($actualEntity, $expectedEntity);
48
    }
49
50
}
51