Issues (59)

tests/unit/Message/MessageTest.php (6 issues)

1
<?php
2
3
/**
4
 * This file is part of graze/queue.
5
 *
6
 * Copyright (c) 2015 Nature Delivered Ltd. <https://www.graze.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @license https://github.com/graze/queue/blob/master/LICENSE MIT
12
 *
13
 * @link    https://github.com/graze/queue
14
 */
15
16
namespace Graze\Queue\Message;
17
18
use Graze\DataStructure\Container\ContainerInterface;
19
use Mockery as m;
20
use Mockery\MockInterface;
21
use Graze\Queue\Test\TestCase;
22
23
class MessageTest extends TestCase
24
{
25
    /** @var ContainerInterface|MockInterface */
26
    private $metadata;
27
28
    public function setUp()
29
    {
30
        $this->metadata = m::mock(ContainerInterface::class);
31
    }
32
33
    public function testInterface()
34
    {
35
        $this->assertInstanceOf(
36
            MessageInterface::class,
37
            new Message('foo', $this->metadata, function () {
0 ignored issues
show
It seems like $this->metadata can also be of type Mockery\MockInterface; however, parameter $metadata of Graze\Queue\Message\Message::__construct() does only seem to accept Graze\DataStructure\Container\ContainerInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
            new Message('foo', /** @scrutinizer ignore-type */ $this->metadata, function () {
Loading history...
38
            })
39
        );
40
    }
41
42
    public function testGetBody()
43
    {
44
        $message = new Message('foo', $this->metadata, function () {
0 ignored issues
show
It seems like $this->metadata can also be of type Mockery\MockInterface; however, parameter $metadata of Graze\Queue\Message\Message::__construct() does only seem to accept Graze\DataStructure\Container\ContainerInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
        $message = new Message('foo', /** @scrutinizer ignore-type */ $this->metadata, function () {
Loading history...
45
        });
46
47
        assertThat($message->getBody(), is(identicalTo('foo')));
48
    }
49
50
    public function testGetMetadata()
51
    {
52
        $message = new Message('foo', $this->metadata, function () {
0 ignored issues
show
It seems like $this->metadata can also be of type Mockery\MockInterface; however, parameter $metadata of Graze\Queue\Message\Message::__construct() does only seem to accept Graze\DataStructure\Container\ContainerInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

52
        $message = new Message('foo', /** @scrutinizer ignore-type */ $this->metadata, function () {
Loading history...
53
        });
54
55
        assertThat($message->getMetadata(), is(identicalTo($this->metadata)));
56
    }
57
58
    public function testIsValidIsFalse()
59
    {
60
        $message = new Message('foo', $this->metadata, function () {
0 ignored issues
show
It seems like $this->metadata can also be of type Mockery\MockInterface; however, parameter $metadata of Graze\Queue\Message\Message::__construct() does only seem to accept Graze\DataStructure\Container\ContainerInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

60
        $message = new Message('foo', /** @scrutinizer ignore-type */ $this->metadata, function () {
Loading history...
61
            return false;
62
        });
63
64
        assertThat($message->isValid(), is(identicalTo(false)));
65
    }
66
67
    public function testIsValidIsTrue()
68
    {
69
        $message = new Message('foo', $this->metadata, function () {
0 ignored issues
show
It seems like $this->metadata can also be of type Mockery\MockInterface; however, parameter $metadata of Graze\Queue\Message\Message::__construct() does only seem to accept Graze\DataStructure\Container\ContainerInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

69
        $message = new Message('foo', /** @scrutinizer ignore-type */ $this->metadata, function () {
Loading history...
70
            return true;
71
        });
72
73
        assertThat($message->isValid(), is(identicalTo(true)));
74
    }
75
76
    public function testIsValidIsCalledWithMessage()
77
    {
78
        $seen = null;
79
        $message = new Message('foo', $this->metadata, function ($msg) use (&$seen) {
0 ignored issues
show
It seems like $this->metadata can also be of type Mockery\MockInterface; however, parameter $metadata of Graze\Queue\Message\Message::__construct() does only seem to accept Graze\DataStructure\Container\ContainerInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

79
        $message = new Message('foo', /** @scrutinizer ignore-type */ $this->metadata, function ($msg) use (&$seen) {
Loading history...
80
            $seen = $msg;
81
        });
82
83
        $message->isValid();
84
85
        assertThat($seen, is(identicalTo($message)));
86
    }
87
}
88