Failed Conditions
Push — master ( b9670c...4ba57f )
by Zac
16:20 queued 37s
created

TestRepositoryTest::testFindTests()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
namespace Overwatch\TestBundle\Tests\Entity;
4
5
use Overwatch\TestBundle\DataFixtures\ORM\TestFixtures;
6
use Overwatch\TestBundle\DataFixtures\ORM\TestGroupFixtures;
7
use Overwatch\UserBundle\Tests\Base\DatabaseAwareTestCase;
8
9
/**
10
 * TestRepositoryTest
11
 * Functional tests for TestRepository
12
 */
13
class TestRepositoryTest extends DatabaseAwareTestCase
14
{
15
    /**
16
     * @var Overwatch\ResultBundle\Entity\TestResultRepository
17
     */
18
    private $repo;
19
    
20
    public function setUp()
21
    {
22
        parent::setUp();
23
        $this->repo = $this->em->getRepository('OverwatchTestBundle:Test');
24
    }
25
    
26
    public function testFindTests()
27
    {
28
        $results = $this->repo->findTests([
29
            TestFixtures::$tests['test-3']->getName(),
30
            TestGroupFixtures::$groups['group-1']->getName()
31
        ]);
32
        
33
        $this->assertCount(3, $results);
34
        $this->assertCollectionContainsObject(
35
            $this->repo->find(TestFixtures::$tests['test-1']->getId()),
36
            $results
37
        );
38
        $this->assertCollectionContainsObject(
39
            $this->repo->find(TestFixtures::$tests['test-2']->getId()),
40
            $results
41
        );
42
        $this->assertCollectionContainsObject(
43
            $this->repo->find(TestFixtures::$tests['test-3']->getId()),
44
            $results
45
        );
46
    }
47
    
48
    public function testFindTestsEmptySearch()
49
    {
50
        $this->assertEquals($this->repo->findAll(), $this->repo->findTests());
51
    }
52
    
53
    public function testFindTestsCorrectsNonArrayParameter()
54
    {
55
        $this->assertEquals(
56
            $this->repo->findTests([TestFixtures::$tests['test-3']->getName()]),
57
            $this->repo->findTests(TestFixtures::$tests['test-3']->getName())
58
        );
59
    }
60
    
61
    public function testFindByName()
62
    {
63
        $name = TestFixtures::$tests['test-1']->getName();
64
        
65
        $this->assertEquals(
66
            $this->repo->findOneBy(['name' => $name]),
67
            $this->repo->findByName($name)
68
        );
69
    }
70
    
71
    public function testFindByGroupName()
72
    {
73
        $group = TestGroupFixtures::$groups['group-1'];
74
        
75
        $this->assertEquals(
76
            $this->repo->findBy(['group' => $group]),
77
            $this->repo->findByGroupName($group->getName())
78
        );
79
    }
80
    
81
    public function testFindByGroupNameInvalidGroup()
82
    {
83
        $this->assertEquals(
84
            [],
85
            $this->repo->findByGroupName('IfThisGroupExistsIBrokeIt')
86
        );
87
    }
88
}
89