PHPUnitTestDoubles::createTestDoubleWithPhpunit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 11
ccs 9
cts 9
cp 1
crap 1
rs 10
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