|
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 function testGetParentId() |
|
44
|
|
|
{ |
|
45
|
|
|
$testId = 100; |
|
46
|
|
|
|
|
47
|
|
|
$testCollection = new \Suricate\DBCollection(); |
|
48
|
|
|
$this->assertNull($testCollection->getParentId()); |
|
49
|
|
|
self::mockProperty($testCollection, 'parentId', $testId); |
|
50
|
|
|
$this->assertSame($testId, $testCollection->getParentId()); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testGetSetLazyLoad() |
|
54
|
|
|
{ |
|
55
|
|
|
$testCollection = new \Suricate\DBCollection(); |
|
56
|
|
|
$this->assertFalse($testCollection->getLazyLoad()); |
|
57
|
|
|
$retVal = $testCollection->setLazyLoad(true); |
|
58
|
|
|
$this->assertInstanceOf(\Suricate\DBCollection::class, $retVal); |
|
59
|
|
|
$this->assertTrue($testCollection->getLazyLoad()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
public static function mockProperty($object, string $propertyName, $value) |
|
64
|
|
|
{ |
|
65
|
|
|
$reflectionClass = new \ReflectionClass($object); |
|
66
|
|
|
|
|
67
|
|
|
$property = $reflectionClass->getProperty($propertyName); |
|
68
|
|
|
$property->setAccessible(true); |
|
69
|
|
|
$property->setValue($object, $value); |
|
70
|
|
|
$property->setAccessible(false); |
|
71
|
|
|
} |
|
72
|
|
|
} |