Completed
Push — tolerant_search_service ( 5b345d...fd3670 )
by André
18:21
created

PHPUnit5CompatTrait::getMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 10
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A PHPUnit5CompatTrait::createMock() 0 9 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * File containing PHPUnit 5 Forward Compatibility trait.
4
 *
5
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
6
 * @license For full copyright and license information view LICENSE file distributed with this source code.
7
 */
8
namespace eZ\Publish\Core\Base\Tests;
9
10
/**
11
 * Trait for PHPUnit 5 Forward Compatibility, for PHPUnit 4.8 use and up.
12
 */
13
trait PHPUnit5CompatTrait
14
{
15
    /**
16
     * Returns a test double for the specified class.
17
     *
18
     * @internal Forward compatibility with PHPUnit 5/6, so unit tests written on 6.7 & backported to 5.4 can use this.
19
     *
20
     * @param string $originalClassName
21
     *
22
     * @return \PHPUnit_Framework_MockObject_MockObject
23
     */
24
    protected function createMock($originalClassName)
25
    {
26
        return $this->getMockBuilder($originalClassName)
0 ignored issues
show
Bug introduced by
It seems like getMockBuilder() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
27
            ->disableOriginalConstructor()
28
            ->disableOriginalClone()
29
            ->disableArgumentCloning()
30
            //->disallowMockingUnknownTypes() Not defined in PHPunit 4.8
31
            ->getMock();
32
    }
33
}
34