ProfileClientFactoryTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Http\HttplugBundle\Tests\Unit\Collector;
6
7
use Http\Client\HttpClient;
8
use Http\HttplugBundle\ClientFactory\ClientFactory;
9
use Http\HttplugBundle\Collector\Collector;
10
use Http\HttplugBundle\Collector\Formatter;
11
use Http\HttplugBundle\Collector\ProfileClient;
12
use Http\HttplugBundle\Collector\ProfileClientFactory;
13
use PHPUnit\Framework\TestCase;
14
use Symfony\Component\Stopwatch\Stopwatch;
15
16
class ProfileClientFactoryTest extends TestCase
17
{
18
    /**
19
     * @var Collector
20
     */
21
    private $collector;
22
23
    /**
24
     * @var Formatter
25
     */
26
    private $formatter;
27
28
    /**
29
     * @var Stopwatch
30
     */
31
    private $stopwatch;
32
33
    /**
34
     * @var HttpClient
35
     */
36
    private $client;
37
38
    public function setUp(): void
39
    {
40
        $this->collector = $this->getMockBuilder(Collector::class)->disableOriginalConstructor()->getMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockBuilder(\H...onstructor()->getMock() of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Http\HttplugBundle\Collector\Collector> of property $collector.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
41
        $this->formatter = $this->getMockBuilder(Formatter::class)->disableOriginalConstructor()->getMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockBuilder(\H...onstructor()->getMock() of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Http\HttplugBundle\Collector\Formatter> of property $formatter.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
42
        $this->stopwatch = $this->getMockBuilder(Stopwatch::class)->getMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockBuilder(\S...atch::class)->getMock() of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Symfony\Component\Stopwatch\Stopwatch> of property $stopwatch.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
        $this->client = $this->getMockBuilder(HttpClient::class)->getMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockBuilder(\H...ient::class)->getMock() of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Http\Client\HttpClient> of property $client.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
44
    }
45
46
    public function testCreateClientFromClientFactory(): void
47
    {
48
        $factory = $this->getMockBuilder(ClientFactory::class)->getMock();
49
        $factory->method('createClient')->willReturn($this->client);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
51
        $subject = new ProfileClientFactory($factory, $this->collector, $this->formatter, $this->stopwatch);
0 ignored issues
show
Documentation introduced by
$factory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Http\HttplugBundl...ClientFactory>|callable.

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...
52
53
        $this->assertInstanceOf(ProfileClient::class, $subject->createClient());
54
    }
55
56
    public function testCreateClientFromCallable(): void
57
    {
58
        $factory = function ($config) {
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
59
            return $this->client;
60
        };
61
62
        $subject = new ProfileClientFactory($factory, $this->collector, $this->formatter, $this->stopwatch);
63
64
        $this->assertInstanceOf(ProfileClient::class, $subject->createClient());
65
    }
66
}
67