CommanderTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SlackyTests\Core;
4
5
6
use PHPUnit\Framework\TestCase;
7
use Slacky\Core\Commander;
8
use Slacky\Http\CurlInteractor;
9
use Slacky\Http\SlackResponseFactory;
10
11
/**
12
 * Class CommanderTest
13
 * @package SlackyTests\Core
14
 *
15
 * @property Commander commander
16
 */
17
class CommanderTest extends TestCase
18
{
19
    private $commander;
20
21
    public function setUp()/* The :void return type declaration that should be here would cause a BC issue */
22
    {
23
        parent::setUp();
24
        $interactor = new CurlInteractor();
25
        $interactor->setResponseFactory(new SlackResponseFactory());
26
27
        $this->commander = new Commander('xoxp-some-token-for-slack', $interactor);
28
    }
29
30
    /**
31
     * Test get method
32
     * @test
33
     */
34
    public function it_runs_execute_get()
35
    {
36
        $response = $this->commander->execute('chat.postMessage', [
37
            'channel' => '#general',
38
            'text'    => 'Hello, world!'
39
        ]);
40
41
        $resp = $response->getBody();
42
        $this->assertFalse($resp['ok']);
43
        $this->assertEquals('invalid_auth', $resp['error']);
44
        $this->assertEquals('slack.com', $response->getHeaders()['Host']);
45
    }
46
47
    /**
48
     * @test
49
     */
50
    public function it_runs_execute_post()
51
    {
52
        $response = $this->commander->execute('files.upload', [
53
            'channel' => '#general',
54
            'text'    => 'Hello, world!'
55
        ]);
56
57
        $resp = $response->getBody();
58
        $this->assertFalse($resp['ok']);
59
        $this->assertEquals('not_authed', $resp['error']);
60
        $this->assertEquals('slack.com', $response->getHeaders()['Host']);
61
    }
62
}