Passed
Push — master ( 1fb483...35eebd )
by Roman
04:31
created

DictionaryTestCase::messageBusMock()

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
nc 1
nop 0
dl 0
loc 6
ccs 0
cts 3
cp 0
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A DictionaryTestCase.php$0 ➔ dispatch() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Tests\Dictionary;
6
7
use Faker\Factory;
0 ignored issues
show
Bug introduced by
The type Faker\Factory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use PHPUnit\Framework\MockObject\Rule\InvocationOrder;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\MockObject\Rule\InvocationOrder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Symfony\Component\Messenger\Envelope;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Messenger\Envelope was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Symfony\Component\Messenger\MessageBusInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Messenger\MessageBusInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
abstract class DictionaryTestCase extends TestCase
14
{
15
    protected function messageBusMock(): MessageBusInterface
16
    {
17
        return new class implements MessageBusInterface {
18
            public function dispatch($message, array $stamps = []): Envelope
19
            {
20
                return new Envelope($message);
21
            }
22
        };
23
    }
24
25
    protected function messageBusMockWithConsecutive(
26
        InvocationOrder $invocationRule,
27
        $message = null
28
    ): MessageBusInterface {
29
        if (null === $message) {
30
            $messageBus = $this->createMock(MessageBusInterface::class);
31
            $messageBus->expects($invocationRule)->method('dispatch');
32
33
            return $messageBus;
34
        }
35
36
        $messageBus = $this->createMock(MessageBusInterface::class);
37
        $messageBus->expects($invocationRule)
38
            ->method('dispatch')
39
            ->withConsecutive(
40
                [
41
                    self::isInstanceOf(get_class($message)),
42
                ]
43
            )
44
            ->willReturn(new Envelope($message));
45
46
        return $messageBus;
47
    }
48
49
    protected function createTempFile(string $ext = '.tmp', array $data = []): string
50
    {
51
        $filePath = sys_get_temp_dir() . uniqid(Factory::create()->name, true) . $ext;
52
        foreach ($data as $item) {
53
            file_put_contents($filePath, $item . PHP_EOL, FILE_APPEND);
54
        }
55
56
        return $filePath;
57
    }
58
}
59