|
1
|
|
|
<?php |
|
2
|
|
|
class DBObjectTest extends PHPUnit_Framework_TestCase |
|
|
|
|
|
|
3
|
|
|
{ |
|
4
|
|
|
public function testContructor() |
|
5
|
|
|
{ |
|
6
|
|
|
$classname = '\Suricate\DBObject'; |
|
7
|
|
|
|
|
8
|
|
|
// Get mock, without the constructor being called |
|
9
|
|
|
$mock = $this->getMockBuilder($classname) |
|
10
|
|
|
->disableOriginalConstructor() |
|
11
|
|
|
->setMethods(array('setRelations')) |
|
12
|
|
|
->getMockForAbstractClass(); |
|
13
|
|
|
|
|
14
|
|
|
// set expectations for constructor calls |
|
15
|
|
|
$mock->expects($this->once()) |
|
16
|
|
|
->method('setRelations'); |
|
17
|
|
|
|
|
18
|
|
|
// now call the constructor |
|
19
|
|
|
$reflectedClass = new ReflectionClass($classname); |
|
20
|
|
|
$constructor = $reflectedClass->getConstructor(); |
|
21
|
|
|
$constructor->invoke($mock); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testUndefinedGet() |
|
25
|
|
|
{ |
|
26
|
|
|
$testDBO = new \Suricate\DBObject(); |
|
27
|
|
|
self::mockProperty($testDBO, 'dbVariables', ['id', 'name', 'last_update']); |
|
28
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
29
|
|
|
|
|
30
|
|
|
$testDBO->undefinedVar; |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testDBProperty() |
|
34
|
|
|
{ |
|
35
|
|
|
$testDBO = new \Suricate\DBObject(); |
|
36
|
|
|
$testDBO->regularProperty = 42; |
|
|
|
|
|
|
37
|
|
|
self::mockProperty($testDBO, 'dbVariables', ['id', 'name', 'not_loaded_var']); |
|
38
|
|
|
self::mockProperty($testDBO, 'dbValues', ['id' => 1, 'name' => 'test name']); |
|
39
|
|
|
$this->assertEquals($testDBO->id, 1); |
|
|
|
|
|
|
40
|
|
|
$this->assertNotEquals($testDBO->name, 'test name edited'); |
|
|
|
|
|
|
41
|
|
|
$this->assertNull($testDBO->not_loaded_var); |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
$this->assertTrue($testDBO->isDBVariable('id')); |
|
44
|
|
|
$this->assertFalse($testDBO->isDBVariable('regularProperty')); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
public static function mockProperty($object, string $propertyName, $value) |
|
49
|
|
|
{ |
|
50
|
|
|
$reflectionClass = new \ReflectionClass($object); |
|
51
|
|
|
|
|
52
|
|
|
$property = $reflectionClass->getProperty($propertyName); |
|
53
|
|
|
$property->setAccessible(true); |
|
54
|
|
|
$property->setValue($object, $value); |
|
55
|
|
|
$property->setAccessible(false); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths