PHPUnitTestDoubles   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 16
c 1
b 0
f 0
dl 0
loc 31
ccs 18
cts 18
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createTestDoubleWithPhpunit() 0 11 1
A initialisePHPUnitTestDoubles() 0 11 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Zalas\PHPUnit\Doubles\TestCase;
5
6
use PHPUnit\Framework\Assert;
7
use PHPUnit\Framework\MockObject\MockBuilder;
8
use PHPUnit\Framework\MockObject\MockObject;
9
use PHPUnit\Framework\TestCase;
10
use Zalas\PHPUnit\Doubles\Injector\PropertyAccessInjector;
11
use Zalas\PHPUnit\Doubles\PhpDocumentor\ReflectionExtractor;
12
13
trait PHPUnitTestDoubles
14
{
15
    abstract public function getMockBuilder(string $className): MockBuilder;
16
17
    /**
18
     * @before
19
     */
20 6
    protected function initialisePHPUnitTestDoubles(): void
21
    {
22 6
        $doubler = new Doubler(
23 6
            new ReflectionExtractor([TestCase::class, Assert::class]),
24 6
            new PropertyAccessInjector(),
25 6
            function (array $types) {
26
                return $this->createTestDoubleWithPhpunit($types);
27 6
            },
28 6
            MockObject::class
29 6
        );
30 6
        $doubler->createDoubles($this);
31
    }
32
33 6
    private function createTestDoubleWithPhpunit(array $types): MockObject
34
    {
35 6
        $normalisedTypes = \array_shift($types) ?? \stdClass::class;
36
37 6
        return $this->getMockBuilder($normalisedTypes)
38 6
            ->disableOriginalConstructor()
39 6
            ->disableOriginalClone()
40 6
            ->disableArgumentCloning()
41 6
            ->disableProxyingToOriginalMethods()
42 6
            ->disallowMockingUnknownTypes()
43 6
            ->getMock();
44
    }
45
}
46