GameTest::testGameNumberAndLocalIdentifier()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: benedikt
6
 * Date: 10/1/17
7
 * Time: 1:11 PM
8
 */
9
10
namespace Tfboe\FmLib\Tests\Unit\Entity\Traits;
11
12
use Doctrine\Common\Collections\ArrayCollection;
13
use Doctrine\Common\Collections\Collection;
14
use PHPUnit\Framework\MockObject\MockObject;
15
use Tfboe\FmLib\Entity\MatchInterface;
16
use Tfboe\FmLib\Entity\Traits\Game;
17
use Tfboe\FmLib\Helpers\Level;
18
use Tfboe\FmLib\Tests\Entity\Player;
19
use Tfboe\FmLib\Tests\Helpers\UnitTestCase;
20
21
22
/**
23
 * Class GameTest
24
 * @package Tfboe\FmLib\Tests\Unit\Entity
25
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
26
 */
27
class GameTest extends UnitTestCase
28
{
29
//<editor-fold desc="Public Methods">
30
  /**
31
   * @covers \Tfboe\FmLib\Entity\Traits\Game::getChildren
32
   * @uses   \Tfboe\FmLib\Entity\Traits\Game::init
33
   */
34
  public function testChildren()
35
  {
36
    $game = $this->game();
37
    self::callProtectedMethod($game, 'init');
38
    self::assertEmpty($game->getChildren());
0 ignored issues
show
Bug introduced by
The method getChildren does only exist in Tfboe\FmLib\Entity\Traits\Game, 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...
39
  }
40
41
  /**
42
   * @covers \Tfboe\FmLib\Entity\Traits\Game::setGameNumber
43
   * @covers \Tfboe\FmLib\Entity\Traits\Game::getGameNumber
44
   * @covers \Tfboe\FmLib\Entity\Traits\Game::getLocalIdentifier
45
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
46
   */
47
  public function testGameNumberAndLocalIdentifier()
48
  {
49
    $game = $this->game();
50
    $gameNumber = 1;
51
    $game->setGameNumber($gameNumber);
0 ignored issues
show
Bug introduced by
The method setGameNumber does only exist in Tfboe\FmLib\Entity\Traits\Game, 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...
52
    self::assertEquals($gameNumber, $game->getGameNumber());
0 ignored issues
show
Bug introduced by
The method getGameNumber does only exist in Tfboe\FmLib\Entity\Traits\Game, 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...
53
    self::assertEquals($game->getGameNumber(), $game->getLocalIdentifier());
0 ignored issues
show
Bug introduced by
The method getLocalIdentifier does only exist in Tfboe\FmLib\Entity\Traits\Game, 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...
54
  }
55
56
  /**
57
   * @covers \Tfboe\FmLib\Entity\Traits\Game::init
58
   * @uses   \Tfboe\FmLib\Entity\Traits\Game::getPlayersA
59
   * @uses   \Tfboe\FmLib\Entity\Traits\Game::getPlayersB
60
   */
61 View Code Duplication
  public function testInit()
0 ignored issues
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...
62
  {
63
    $game = $this->game();
64
    self::callProtectedMethod($game, 'init');
65
    self::assertInstanceOf(Collection::class, $game->getPlayersA());
0 ignored issues
show
Bug introduced by
The method getPlayersA does only exist in Tfboe\FmLib\Entity\Traits\Game, 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...
66
    self::assertInstanceOf(Collection::class, $game->getPlayersB());
0 ignored issues
show
Bug introduced by
The method getPlayersB does only exist in Tfboe\FmLib\Entity\Traits\Game, 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...
67
    self::assertEquals(0, $game->getPlayersA()->count());
68
    self::assertEquals(0, $game->getPlayersB()->count());
69
  }
70
71
  /**
72
   * @covers \Tfboe\FmLib\Entity\Traits\Game::getLevel
73
   */
74
  public function testLevel()
75
  {
76
    self::assertEquals(Level::GAME, $this->game()->getLevel());
0 ignored issues
show
Bug introduced by
The method getLevel does only exist in Tfboe\FmLib\Entity\Traits\Game, 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...
77
  }
78
79
  /**
80
   * @covers \Tfboe\FmLib\Entity\Traits\Game::setMatch
81
   * @covers \Tfboe\FmLib\Entity\Traits\Game::getMatch
82
   * @covers \Tfboe\FmLib\Entity\Traits\Game::getParent
83
   * @uses   \Tfboe\FmLib\Entity\Traits\Game::getGameNumber
84
   * @uses   \Tfboe\FmLib\Entity\Traits\Game::setGameNumber
85
   */
86 View Code Duplication
  public function testMatchAndParent()
0 ignored issues
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...
87
  {
88
    $game = $this->game();
89
    $match = $this->createMock(MatchInterface::class);
90
    $games = new ArrayCollection();
91
    $match->method('getGames')->willReturn($games);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
92
    $game->setGameNumber(1);
0 ignored issues
show
Bug introduced by
The method setGameNumber does only exist in Tfboe\FmLib\Entity\Traits\Game, 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...
93
94
    /** @var MatchInterface $match */
95
    $game->setMatch($match);
0 ignored issues
show
Bug introduced by
The method setMatch does only exist in Tfboe\FmLib\Entity\Traits\Game, 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...
96
    self::assertEquals($match, $game->getMatch());
0 ignored issues
show
Bug introduced by
The method getMatch does only exist in Tfboe\FmLib\Entity\Traits\Game, 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...
97
    self::assertEquals(1, $game->getMatch()->getGames()->count());
98
    self::assertEquals($game, $game->getMatch()->getGames()[$game->getGameNumber()]);
0 ignored issues
show
Bug introduced by
The method getGameNumber does only exist in Tfboe\FmLib\Entity\Traits\Game, 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
    self::assertEquals($game->getMatch(), $game->getParent());
0 ignored issues
show
Bug introduced by
The method getParent does only exist in Tfboe\FmLib\Entity\Traits\Game, 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
101
    $match2 = $this->createMock(MatchInterface::class);
102
    $games2 = new ArrayCollection();
103
    $match2->method('getGames')->willReturn($games2);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
104
105
    /** @var MatchInterface $match2 */
106
    $game->setMatch($match2);
107
    self::assertEquals($match2, $game->getMatch());
108
    self::assertEquals(1, $game->getMatch()->getGames()->count());
109
    self::assertEquals(0, $match->getGames()->count());
110
    self::assertEquals($game, $game->getMatch()->getGames()[$game->getGameNumber()]);
111
    self::assertEquals($game->getMatch(), $game->getParent());
112
  }
113
114
  /**
115
   * @covers \Tfboe\FmLib\Entity\Traits\Game::getPlayersA
116
   * @uses   \Tfboe\FmLib\Entity\Traits\Game::init
117
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
118
   */
119
  public function testPlayersA()
120
  {
121
    $game = $this->game();
122
    self::callProtectedMethod($game, 'init');
123
    /** @var Player $player */
124
    $player = $this->createStubWithId(Player::class, 1, 'getId');
125
    $game->getPlayersA()->set($player->getId(), $player);
0 ignored issues
show
Bug introduced by
The method getPlayersA does only exist in Tfboe\FmLib\Entity\Traits\Game, 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
    self::assertEquals(1, $game->getPlayersA()->count());
127
    self::assertEquals($player, $game->getPlayersA()[$player->getId()]);
128
  }
129
130
  /**
131
   * @covers \Tfboe\FmLib\Entity\Traits\Game::getPlayersB
132
   * @uses   \Tfboe\FmLib\Entity\Traits\Game::init
133
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
134
   */
135
  public function testPlayersB()
136
  {
137
    $game = $this->game();
138
    self::callProtectedMethod($game, 'init');
139
    /** @var Player $player */
140
    $player = $this->createStubWithId(Player::class, 1, 'getId');
141
    $game->getPlayersB()->set($player->getId(), $player);
0 ignored issues
show
Bug introduced by
The method getPlayersB does only exist in Tfboe\FmLib\Entity\Traits\Game, 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...
142
    self::assertEquals(1, $game->getPlayersB()->count());
143
    self::assertEquals($player, $game->getPlayersB()[$player->getId()]);
144
  }
145
//</editor-fold desc="Public Methods">
146
147
//<editor-fold desc="Private Methods">
148
  /**
149
   * @return Game|MockObject a new game
150
   */
151
  private function game(): MockObject
152
  {
153
    return $this->getMockForTrait(Game::class);
154
  }
155
//</editor-fold desc="Private Methods">
156
}