Completed
Push — master ( 32ae80...bc59dd )
by Arnold
03:16
created

SafeMocksTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 28
ccs 8
cts 8
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A createMock() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jasny\PHPUnit;
6
7
use PHPUnit\Framework\MockObject\MockBuilder;
8
use PHPUnit\Framework\MockObject\MockObject;
9
10
/**
11
 * Overwrite `createMock` method to disable auto-return value generation.
12
 */
13
trait SafeMocksTrait
14
{
15
    /**
16
     * Returns a builder object to create mock objects using a fluent interface.
17
     *
18
     * @param string $className
19
     * @return MockBuilder
20
     */
21
    abstract public function getMockBuilder($className): MockBuilder;
22
23
    /**
24
     * Returns a mock object for the specified class.
25
     *
26
     * @param string|string[] $originalClassName
27
     *
28
     * @psalm-template RealInstanceType of object
29
     * @psalm-param class-string<RealInstanceType>|string[] $originalClassName
30
     * @psalm-return MockObject&RealInstanceType
31
     */
32 1
    protected function createMock($originalClassName): MockObject
33
    {
34 1
        return $this->getMockBuilder($originalClassName)
0 ignored issues
show
Bug introduced by
It seems like $originalClassName can also be of type string[]; however, parameter $className of Jasny\PHPUnit\SafeMocksTrait::getMockBuilder() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
        return $this->getMockBuilder(/** @scrutinizer ignore-type */ $originalClassName)
Loading history...
35 1
            ->disableOriginalConstructor()
36 1
            ->disableOriginalClone()
37 1
            ->disableArgumentCloning()
38 1
            ->disallowMockingUnknownTypes()
39 1
            ->disableAutoReturnValueGeneration()
40 1
            ->getMock();
41
    }
42
}
43