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

TellCommandTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 8
loc 8
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 Doctrine\DBAL\Configuration;
13
use Doctrine\DBAL\DriverManager;
14
use React\EventLoop\LoopInterface;
15
use Slack\Payload;
16
use Slack\RealTimeClient;
17
use T3Bot\Commands\TellCommand;
18
use T3Bot\Tests\Unit\BaseCommandTestCase;
19
20
/**
21
 * Class TellCommandTest.
22
 */
23
24
/** @noinspection LongInheritanceChainInspection */
25
class TellCommandTest extends BaseCommandTestCase
26
{
27
    /**
28
     *
29
     */
30 View Code Duplication
    public function tearDown()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32
        DriverManager::getConnection($GLOBALS['config']['db'], new Configuration())
33
            ->delete('notifications', [
34
                'to_user' => 'U12345'
35
            ]);
36
        parent::tearDown();
37
    }
38
39
    /**
40
     * @return array
41
     */
42
    public function tellDataProvider() : array
43
    {
44
        return [
45
            'tell <@U12345> about review:47640' => ['tell <@U12345> about review:47640', 'OK, I will tell <@U12345> about your message'],
46
            'tell <@U12345> about forge:23456' => ['tell <@U12345> about forge:23456', 'OK, I will tell <@U12345> about your message'],
47
            'tell <@U12345> you are so nice' => ['tell <@U12345> you are so nice', 'OK, I will tell <@U12345> about your message'],
48
        ];
49
    }
50
51
    /**
52
     * @test
53
     * @dataProvider tellDataProvider
54
     *
55
     * @param string $message
56
     * @param string $expectedMessage
57
     */
58 View Code Duplication
    public function processTellReturnsCorrectResponse($message, $expectedMessage)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    {
60
        $this->initCommandWithPayload(TellCommand::class, [
61
            'user' => 'U54321',
62
            'text' => $message,
63
        ]);
64
        $result = $this->command->process();
0 ignored issues
show
Bug introduced by
The method process does only exist in T3Bot\Commands\AbstractCommand, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
65
        static::assertEquals($expectedMessage, $result);
66
    }
67
68
    /**
69
     * @test
70
     */
71
    public function processPresenceChangeReturnsCorrectResponseForPresenceAway()
72
    {
73
        $loop = $this->getMock(LoopInterface::class);
74
        /** @var Payload $payload */
75
        $payload = new Payload([
76
            'user' => 'U12345',
77
            'presence' => 'away',
78
        ]);
79
        /** @var RealTimeClient $client */
80
        $client = $this->getMock(RealTimeClient::class, [], [$loop]);
81
        /** @var TellCommand|\PHPUnit_Framework_MockObject_MockObject $command */
82
        $command = $this->getMock(TellCommand::class, ['sendResponse'], [$payload, $client]);
83
        $command->expects(static::exactly(0))
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in T3Bot\Commands\TellCommand.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
84
            ->method('sendResponse');
85
        $command->processPresenceChange('U12345', 'away');
0 ignored issues
show
Bug introduced by
The method processPresenceChange does only exist in T3Bot\Commands\TellCommand, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
86
    }
87
88
    /**
89
     * @test
90
     * @dataProvider tellDataProvider
91
     */
92
    public function processPresenceChangeReturnsCorrectResponseForPresenceActive($message)
93
    {
94
        $this->initCommandWithPayload(TellCommand::class, [
95
            'user' => 'U54321',
96
            'text' => $message,
97
        ]);
98
        $this->command->process();
0 ignored issues
show
Bug introduced by
The method process does only exist in T3Bot\Commands\AbstractCommand, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
99
100
        $loop = $this->getMock(LoopInterface::class);
101
        $payload = new Payload([
102
            'user' => 'U12345',
103
            'presence' => 'active',
104
        ]);
105
        $client = $this->getMock(RealTimeClient::class, [], [$loop]);
106
        /** @var TellCommand|\PHPUnit_Framework_MockObject_MockObject $command */
107
        $command = $this->getMock(TellCommand::class, ['sendResponse'], [$payload, $client]);
108
        $command
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in T3Bot\Commands\TellCommand.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
109
            ->expects(static::exactly(1))
110
            ->method('sendResponse');
111
        $command->processPresenceChange('U12345', 'active');
0 ignored issues
show
Bug introduced by
The method processPresenceChange does only exist in T3Bot\Commands\TellCommand, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
112
    }
113
}
114