Completed
Push — master ( 5b0da2...bacf03 )
by amaury
02:51
created

KeywordRepositoryTest::provideCountWithFilter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace OpenOrchestra\FunctionalTests\ModelBundle\Repository;
4
5
use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractKernelTestCase;
6
use OpenOrchestra\ModelInterface\Repository\KeywordRepositoryInterface;
7
use OpenOrchestra\Pagination\Configuration\PaginateFinderConfiguration;
8
9
/**
10
 * Class KeywordRepositoryTest
11
 *
12
 * @group integrationTest
13
 */
14
class KeywordRepositoryTest extends AbstractKernelTestCase
15
{
16
    /**
17
     * @var KeywordRepositoryInterface
18
     */
19
    protected $repository;
20
21
    /**
22
     * Set up test
23
     */
24
    protected function setUp()
25
    {
26
        parent::setUp();
27
28
        static::bootKernel();
29
        $this->repository = static::$kernel->getContainer()->get('open_orchestra_model.repository.keyword');
30
    }
31
32
    /**
33
     * @param PaginateFinderConfiguration  $configuration
34
     * @param int                          $count
35
     *
36
     * @dataProvider providePaginateAndSearch
37
     */
38
    public function testFindForPaginate(PaginateFinderConfiguration $configuration, $count)
39
    {
40
        $keywords = $this->repository->findForPaginate($configuration);
41
        $this->assertCount($count, $keywords);
42
    }
43
44
    /**
45
     * @return array
46
     */
47
    public function providePaginateAndSearch()
48
    {
49
        $configurationAll = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array());
50
        $configurationLimit = PaginateFinderConfiguration::generateFromVariable(array(), 0, 1, array());
51
        $configurationSearch = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('label' => 'lorem'));
52
        $configurationAllOrder = PaginateFinderConfiguration::generateFromVariable(array('label' => 'desc'), 0, 100, array());
53
54
        return array(
55
            'all' => array($configurationAll, 5),
56
            'limit' => array($configurationLimit, 1),
57
            'search' => array($configurationSearch, 1),
58
            'order' => array($configurationAllOrder, 5),
59
        );
60
    }
61
62
    /**
63
     * test count all keyword
64
     */
65
    public function testCount()
66
    {
67
        $keywords = $this->repository->count();
68
        $this->assertEquals(5, $keywords);
69
    }
70
71
    /**
72
     * @param PaginateFinderConfiguration $configuration
73
     * @param int                         $count
74
     *
75
     * @dataProvider provideCountWithFilter
76
     */
77
    public function testCountWithFilter($configuration, $count)
78
    {
79
        $keywords = $this->repository->countWithFilter($configuration);
80
        $this->assertEquals($count, $keywords);
81
    }
82
83
    /**
84
     * @return array
85
     */
86
    public function provideCountWithFilter()
87
    {
88
        $configurationAll = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array());
89
        $configurationLimit = PaginateFinderConfiguration::generateFromVariable(array(), 0, 1, array());
90
        $configurationSearch = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('label' => 'lorem'));
91
92
        return array(
93
            'all' => array($configurationAll, 5),
94
            'limit' => array($configurationLimit, 5),
95
            'search' => array($configurationSearch, 1),
96
        );
97
    }
98
99
    /**
100
     * Test remove keywords
101
     */
102 View Code Duplication
    public function testRemoveKeywords()
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...
103
    {
104
        $dm = static::$kernel->getContainer()->get('object_manager');
105
        $lorem = $this->repository->findOneByLabel('lorem');
106
        $dolor = $this->repository->findOneByLabel('dolor');
107
108
        $keywordIds = array($lorem->geTId(), $dolor->getId());
109
110
        $this->repository->removeKeywords($keywordIds);
111
        $this->assertNull($this->repository->findOneByLabel('lorem'));
112
        $this->assertNull($this->repository->findOneByLabel('dolor'));
113
114
        $dm->persist(clone $lorem);
115
        $dm->persist(clone $dolor);
116
        $dm->flush();
117
    }
118
}
119