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

TestResultRepositoryTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 45
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testGetResults() 0 10 1
A testGetResultsPagination() 0 12 1
A testGetResultsOlderThan() 0 7 1
1
<?php
2
3
namespace Overwatch\ResultBundle\Tests\Entity;
4
5
use Overwatch\ResultBundle\DataFixtures\ORM\TestResultFixtures;
6
use Overwatch\TestBundle\DataFixtures\ORM\TestFixtures;
7
use Overwatch\UserBundle\Tests\Base\DatabaseAwareTestCase;
8
9
/**
10
 * TestResultRepository
11
 * Functional tests for TestResultRepository
12
 */
13
class TestResultRepositoryTest 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('OverwatchResultBundle:TestResult');
24
    }
25
26
    public function testGetResults()
27
    {
28
        $results = $this->repo->getResults(['test' => TestFixtures::$tests['test-1']]);
29
30
        $this->assertInternalType('array', $results);
31
        $this->assertCount(3, $results);
32
        $this->assertCollectionContainsObject(TestResultFixtures::$results['result-1'], $results);
33
        $this->assertCollectionContainsObject(TestResultFixtures::$results['result-2'], $results);
34
        $this->assertCollectionContainsObject(TestResultFixtures::$results['result-3'], $results);
35
    }
36
37
    public function testGetResultsPagination()
38
    {
39
        $results = $this->repo->getResults(['test' => TestFixtures::$tests['test-1']], 1);
40
        $this->assertInternalType('array', $results);
41
        $this->assertCount(1, $results);
42
        $this->assertCollectionContainsObject(TestResultFixtures::$results['result-3'], $results);
43
44
        $results = $this->repo->getResults(['test' => TestFixtures::$tests['test-1']], 1, 2);
45
        $this->assertInternalType('array', $results);
46
        $this->assertCount(1, $results);
47
        $this->assertCollectionContainsObject(TestResultFixtures::$results['result-2'], $results);
48
    }
49
50
    public function testGetResultsOlderThan()
51
    {
52
        $cutoff = new \DateTime('-90 minutes');
53
        $results = $this->repo->getResultsOlderThan($cutoff);
54
        $this->assertEquals(TestResultFixtures::$results['result-1']->getId(), $results->next()[0]->getId());
55
        $this->assertFalse($results->next());
56
    }
57
}
58