ProviderInvokerTest::testOnTerminate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
use Beberlei\Metrics\Collector\Collector;
4
use Flagbit\Bundle\MetricsBundle\Collector\CollectorCollection;
5
use Flagbit\Bundle\MetricsBundle\Collector\Factory\CollectorCollectionFactory;
6
use Flagbit\Bundle\MetricsBundle\Provider\ProviderInterface;
7
use Flagbit\Bundle\MetricsBundle\Provider\ProviderInvoker;
8
use PHPUnit\Framework\TestCase;
9
10
class ProviderInvokerTest extends TestCase
11
{
12
    /**
13
     * @var \PHPUnit_Framework_MockObject_MockObject
14
     */
15
    private $factory;
16
17
    /**
18
     * @var ProviderInvoker
19
     */
20
    private $metricsProvider;
21
22
    protected function setUp()
23
    {
24
        $this->factory = $this->createMock(CollectorCollectionFactory::class);
25
        $this->metricsProvider = new ProviderInvoker($this->factory);
0 ignored issues
show
Documentation introduced by
$this->factory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Flagbit\Bundle\Me...ectorCollectionFactory>.

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...
26
    }
27
28
    public function testAddMetricsProvider()
29
    {
30
        $collector = $this->createMock(Collector::class);
31
        $provider = $this->createMock(ProviderInterface::class);
32
33
        $this->getCollectorCollection($collector);
34
35
        $this->metricsProvider->addMetricsProvider($provider, [$collector]);
0 ignored issues
show
Documentation introduced by
$provider is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Flagbit\Bundle\Me...ider\ProviderInterface>.

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...
Documentation introduced by
array($collector) is of type array<integer,object<PHP...kObject\\MockObject>"}>, but the function expects a array<integer,object<Beb...s\Collector\Collector>>.

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...
36
    }
37
38 View Code Duplication
    public function testCollectMetrics()
0 ignored issues
show
Duplication introduced by
This method 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...
39
    {
40
        $collector = $this->createMock(Collector::class);
41
        $provider = $this->createMock(ProviderInterface::class);
42
        $collectorCollection = $this->getCollectorCollection($collector);
43
44
        $provider
45
            ->expects($this->once())
46
            ->method('collectMetrics')
47
            ->with($collectorCollection);
48
49
        $this->metricsProvider->addMetricsProvider($provider, [$collector]);
0 ignored issues
show
Documentation introduced by
$provider is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Flagbit\Bundle\Me...ider\ProviderInterface>.

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...
Documentation introduced by
array($collector) is of type array<integer,object<PHP...kObject\\MockObject>"}>, but the function expects a array<integer,object<Beb...s\Collector\Collector>>.

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...
50
        $this->metricsProvider->collectMetrics();
51
    }
52
53 View Code Duplication
    public function testOnTerminate()
0 ignored issues
show
Duplication introduced by
This method 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...
54
    {
55
        $collector = $this->createMock(Collector::class);
56
        $provider = $this->createMock(ProviderInterface::class);
57
        $collectorCollection = $this->getCollectorCollection($collector);
58
59
        $provider
60
            ->expects($this->once())
61
            ->method('collectMetrics')
62
            ->with($collectorCollection);
63
64
        $this->metricsProvider->addMetricsProvider($provider, [$collector]);
0 ignored issues
show
Documentation introduced by
$provider is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Flagbit\Bundle\Me...ider\ProviderInterface>.

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...
Documentation introduced by
array($collector) is of type array<integer,object<PHP...kObject\\MockObject>"}>, but the function expects a array<integer,object<Beb...s\Collector\Collector>>.

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...
65
        $this->metricsProvider->collectMetrics();
66
    }
67
68
    private function getCollectorCollection($collector)
69
    {
70
        $collectorCollection = $this->createMock(CollectorCollection::class);
71
72
        $this->factory
73
            ->expects($this->once())
74
            ->method('create')
75
            ->willReturn($collectorCollection);
76
77
        $collectorCollection
78
            ->expects($this->once())
79
            ->method('addCollector')
80
            ->with($collector);
81
82
        return $collectorCollection;
83
    }
84
}
85