Completed
Push — master ( 73f97f...e73c1d )
by Matthew
03:44
created

GridSourceManagerTest::testConstruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Dtc\GridBundle\Tests\Manager;
4
5
use Doctrine\Common\Annotations\AnnotationReader;
6
use Dtc\GridBundle\Manager\GridSourceManager;
7
use Dtc\GridBundle\Tests\Grid\Source\TestGridSource;
8
use PHPUnit\Framework\TestCase;
9
use Symfony\Component\DependencyInjection\Container;
10
11
class GridSourceManagerTest extends TestCase
12
{
13
    public function testConstruct()
14
    {
15
        $container = new Container();
16
        $container->setParameter('dtc_grid.custom_managers', []);
17
        $gridSourceManager = new GridSourceManager(new AnnotationReader(), '/tmp', true);
18
        self::assertNotNull($gridSourceManager->all());
19
        self::assertInternalType('array', $gridSourceManager->all());
20
        self::assertEmpty($gridSourceManager->all());
21
    }
22
23
    public function testAdd()
24
    {
25
        $container = new Container();
26
        $container->setParameter('dtc_grid.custom_managers', []);
27
        $gridSourceManager = new GridSourceManager(new AnnotationReader(), '/tmp', true);
28
        $gridSource = new TestGridSource();
29
        $gridSourceManager->add('test_grid_source', $gridSource);
30
        self::assertSame($gridSource, $gridSourceManager->get('test_grid_source'));
31
        try {
32
            $gridSourceManager->get('test_grirce');
33
            $this->fail('should not get a gridsource here');
34
        } catch (\Exception $exception) {
35
        }
36
    }
37
38
    public function testGetNegativeCase()
39
    {
40
        $container = new Container();
41
        $container->setParameter('dtc_grid.custom_managers', []);
42
        $gridSourceManager = new GridSourceManager(new AnnotationReader(), '/tmp', true);
43
        $gridSource = new TestGridSource();
44
        try {
45
            $gridSourceManager->get('test_grirce');
46
            $this->fail('should not get a gridsource here');
47
        } catch (\Exception $exception) {
48
        }
49
        $gridSourceManager->add('test_grid_source', $gridSource);
50
        try {
51
            $gridSourceManager->get('test_grirce');
52
            $this->fail('should not get a gridsource here');
53
        } catch (\Exception $exception) {
54
        }
55
        try {
56
            $gridSourceManager->get('');
57
            $this->fail('should not get a gridsource here');
58
        } catch (\Exception $exception) {
59
        }
60
        try {
61
            $gridSourceManager->get(null);
62
            $this->fail('should not get a gridsource here');
63
        } catch (\Exception $exception) {
64
        }
65
    }
66
}
67