Completed
Push — master ( d1d910...7edec1 )
by amaury
03:34
created

ModelBundle/Repository/StatustRepositoryTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace OpenOrchestra\FunctionalTests\ModelBundle\Repository;
4
5
use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractKernelTestCase;
6
use OpenOrchestra\ModelBundle\Repository\StatusRepository;
7
use OpenOrchestra\Pagination\Configuration\PaginateFinderConfiguration;
8
9
/**
10
 * Test StatusRepositoryTest
11
 *
12
 * @group integrationTest
13
 */
14
class StatusRepositoryTest extends AbstractKernelTestCase
15
{
16
    /**
17
     * @var StatusRepository
18
     */
19
    protected $repository;
20
21
    /**
22
     * Set up the test
23
     */
24
    public function setUp()
25
    {
26
        parent::setUp();
27
28
        static::bootKernel();
29
        $this->repository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status');
30
    }
31
32
    /**
33
     * test find not out of workflow
34
     */
35
    public function testFindNotOutOfWorkflow()
36
    {
37
        $statuses = $this->repository->findNotOutOfWorkflow();
38
        $this->assertCount(5, $statuses);
39
        foreach ($statuses as $status) {
40
            $this->assertFalse($status->isOutOfWorkflow());
41
        }
42
    }
43
44
    /**
45
     * test find other by translation state
46
     */
47
    public function testFindOtherByTranslationState()
48
    {
49
        $statuses = $this->repository->findOtherByTranslationState('toTranslate');
50
        $this->assertCount(0, $statuses);
51
    }
52
53
    /**
54
     * test find one by translation state
55
     */
56
    public function testFindOneByTranslationState()
57
    {
58
        $status = $this->repository->findOneByTranslationState();
59
        $this->assertTrue($status->isTranslationState());
60
    }
61
62
    /**
63
     * test findForPaginate
64
     *
65
     * @param PaginateFinderConfiguration $configuration
66
     * @param int                         $expectedCount
67
     * @param int                         $expectedFilteredCount
68
     *
69
     * @dataProvider providePaginateConfiguration
70
     */
71
    public function testFindForPaginate(PaginateFinderConfiguration $configuration, $expectedCount, $expectedFilteredCount)
72
    {
73
        $this->assertCount($expectedCount, $this->repository->findForPaginate($configuration));
74
    }
75
76
    /**
77
     * test count
78
     */
79
    public function testCountNotOutOfWorkflow()
80
    {
81
        $this->assertSame(5, $this->repository->CountNotOutOfWorkflow());
82
    }
83
84
    /**
85
     * test countWithFilter
86
     *
87
     * @param PaginateFinderConfiguration $configuration
88
     * @param int                         $expectedCount
89
     * @param int                         $expectedFilteredCount
90
     *
91
     * @dataProvider providePaginateConfiguration
92
     */
93
    public function testCountWithFilter(PaginateFinderConfiguration $configuration, $expectedCount, $expectedFilteredCount)
94
    {
95
        $this->assertSame($expectedFilteredCount, $this->repository->countWithFilter($configuration));
96
    }
97
98
    /**
99
     * Provide PaginateFinderConfiguration
100
     *
101
     * @return array
102
     */
103
    public function providePaginateConfiguration()
104
    {
105
        $mapping =  array('label' => 'labels');
106
        $conf1 = PaginateFinderConfiguration::generateFromVariable(null , null, null, $mapping, null);
107
        $conf2 = PaginateFinderConfiguration::generateFromVariable(null , null, null, $mapping, array('label' => 'o', 'language' => 'en'));
108
        $conf3 = PaginateFinderConfiguration::generateFromVariable(null , 2   , 4   , $mapping, array('label' => 'r', 'language' => 'en'));
109
110
        return array(
111
            'No criteria'                => array($conf1, 5, 5),
112
            'Filtering "o"'              => array($conf2, 2, 2),
113
            'Filtering 2 items with "r"' => array($conf3, 0, 2),
114
        );
115
    }
116
117
    /**
118
     * Test remove statuses
119
     */
120 View Code Duplication
    public function testRemoveStatuses()
0 ignored issues
show
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...
121
    {
122
        $dm = static::$kernel->getContainer()->get('object_manager');
123
        $statusPending = $this->repository->findOneByName('pending');
124
        $statusPublished = $this->repository->findOneByName('published');
125
126
        $statusIds = array($statusPending->getId(), $statusPublished->getId());
127
128
        $this->repository->removeStatuses($statusIds);
129
        $this->assertNull($this->repository->findOneByName('pending'));
130
        $this->assertNull($this->repository->findOneByName('published'));
131
132
        $dm->persist(clone $statusPending);
133
        $dm->persist(clone $statusPublished);
134
        $dm->flush();
135
    }
136
 }
137