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; |
|
|
|
|
15
|
|
|
private $connection; |
|
|
|
|
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); |
|
|
|
|
22
|
|
|
$this->mockConnector = m::mock('Elchroy\PotatoORM\PotatoConnector'); |
23
|
|
|
$this->mockStatement = m::mock('PDOStatement'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function teardDown() |
27
|
|
|
{ |
28
|
|
|
// m::close(); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testGetMagicFunctionWorksAndREturnTheDataInDatatoSave() |
32
|
|
|
{ |
33
|
|
|
$model = new PotatoModel($this->mockQuery); |
34
|
|
|
$model->name = 'Puffy'; |
|
|
|
|
35
|
|
|
$name = $model->name; |
|
|
|
|
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; |
|
|
|
|
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; |
|
|
|
|
73
|
|
|
$result = $model->isStored(); |
74
|
|
|
$this->assertTrue($result); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
View Code Duplication |
public function testSavefunctionWorksForInsert() |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
$this->mockQuery->shouldReceive('storeIn')->andReturn(true); |
80
|
|
|
|
81
|
|
|
$this->mockModel->name = 'Harry'; |
|
|
|
|
82
|
|
|
$result = $this->mockModel->save(); |
83
|
|
|
|
84
|
|
|
$this->assertTrue($result); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
View Code Duplication |
public function testSavefunctionWorksForUpdate() |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
$this->mockQuery->shouldReceive('updateAt')->andReturn(true); |
90
|
|
|
|
91
|
|
|
$this->mockModel->id = 23; |
|
|
|
|
92
|
|
|
$this->mockModel->name = 'Harry'; |
|
|
|
|
93
|
|
|
$result = $this->mockModel->save(); |
94
|
|
|
|
95
|
|
|
$this->assertTrue($result); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
View Code Duplication |
public function testUpdateFunctionworks() |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
$this->mockQuery->shouldReceive('updateAt')->andReturn(true); |
101
|
|
|
|
102
|
|
|
$this->mockModel->id = 23; |
|
|
|
|
103
|
|
|
$this->mockModel->name = 'Harry'; |
|
|
|
|
104
|
|
|
$result = $this->mockModel->update(); |
105
|
|
|
|
106
|
|
|
$this->assertTrue($result); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
View Code Duplication |
public function testInsertFunctionworks() |
|
|
|
|
110
|
|
|
{ |
111
|
|
|
$this->mockQuery->shouldReceive('storeIn')->andReturn(true); |
112
|
|
|
$this->mockModel->name = 'harry'; |
|
|
|
|
113
|
|
|
$result = $this->mockModel->insert(); |
114
|
|
|
$this->assertTrue($result); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function testDestroyFunctionWorks() |
118
|
|
|
{ |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.