Completed
Pull Request — master (#11)
by Elisha-Wigwe Chijioke
03:32
created

PotatoModelTest   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 113
Duplicated Lines 31.86 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 12
Bugs 6 Features 4
Metric Value
wmc 13
c 12
b 6
f 4
lcom 1
cbo 4
dl 36
loc 113
rs 10

13 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A teardDown() 0 4 1
A testGetMagicFunctionWorksAndREturnTheDataInDatatoSave() 0 8 1
A testGetMagicFunctionDoesNotWorkIfCalledREquesIsNotInDataToSave() 0 7 1
A tesnotMagicFunctionIsSetWorks() 0 9 1
A testGetAllFunctionWorksWithNullAsQuery() 0 3 1
A testIsStoredFunctionWorksForFalse() 0 6 1
A testIsStoredFunctionWorksForTrue() 0 7 1
A testSavefunctionWorksForInsert() 9 9 1
A testSavefunctionWorksForUpdate() 10 10 1
A testUpdateFunctionworks() 10 10 1
A testInsertFunctionworks() 7 7 1
A testDestroyFunctionWorks() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
// namespace Elchroy\ORM\Tests;
4
5
use Elchroy\PotatoORM\PotatoModel;
6
use Mockery as m;
7
8
class PotatoModelTest extends \PHPUnit_Framework_TestCase
9
{
10
    public $mockConnector;
11
    public $mockStatement;
12
    private $mockQuery;
13
    private $mockModel;
14
    private $model;
0 ignored issues
show
Unused Code introduced by
The property $model is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
15
    private $connection;
0 ignored issues
show
Unused Code introduced by
The property $connection is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
17
    public function setUp()
18
    {
19
        $this->mockQuery = m::mock('Elchroy\PotatoORM\PotatoQuery');
20
        $this->mockModel = new PotatoModel($this->mockQuery);
21
        // $this->mockModel2 = PotatoModel::find(4);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
22
        $this->mockConnector = m::mock('Elchroy\PotatoORM\PotatoConnector');
23
        $this->mockStatement = m::mock('PDOStatement');
24
    }
25
26
    public function teardDown()
27
    {
28
        // m::close();
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
29
    }
30
31
    public function testGetMagicFunctionWorksAndREturnTheDataInDatatoSave()
32
    {
33
        $model = new PotatoModel($this->mockQuery);
34
        $model->name = 'Puffy';
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Elchroy\PotatoORM\PotatoModel>. 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...
35
        $name = $model->name;
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Elchroy\PotatoORM\PotatoModel>. 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...
36
        $this->assertContains('name', array_keys($model->dataToSave));
37
        $this->assertTrue($name == 'Puffy');
38
    }
39
40
    public function testGetMagicFunctionDoesNotWorkIfCalledREquesIsNotInDataToSave()
41
    {
42
        $model = new PotatoModel($this->mockQuery);
43
        $name = $model->name;
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Elchroy\PotatoORM\PotatoModel>. 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->assertNotContains('name', $model->dataToSave);
45
        $this->assertEquals('name not found.', $name);
46
    }
47
48
    public function tesnotMagicFunctionIsSetWorks()
49
    {
50
        $this->getMockBuilder('PotatoModel')
51
        ->setMethods(['insert'])
52
        ->getMock();
53
        $this->expects($this->once())
54
        ->method('handleValue')
55
        ->will($this->returnValue(23)); //Whatever value you want to return
56
    }
57
58
    public function testGetAllFunctionWorksWithNullAsQuery()
59
    {
60
    }
61
62
    public function testIsStoredFunctionWorksForFalse()
63
    {
64
        $model = new PotatoModel($this->mockQuery);
65
        $result = $model->isStored();
66
        $this->assertFalse($result);
67
    }
68
69
    public function testIsStoredFunctionWorksForTrue()
70
    {
71
        $model = new PotatoModel($this->mockQuery);
72
        $model->id = 34;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Elchroy\PotatoORM\PotatoModel>. 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...
73
        $result = $model->isStored();
74
        $this->assertTrue($result);
75
    }
76
77 View Code Duplication
    public function testSavefunctionWorksForInsert()
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...
78
    {
79
        $this->mockQuery->shouldReceive('storeIn')->andReturn(true);
80
81
        $this->mockModel->name = 'Harry';
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Elchroy\PotatoORM\PotatoModel>. 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...
82
        $result = $this->mockModel->save();
83
84
        $this->assertTrue($result);
85
    }
86
87 View Code Duplication
    public function testSavefunctionWorksForUpdate()
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...
88
    {
89
        $this->mockQuery->shouldReceive('updateAt')->andReturn(true);
90
91
        $this->mockModel->id = 23;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Elchroy\PotatoORM\PotatoModel>. 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...
92
        $this->mockModel->name = 'Harry';
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Elchroy\PotatoORM\PotatoModel>. 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...
93
        $result = $this->mockModel->save();
94
95
        $this->assertTrue($result);
96
    }
97
98 View Code Duplication
    public function testUpdateFunctionworks()
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...
99
    {
100
        $this->mockQuery->shouldReceive('updateAt')->andReturn(true);
101
102
        $this->mockModel->id = 23;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Elchroy\PotatoORM\PotatoModel>. 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...
103
        $this->mockModel->name = 'Harry';
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Elchroy\PotatoORM\PotatoModel>. 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...
104
        $result = $this->mockModel->update();
105
106
        $this->assertTrue($result);
107
    }
108
109 View Code Duplication
    public function testInsertFunctionworks()
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...
110
    {
111
        $this->mockQuery->shouldReceive('storeIn')->andReturn(true);
112
        $this->mockModel->name = 'harry';
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Elchroy\PotatoORM\PotatoModel>. 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...
113
        $result = $this->mockModel->insert();
114
        $this->assertTrue($result);
115
    }
116
117
    public function testDestroyFunctionWorks()
118
    {
119
    }
120
}
121