Completed
Push — master ( 685463...a3ac99 )
by Benedikt
13:47
created

TournamentTest::tournament()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
rs 10
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 PHPUnit\Framework\MockObject\MockObject;
14
use Tfboe\FmLib\Entity\CompetitionInterface;
15
use Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity;
16
use Tfboe\FmLib\Entity\TournamentInterface;
17
use Tfboe\FmLib\Entity\User;
18
use Tfboe\FmLib\Helpers\Level;
19
use Tfboe\FmLib\TestHelpers\UnitTestCase;
20
21
/** @noinspection PhpMultipleClassesDeclarationsInOneFile */
22
abstract class Tournament extends TournamentHierarchyEntity implements TournamentInterface
23
{
24
  use \Tfboe\FmLib\Entity\Traits\Tournament;
25
}
26
27
/** @noinspection PhpMultipleClassesDeclarationsInOneFile */
28
29
/**
30
 * Class TournamentTest
31
 * @package Tfboe\FmLib\Tests\Unit\Entity
32
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
33
 */
34
class TournamentTest extends UnitTestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
35
{
36
//<editor-fold desc="Public Methods">
37
  /**
38
   * @covers \Tfboe\FmLib\Entity\Traits\Tournament::getCompetitions
39
   * @covers \Tfboe\FmLib\Entity\Traits\Tournament::getChildren
40
   * @uses   \Tfboe\FmLib\Entity\Helpers\NameEntity::getName
41
   * @uses   \Tfboe\FmLib\Entity\Helpers\NameEntity::setName
42
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament::init
43
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
44
   */
45 View Code Duplication
  public function testCompetitionsAndChildren()
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...
46
  {
47
    $tournament = $this->tournament();
48
    $tournament->init();
0 ignored issues
show
Bug introduced by
The method init does only exist in Tfboe\FmLib\Tests\Unit\Entity\Traits\Tournament, 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...
49
    $competition = $this->createStub(CompetitionInterface::class, ['getName' => 'comp name']);
50
    self::assertEquals($tournament->getCompetitions(), $tournament->getChildren());
0 ignored issues
show
Bug introduced by
The method getCompetitions does only exist in Tfboe\FmLib\Tests\Unit\Entity\Traits\Tournament, 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...
Bug introduced by
The method getChildren does only exist in Tfboe\FmLib\Tests\Unit\Entity\Traits\Tournament, 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...
51
    /** @var CompetitionInterface $competition */
52
    $tournament->getCompetitions()->set($competition->getName(), $competition);
53
    self::assertEquals(1, $tournament->getCompetitions()->count());
54
    self::assertEquals($competition, $tournament->getCompetitions()[$competition->getName()]);
55
    self::assertEquals($tournament->getCompetitions(), $tournament->getChildren());
56
  }
57
58
  /**
59
   * @covers \Tfboe\FmLib\Entity\Traits\Tournament::init
60
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament::getCompetitions
61
   * @uses   \Tfboe\FmLib\Entity\Traits\Tournament::getTournamentListId
62
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
63
   */
64
  public function testConstructor()
65
  {
66
    $tournament = $this->tournament();
67
    $tournament->init();
0 ignored issues
show
Bug introduced by
The method init does only exist in Tfboe\FmLib\Tests\Unit\Entity\Traits\Tournament, 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...
68
    self::assertInstanceOf(ArrayCollection::class, $tournament->getCompetitions());
0 ignored issues
show
Bug introduced by
The method getCompetitions does only exist in Tfboe\FmLib\Tests\Unit\Entity\Traits\Tournament, 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...
69
    self::assertEquals(0, $tournament->getCompetitions()->count());
70
    self::assertEquals("", $tournament->getTournamentListId());
0 ignored issues
show
Bug introduced by
The method getTournamentListId does only exist in Tfboe\FmLib\Tests\Unit\Entity\Traits\Tournament, 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...
71
  }
72
73
  /**
74
   * @covers \Tfboe\FmLib\Entity\Traits\Tournament::setCreator
75
   * @covers \Tfboe\FmLib\Entity\Traits\Tournament::getCreator
76
   * @uses   \Tfboe\FmLib\Entity\User::__construct
77
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
78
   */
79
  public function testCreator()
80
  {
81
    $tournament = $this->tournament();
82
    $creator = new User();
83
    $tournament->setCreator($creator);
0 ignored issues
show
Bug introduced by
The method setCreator does only exist in Tfboe\FmLib\Tests\Unit\Entity\Traits\Tournament, 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...
84
    self::assertEquals($creator, $tournament->getCreator());
0 ignored issues
show
Bug introduced by
The method getCreator does only exist in Tfboe\FmLib\Tests\Unit\Entity\Traits\Tournament, 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...
85
  }
86
87
  /**
88
   * @covers \Tfboe\FmLib\Entity\Traits\Tournament::getLocalIdentifier
89
   * @uses   \Tfboe\FmLib\Entity\Helpers\UUIDEntity::getId
90
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
91
   */
92
  public function testGetLocalIdentifier()
93
  {
94
    $tournament = $this->tournament();
95
    /** @noinspection PhpUnhandledExceptionInspection */
96
    self::getProperty(get_class($tournament), 'id')->setValue($tournament, 'user-id');
97
    self::assertEquals($tournament->getId(), $tournament->getLocalIdentifier());
0 ignored issues
show
Bug introduced by
The method getId does only exist in Tfboe\FmLib\Tests\Unit\Entity\Traits\Tournament, 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...
Bug introduced by
The method getLocalIdentifier does only exist in Tfboe\FmLib\Tests\Unit\Entity\Traits\Tournament, 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...
98
  }
99
100
  /**
101
   * @covers \Tfboe\FmLib\Entity\Traits\Tournament::getLevel
102
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
103
   */
104
  public function testLevel()
105
  {
106
    self::assertEquals(Level::TOURNAMENT, $this->tournament()->getLevel());
0 ignored issues
show
Bug introduced by
The method getLevel does only exist in Tfboe\FmLib\Tests\Unit\Entity\Traits\Tournament, 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...
107
  }
108
109
  /**
110
   * @covers \Tfboe\FmLib\Entity\Traits\Tournament::getParent
111
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
112
   */
113
  public function testParent()
114
  {
115
    self::assertNull($this->tournament()->getParent());
0 ignored issues
show
Bug introduced by
The method getParent does only exist in Tfboe\FmLib\Tests\Unit\Entity\Traits\Tournament, 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...
116
  }
117
118
  /**
119
   * @covers \Tfboe\FmLib\Entity\Traits\Tournament::setTournamentListId
120
   * @covers \Tfboe\FmLib\Entity\Traits\Tournament::getTournamentListId
121
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
122
   */
123
  public function testTournamentListId()
124
  {
125
    $tournament = $this->tournament();
126
    $tournament->setTournamentListId("Changed");
0 ignored issues
show
Bug introduced by
The method setTournamentListId does only exist in Tfboe\FmLib\Tests\Unit\Entity\Traits\Tournament, 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...
127
    self::assertEquals("Changed", $tournament->getTournamentListId());
0 ignored issues
show
Bug introduced by
The method getTournamentListId does only exist in Tfboe\FmLib\Tests\Unit\Entity\Traits\Tournament, 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...
128
  }
129
130
  /**
131
   * @covers \Tfboe\FmLib\Entity\Traits\Tournament::setUserIdentifier
132
   * @covers \Tfboe\FmLib\Entity\Traits\Tournament::getUserIdentifier
133
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
134
   */
135
  public function testUserIdentifier()
136
  {
137
    $tournament = $this->tournament();
138
    $tournament->setUserIdentifier("UserIdentifier");
0 ignored issues
show
Bug introduced by
The method setUserIdentifier does only exist in Tfboe\FmLib\Tests\Unit\Entity\Traits\Tournament, 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...
139
    self::assertEquals("UserIdentifier", $tournament->getUserIdentifier());
0 ignored issues
show
Bug introduced by
The method getUserIdentifier does only exist in Tfboe\FmLib\Tests\Unit\Entity\Traits\Tournament, 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...
140
  }
141
//</editor-fold desc="Public Methods">
142
143
//<editor-fold desc="Private Methods">
144
  /**
145
   * @return Tournament|MockObject a new tournament
146
   */
147
  private function tournament(): MockObject
148
  {
149
    return $this->getMockForAbstractClass(Tournament::class);
150
  }
151
//</editor-fold desc="Private Methods">
152
}