Completed
Push — develop ( 64da83...d844ac )
by Mathieu
01:46
created

DBCollectionTest::testGetParentIdField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
<?php
2
3
require_once 'stubs/Category.php';
4
5
class DBCollectionTest extends \PHPUnit\Framework\TestCase
6
{
7
    public function testGetTableName()
8
    {
9
        $testName = 'categories';
10
11
        $testCollection = new \Suricate\DBCollection();
12
        self::mockProperty($testCollection, 'tableName', $testName);
13
        $this->assertEquals($testName, $testCollection->getTableName());
14
    }
15
16
    public function testGetItemsType()
17
    {
18
        $testName = Category::class;
19
20
        $testCollection = new \Suricate\DBCollection();
21
        self::mockProperty($testCollection, 'itemsType', $testName);
22
        $this->assertEquals($testName, $testCollection->getItemsType());
23
    }
24
25
    public function testGetDBConfig()
26
    {
27
        $testConfigName = 'my_config';
28
29
        $testCollection = new \Suricate\DBCollection();
30
        self::mockProperty($testCollection, 'DBConfig', $testConfigName);
31
        $this->assertEquals($testConfigName, $testCollection->getDBConfig());
32
    }
33
34
    public function testGetParentIdField()
35
    {
36
        $testName = 'parent_id';
37
38
        $testCollection = new \Suricate\DBCollection();
39
        self::mockProperty($testCollection, 'parentIdField', $testName);
40
        $this->assertEquals($testName, $testCollection->getParentIdField());
41
    }
42
    
43
    public static function mockProperty($object, string $propertyName, $value)
44
    {
45
        $reflectionClass = new \ReflectionClass($object);
46
47
        $property = $reflectionClass->getProperty($propertyName);
48
        $property->setAccessible(true);
49
        $property->setValue($object, $value);
50
        $property->setAccessible(false);
51
    }
52
}