Completed
Push — master ( 3a177f...0ba58c )
by Gabriel
03:15
created

BelongsToTest::_after()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace Nip\Records\Tests\Relations;
4
5
use Mockery as m;
6
use Nip\Records\Record;
7
use Nip\Records\Relations\BelongsTo;
8
9
/**
10
 * Class BelongsToTest
11
 * @package Nip\Records\Tests\Relations
12
 */
13
class BelongsToTest extends \Nip\Records\Tests\AbstractTest
14
{
15
16
    /**
17
     * @var BelongsTo
18
     */
19
    protected $_object;
20
21
    public function testInitResults()
22
    {
23
        static::assertSame($this->_user, $this->_object->getResults());
0 ignored issues
show
Bug introduced by
The property _user does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
24
    }
25
26
    protected function setUp()
27
    {
28
        parent::setUp();
29
30
        $this->_object = new BelongsTo();
31
        $this->_object->setName('User');
32
33
        $this->_user = new Record();
34
35
        $users = m::namedMock('Users', 'Nip\Records\RecordManager')->shouldDeferMissing()
36
            ->shouldReceive('instance')->andReturnSelf()
37
            ->shouldReceive('findOne')->andReturn($this->_user)->getMock();
38
        $users->setPrimaryFK('id_user');
39
//        m::namedMock('User', 'Record');
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
40
41
        $this->_object->setWith($users);
42
        $article = new Record();
43
        $article->id_user = 3;
0 ignored issues
show
Documentation introduced by
The property id_user does not exist on object<Nip\Records\Record>. 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...
44
        $this->_object->setItem($article);
45
    }
46
47
}
48