Completed
Push — master ( 3f30e7...37b632 )
by Dmitry
08:21
created

ExecutorTest::testBasics()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 9.36
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Test;
4
5
use Basis\Context;
6
use Basis\Executor;
7
use Basis\Test;
8
9
class ExecutorTest extends Test
10
{
11
    public function testDispatcherProcessingTrigger()
12
    {
13
        $note = $this->create('note', []);
14
        $result = $this->get(Executor::class)->dispatch('actor', ['note' => $note->id]);
15
        $this->assertNotNull($result);
16
    }
17
    public function testContext()
18
    {
19
        $note = $this->create('note', []);
20
        $this->send('actor', ['note' => $note->id]);
21
        $this->get(Executor::class)->process();
22
        $this->assertSame($note->message, '');
23
24
        $this->actAs(1);
25
        $this->send('actor', ['note' => $note->id]);
26
27
        $this->actAs(2);
28
        $this->get(Executor::class)->process();
29
30
        $this->assertSame($note->message, '1');
31
        $this->assertSame($this->get(Context::class)->getPerson(), 2);
32
    }
33
34
    public function testBasics()
35
    {
36
        $note = $this->create('note', ['message' => 5]);
37
        $this->actAs(1);
38
        $this->send('increment', ['note' => $note->id]);
39
        $this->assertEquals($note->message, 5);
40
41
        $this->assertCount(1, $this->find('job_queue'));
0 ignored issues
show
Documentation introduced by
$this->find('job_queue') is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

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...
42
        $request = $this->findOne('job_queue');
0 ignored issues
show
Unused Code introduced by
$request is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
43
44
        $this->get(Executor::class)->process();
45
46
        $this->assertCount(0, $this->find('job_queue'));
0 ignored issues
show
Documentation introduced by
$this->find('job_queue') is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

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...
47
        $this->assertCount(0, $this->find('job_result'));
0 ignored issues
show
Documentation introduced by
$this->find('job_result') is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

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...
48
        $this->assertEquals($note->message, 6);
49
50
        $request = $this->get(Executor::class)->request([
51
            'job' => 'increment',
52
            'recipient' => 'test',
53
            'params' => [
54
                'note' => $note->id,
55
            ],
56
        ]);
57
58
        $this->assertEquals($request->recipient, 'test');
59
        $this->assertCount(1, $this->find('job_queue'));
0 ignored issues
show
Documentation introduced by
$this->find('job_queue') is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

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...
60
        $this->assertCount(0, $this->find('job_result'));
0 ignored issues
show
Documentation introduced by
$this->find('job_result') is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

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...
61
62
        $this->get(Executor::class)->process();
63
        $this->assertCount(0, $this->find('job_queue'));
0 ignored issues
show
Documentation introduced by
$this->find('job_queue') is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

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...
64
        $this->assertCount(1, $this->find('job_result'));
0 ignored issues
show
Documentation introduced by
$this->find('job_result') is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

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
66
        $result = $this->get(Executor::class)->result($request->hash);
67
        $this->assertEquals($result->note->message, 7);
68
    }
69
}
70