Completed
Push — master ( 0f15f1...06dce9 )
by Pavel
09:44
created

CountControllerTest::testCounting()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 22
nc 1
nop 0
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Tests\Unit\Controller;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Prophecy\Argument;
7
use ScayTrase\Api\Cruds\Controller\CountController;
8
use ScayTrase\Api\Cruds\Criteria\EntityCriteriaConfigurator;
9
use ScayTrase\Api\Cruds\Event\CrudEvents;
10
use ScayTrase\Api\Cruds\PublicPropertyMapper;
11
use ScayTrase\Api\Cruds\ReferenceProviderInterface;
12
use ScayTrase\Api\Cruds\Tests\Fixtures\AbcClass;
13
use ScayTrase\Api\Cruds\Tests\Unit\AbstractControllerTest;
14
use Symfony\Component\EventDispatcher\Event;
15
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
16
17
class CountControllerTest extends \PHPUnit_Framework_TestCase
18
{
19
    public function testCounting()
20
    {
21
        $collection = new ArrayCollection();
22
23
        $f1 = $this->createFixture(1, 'b', null);
24
        $f2 = $this->createFixture(2, '5', '10');
25
        $f3 = $this->createFixture(3, 5, null);
26
        $f4 = $this->createFixture(4, null, 10);
27
        $collection->add($f1);
28
        $collection->add($f2);
29
        $collection->add($f3);
30
        $collection->add($f4);
31
32
        $configuration = new EntityCriteriaConfigurator(
33
            new PublicPropertyMapper(),
34
            $this->getReferenceProvider()
0 ignored issues
show
Bug introduced by
It seems like $this->getReferenceProvider() targeting ScayTrase\Api\Cruds\Test...:getReferenceProvider() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, ScayTrase\Api\Cruds\Crit...igurator::__construct() does only seem to accept object<ScayTrase\Api\Cru...renceProviderInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
35
        );
36
37
        $evmProphecy = $this->prophesize(EventDispatcherInterface::class);
38
        $evmProphecy->dispatch(CrudEvents::COUNT, Argument::type(Event::class))->shouldBeCalled();
39
        /** @var EventDispatcherInterface $evm */
40
        $evm = $evmProphecy->reveal();
41
42
        $controller = new CountController(AbcClass::class, $collection, $configuration, $evm);
43
44
        self::assertSame(1, $controller->countAction(['b' => 5]));
45
        self::assertSame(1, $controller->countAction(['b' => '5']));
46
        self::assertSame(2, $controller->countAction(['c' => null]));
47
        self::assertSame(4, $controller->countAction(['a' => [1, 2, 3, 4]]));
48
        self::assertSame(3, $controller->countAction(['a' => [1, 2, 4]]));
49
    }
50
51 View Code Duplication
    private function createFixture($a, $b, $c)
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...
52
    {
53
        $entity    = new AbcClass();
54
        $entity->a = $a;
55
        $entity->b = $b;
56
        $entity->c = $c;
57
58
        return $entity;
59
    }
60
61
    /**
62
     * @return ReferenceProviderInterface|\PHPUnit_Framework_MockObject_MockObject
63
     */
64
    private function getReferenceProvider()
65
    {
66
        $mock = $this->getMockBuilder(ReferenceProviderInterface::class)->getMock();
67
68
        $mock->method('getEntityReference')->willReturnArgument(2);
69
70
        return $mock;
71
    }
72
}
73
74