Completed
Push — master ( 57d73d...015892 )
by Vincenzo
03:10
created

OrmModelsTest::testPlayerOrmGetSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Importance

Changes 3
Bugs 0 Features 3
Metric Value
c 3
b 0
f 3
dl 11
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
4
/**
5
 * Class OrmModelsTest
6
 */
7
class OrmModelsTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
10
11
    /**
12
     * @group OrmModels
13
     * @group PlayerOrm
14
     */
15 View Code Duplication
    public function testPlayerOrmGetSet()
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...
16
    {
17
        $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller();
18
        $playerM = $rndFiller->getPlayer();
19
        $arrayPl = $playerM->toArray();
20
        $playerO = \App\Lib\DsManager\Models\Orm\Player::create($arrayPl);
21
        $this->assertNotEmpty($playerO);
22
23
        $newPlayer = \App\Lib\DsManager\Models\Player::fromArray($playerO->toArray());
24
        $this->assertNotEmpty($newPlayer);
25
    }
26
27
    /**
28
     * @group OrmModels
29
     * @group CoachOrm
30
     */
31
    public function testCoachOrmGetSet()
32
    {
33
        $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller();
34
        $coach = $rndFiller->getCoach();
35
        $arrayPl = $coach->toArray();
36
        $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($arrayPl);
37
        $this->assertNotEmpty($coachO);
38
39
        $newCoach = \App\Lib\DsManager\Models\Coach::fromArray($coachO->toArray());
40
        $this->assertNotEmpty($newCoach);
41
    }
42
43
    /**
44
     * @group OrmModels
45
     * @group TeamOrm
46
     */
47
    public function testTeamOrm()
48
    {
49
        $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller();
50
        $team = $rndFiller->getTeam($rndFiller->getLocale());
51
        $teamArray = $team->toArray();
52
        $this->assertNotEmpty($team);
53
        $teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray);
54
        $this->assertNotEmpty($teamArray);
55
        $this->assertNotEmpty($teamArray['roster']);
56
        foreach ($teamArray['roster'] as $player) {
57
            $player['team_id'] = $teamO->id;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Lib\DsManager\Models\Orm\Team>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
58
            $playerO = \App\Lib\DsManager\Models\Orm\Player::create($player);
59
            $this->assertNotEmpty($playerO);
60
        }
61
        $teamArray['coach']['team_id'] = $teamO->id;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Lib\DsManager\Models\Orm\Team>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
62
        $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']);
63
        $this->assertNotEmpty($coachO);
64
65
        $this->assertNotEmpty(
66
            \App\Lib\DsManager\Models\Orm\Team::with(
67
                'roster'
68
            )->with(
69
                'coach'
70
            )->where(
71
                [
72
                    'id' => $teamO->id
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Lib\DsManager\Models\Orm\Team>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
73
                ]
74
            )->get()->toArray()
75
        );
76
    }
77
}
78