ProphecyTestDoubles   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
c 1
b 0
f 0
dl 0
loc 33
ccs 16
cts 16
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createTestDoubleWithProphecy() 0 13 3
A initialiseProphecyTestDoubles() 0 11 1
1
<?php declare(strict_types=1);
2
3
namespace Zalas\PHPUnit\Doubles\TestCase;
4
5
use PHPUnit\Framework\Assert;
6
use PHPUnit\Framework\TestCase;
7
use Prophecy\Prophecy\ObjectProphecy;
8
use Zalas\PHPUnit\Doubles\Injector\PropertyAccessInjector;
9
use Zalas\PHPUnit\Doubles\PhpDocumentor\ReflectionExtractor;
10
11
trait ProphecyTestDoubles
12
{
13
    abstract protected function prophesize(?string $classOrInterface = null): ObjectProphecy;
14
15
    /**
16
     * @before
17
     */
18 12
    protected function initialiseProphecyTestDoubles(): void
19
    {
20 12
        $doubler = new Doubler(
21 12
            new ReflectionExtractor([TestCase::class, Assert::class]),
22 12
            new PropertyAccessInjector(),
23 12
            function (array $types) {
24
                return $this->createTestDoubleWithProphecy($types);
25 12
            },
26 12
            ObjectProphecy::class
27 12
        );
28 12
        $doubler->createDoubles($this);
29
    }
30
31 12
    private function createTestDoubleWithProphecy(array $types): ObjectProphecy
32
    {
33 12
        $prophecy = $this->prophesize(\array_shift($types));
34
35 12
        foreach ($types as $type) {
36 3
            if (\interface_exists($type)) {
37 3
                $prophecy->willImplement($type);
38
            } else {
39 3
                $prophecy->willExtend($type);
40
            }
41
        }
42
43 12
        return $prophecy;
44
    }
45
}
46