Passed
Pull Request — master (#30)
by Alexander
02:06
created

CallbackDependencyTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testPlainClosure() 0 7 1
testScopeWithObject() 0 15 ?
A createDependency() 0 5 1
A hp$0 ➔ testScopeWithObject() 0 15 1
1
<?php
2
namespace Yiisoft\CacheOld\Tests\Dependency;
3
4
use Yiisoft\CacheOld\Dependency\CallbackDependency;
0 ignored issues
show
Bug introduced by
The type Yiisoft\CacheOld\Dependency\CallbackDependency was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
use Yiisoft\CacheOld\Dependency\Dependency;
0 ignored issues
show
Bug introduced by
The type Yiisoft\CacheOld\Dependency\Dependency was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
class CallbackDependencyTest extends DependencyTestCase
8
{
9
    private function createDependency(callable $callback, $dependencyData): Dependency
10
    {
11
        $dependency = new CallbackDependency($callback);
12
        $this->setInaccessibleProperty($dependency, 'data', $dependencyData);
13
        return $dependency;
14
    }
15
16
    public function testPlainClosure(): void
17
    {
18
        $dependency = $this->createDependency(static function () {
19
            return true;
20
        }, true);
21
22
        $this->assertDependencyNotChanged($dependency);
23
    }
24
25
    public function testScopeWithObject(): void
26
    {
27
        $dataObject = new class {
28
            public $value = 42;
29
        };
30
31
        $dependency = $this->createDependency(static function () use ($dataObject) {
32
            return $dataObject->value;
33
        }, 42);
34
35
        $this->assertDependencyNotChanged($dependency);
36
37
        $dataObject->value = 13;
38
39
        $this->assertDependencyChanged($dependency);
40
    }
41
}
42