Completed
Push — master ( 191869...afc708 )
by Frank
08:08
created

AbstractCommandTest::ensureSendResponseHandlingForMessageResponseWithUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * T3Bot.
4
 *
5
 * @author Frank Nägler <[email protected]>
6
 *
7
 * @link http://www.t3bot.de
8
 * @link http://wiki.typo3.org/T3Bot
9
 */
10
namespace T3Bot\Tests\Unit\Commands;
11
12
use Prophecy\Argument;
13
use Slack\Payload;
14
use Slack\RealTimeClient;
15
use T3Bot\Commands\AbstractCommand;
16
use T3Bot\Slack\Message;
17
use T3Bot\Tests\Unit\BaseCommandTestCase;
18
19
/**
20
 * Class AbstractCommandTest.
21
 */
22
23
/** @noinspection LongInheritanceChainInspection */
24
class AbstractCommandTest extends BaseCommandTestCase
25
{
26
    /**
27
     * @test
28
     */
29
    public function ensureSendResponseHandlingForStringResponse()
30
    {
31
        /** @var Payload $payload */
32
        $payload = new Payload([
33
            'text' => 'test message',
34
            'channel' => '#fntest',
35
        ]);
36
        /** @var RealTimeClient $client */
37
        $client = $this->prophesize(RealTimeClient::class);
38
39
        $client->apiCall('chat.postMessage', [
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<React\Promise\PromiseInterface>.

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...
40
            'unfurl_links' => false,
41
            'unfurl_media' => false,
42
            'parse' => 'none',
43
            'text' => 'this is a test string',
44
            'channel' => '#fntest',
45
            'as_user' => true,
46
        ])->willReturn(true);
47
48
        /** @var AbstractCommand $stub */
49
        $stub = $this->getMockForAbstractClass(AbstractCommand::class, [$payload, $client->reveal()]);
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Slack\RealTimeClient>.

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
        $stub->sendResponse('this is a test string');
51
    }
52
53
    /**
54
     * @test
55
     */
56
    public function ensureSendResponseHandlingForMessageResponse()
57
    {
58
        /** @var Payload $payload */
59
        $payload = new Payload([
60
            'text' => 'test message',
61
            'channel' => '#fntest',
62
        ]);
63
        /** @var RealTimeClient $client */
64
        $client = $this->prophesize(RealTimeClient::class);
65
        /* @noinspection PhpParamsInspection */
66
        $client->postMessage(Argument::any())->willReturn(true);
0 ignored issues
show
Documentation introduced by
\Prophecy\Argument::any() is of type object<Prophecy\Argument\Token\AnyValueToken>, but the function expects a object<Slack\Message\Message>.

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...
67
68
        $message = new Message(['icon_emoji' => 'foo']);
69
        $attachment = new Message\Attachment(['title' => 'Test']);
70
        $attachment->setTitle('Test');
71
        $attachment->setTitleLink('http://www.google.de');
72
        $attachment->setText('Test');
73
        $attachment->setFallback('Test');
74
        $attachment->setAuthorName('Test');
75
        $attachment->setAuthorLink('http://www.google.de');
76
        $attachment->setAuthorIcon('foo');
77
        $attachment->setImageUrl('http://www.google.de');
78
        $attachment->setThumbUrl('http://www.google.de');
79
80
        $message->setText('Test');
81
        $message->addAttachment($attachment);
82
83
        /** @var AbstractCommand $stub */
84
        $stub = $this->getMockForAbstractClass(AbstractCommand::class, [$payload, $client->reveal()]);
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Slack\RealTimeClient>.

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...
85
        $stub->sendResponse($message);
86
87
        static::assertEquals('foo', $message->getIconEmoji());
88
        $message->setIconEmoji('bar');
89
        static::assertEquals('bar', $message->getIconEmoji());
90
91
        $message->setAttachments([$attachment]);
92
        static::assertEquals([$attachment], $message->getAttachments());
93
    }
94
}
95