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

BeerCommandTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 9
loc 9
rs 9.6666
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 T3Bot\Commands\BeerCommand;
15
use T3Bot\Tests\Unit\BaseCommandTestCase;
16
17
/**
18
 * Class BeerCommandTest.
19
 */
20
21
/** @noinspection LongInheritanceChainInspection */
22
class BeerCommandTest extends BaseCommandTestCase
23
{
24
    /**
25
     *
26
     */
27 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...
Coding Style introduced by
tearDown uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
28
    {
29
        DriverManager::getConnection($GLOBALS['config']['db'], new Configuration())
30
            ->delete('beers', [
31
                'to_user' => 'U23456',
32
                'from_user' => 'U12345',
33
            ]);
34
        parent::tearDown();
35
    }
36
37
    /**
38
     * @test
39
     */
40 View Code Duplication
    public function processForReturnsCorrectResponseForWrongUsername()
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...
41
    {
42
        $this->initCommandWithPayload(BeerCommand::class, [
43
            'user' => 'U54321',
44
            'text' => 'beer:for max',
45
        ]);
46
        $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...
47
        static::assertEquals('*Sorry, a username must start with a @-sign:*', $result);
48
    }
49
50
    /**
51
     * @test
52
     */
53
    public function processForReturnsCorrectResponseForCorrectUsername()
54
    {
55
        $this->initCommandWithPayload(BeerCommand::class, [
56
            'user' => 'U12345',
57
            'text' => 'beer:for <@U23456>',
58
        ]);
59
        $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...
60
        static::assertStringStartsWith('Yeah, one more :t3beer: for <@U23456>', $result);
61
    }
62
63
    /**
64
     * @test
65
     */
66 View Code Duplication
    public function processForReturnsCorrectResponseForCorrectUsernameWithin24Hours()
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...
67
    {
68
        $this->initCommandWithPayload(BeerCommand::class, [
69
            'user' => 'U12345',
70
            'text' => 'beer:for <@U23456>',
71
        ]);
72
        $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...
73
        $result = $this->command->process();
74
        static::assertStringStartsWith('You spend one :t3beer: to <@U23456> within in last 24 hours. Too much beer is unhealthy ;)', $result);
75
    }
76
77
    /**
78
     * @test
79
     */
80
    public function processAllReturnsCorrectResponse()
81
    {
82
        $this->initCommandWithPayload(BeerCommand::class, [
83
            'user' => 'U12345',
84
            'text' => 'beer:all',
85
        ]);
86
        $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...
87
        static::assertRegExp('/Yeah, ([0-9]*) :t3beer: spend to all people/', $result);
88
    }
89
90
    /**
91
     * @test
92
     */
93
    public function processTop10ReturnsCorrectResponse()
94
    {
95
        $this->initCommandWithPayload(BeerCommand::class, [
96
            'user' => 'U12345',
97
            'text' => 'beer:top10',
98
        ]);
99
        $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...
100
        static::assertStringStartsWith('*Yeah, here are the TOP 10*', $result);
101
    }
102
103
    /**
104
     * @test
105
     */
106
    public function processStatsReturnsCorrectResponseForCorrectUsername()
107
    {
108
        $this->initCommandWithPayload(BeerCommand::class, [
109
            'user' => 'U12345',
110
            'text' => 'beer:stats <@U23456>',
111
        ]);
112
        $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...
113
        static::assertRegExp('/<@U23456> has received ([0-9]*) :t3beer: so far/', $result);
114
    }
115
116
    /**
117
     * @test
118
     */
119 View Code Duplication
    public function processStatsReturnsCorrectResponseForinvalidUsername()
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...
120
    {
121
        $this->initCommandWithPayload(BeerCommand::class, [
122
            'user' => 'U12345',
123
            'text' => 'beer:stats foo',
124
        ]);
125
        $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...
126
        static::assertEquals('*Sorry, a username must start with a @-sign:*', $result);
127
    }
128
}
129