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
|
|
|
} |