Completed
Push — master ( 07e238...0f15f1 )
by Pavel
09:14
created

CountControllerTest::testCounting()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 20
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\Tests\Fixtures\AbcClass;
12
use ScayTrase\Api\Cruds\Tests\Unit\AbstractControllerTest;
13
use Symfony\Component\EventDispatcher\Event;
14
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
15
16
class CountControllerTest extends \PHPUnit_Framework_TestCase
17
{
18
    public function testCounting()
19
    {
20
        $collection = new ArrayCollection();
21
22
        $f1 = $this->createFixture(1, 'b', null);
23
        $f2 = $this->createFixture(2, '5', '10');
24
        $f3 = $this->createFixture(3, 5, null);
25
        $f4 = $this->createFixture(4, null, 10);
26
        $collection->add($f1);
27
        $collection->add($f2);
28
        $collection->add($f3);
29
        $collection->add($f4);
30
31
        $configuration = new EntityCriteriaConfigurator(new PublicPropertyMapper());
32
33
        $evmProphecy = $this->prophesize(EventDispatcherInterface::class);
34
        $evmProphecy->dispatch(CrudEvents::COUNT, Argument::type(Event::class))->shouldBeCalled();
35
        /** @var EventDispatcherInterface $evm */
36
        $evm = $evmProphecy->reveal();
37
38
        $controller = new CountController(AbcClass::class, $collection, $configuration, $evm);
39
40
        self::assertSame(1, $controller->countAction(['b' => 5]));
41
        self::assertSame(1, $controller->countAction(['b' => '5']));
42
        self::assertSame(2, $controller->countAction(['c' => null]));
43
        self::assertSame(4, $controller->countAction(['a' => [1, 2, 3, 4]]));
44
        self::assertSame(3, $controller->countAction(['a' => [1, 2, 4]]));
45
46
    }
47
48 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...
49
    {
50
        $entity    = new AbcClass();
51
        $entity->a = $a;
52
        $entity->b = $b;
53
        $entity->c = $c;
54
55
        return $entity;
56
    }
57
}
58
59