SocketFactoryTest::testCreateClient()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Http\HttplugBundle\Tests\Unit\ClientFactory;
6
7
use Http\Client\Socket\Client;
8
use Http\HttplugBundle\ClientFactory\SocketFactory;
9
use Http\Message\MessageFactory;
10
use PHPUnit\Framework\TestCase;
11
12
/**
13
 * @author Tobias Nyholm <[email protected]>
14
 */
15 View Code Duplication
class SocketFactoryTest extends TestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
{
17
    public function testCreateClient(): void
18
    {
19
        if (!class_exists(Client::class)) {
20
            $this->markTestSkipped('Socket client is not installed');
21
        }
22
23
        $factory = new SocketFactory($this->getMockBuilder(MessageFactory::class)->getMock());
0 ignored issues
show
Documentation introduced by
$this->getMockBuilder(\H...tory::class)->getMock() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Http\Message\MessageFactory>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
24
        $client = $factory->createClient();
25
26
        $this->assertInstanceOf(Client::class, $client);
27
    }
28
}
29