Completed
Push — develop ( ebe2d3...7bc0c1 )
by Oyebanji Jacob
02:13
created
test/ModelTest.php 2 patches
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -5,23 +5,23 @@  discard block
 block discarded – undo
5 5
 
6 6
 class ModelTest extends PHPUnit_Framework_TestCase
7 7
 {
8
-	/**
9
-	 * Instance of DatabaseConnection used in test.
10
-	 */
11
-	protected $databaseConnection;
8
+    /**
9
+     * Instance of DatabaseConnection used in test.
10
+     */
11
+    protected $databaseConnection;
12 12
 
13
-	protected $model;
13
+    protected $model;
14 14
 
15
-	protected $sqlStatement;
15
+    protected $sqlStatement;
16 16
 
17
-	public function setUp(){
17
+    public function setUp(){
18 18
 		
19 19
 
20
-		$databaseConnectionStringFactory =
20
+        $databaseConnectionStringFactory =
21 21
                         m::mock('Pyjac\ORM\DatabaseConnectionStringFactoryInterface');
22 22
 
23 23
         $databaseConnectionStringFactory->shouldReceive('createDatabaseSourceString')
24
-                                             ->with(['DRIVER' => 'sqlite', 'HOSTNAME' => '127.0.0.1', 'USERNAME' => '', 'PASSWORD' => '', 'DBNAME' => 'potatoORM', 'PORT' => '54320'])->once()->andReturn('sqlite::memory:');
24
+                                                ->with(['DRIVER' => 'sqlite', 'HOSTNAME' => '127.0.0.1', 'USERNAME' => '', 'PASSWORD' => '', 'DBNAME' => 'potatoORM', 'PORT' => '54320'])->once()->andReturn('sqlite::memory:');
25 25
 
26 26
         $this->databaseConnection = m::mock('Pyjac\ORM\DatabaseConnection');
27 27
 
@@ -30,118 +30,118 @@  discard block
 block discarded – undo
30 30
         /*$this->databaseConnection = m::mock('Pyjac\ORM\DatabaseConnection[getInstance,createConnection]',array($databaseConnectionStringFactory));*/
31 31
         $this->model =  $this->getMockForAbstractClass('Pyjac\ORM\Model',[$this->databaseConnection]);
32 32
         //= new DatabaseConnection($databaseConnectionStringFactory);
33
-	}
33
+    }
34 34
 
35
-	public function testGetTableNameReturnsCorrectTableName()
35
+    public function testGetTableNameReturnsCorrectTableName()
36 36
     {
37
-    	$this->databaseConnection->shouldReceive('createConnection')->with('sqlite::memory:')->once()->andReturn("");
37
+        $this->databaseConnection->shouldReceive('createConnection')->with('sqlite::memory:')->once()->andReturn("");
38 38
         $this->model->expects($this->any())
39
-             ->method('getTableName')
40
-             ->will($this->returnValue(strtolower(get_class($this->model).'s')));
39
+                ->method('getTableName')
40
+                ->will($this->returnValue(strtolower(get_class($this->model).'s')));
41 41
 
42 42
         $this->assertEquals($this->model->getTableName(), strtolower(get_class($this->model).'s'));
43 43
     }
44 44
 
45 45
     public function testGetReturnsAnObjectWhenIdIsFoundInDatabase()
46 46
     {
47
-    	$this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
48
-    	$this->sqlStatement->shouldReceive('setFetchMode');
49
-    	$this->sqlStatement->shouldReceive('execute');
50
-    	$this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1);
51
-    	$this->sqlStatement->shouldReceive('fetch')->once()->andReturn(new stdClass);
47
+        $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
48
+        $this->sqlStatement->shouldReceive('setFetchMode');
49
+        $this->sqlStatement->shouldReceive('execute');
50
+        $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1);
51
+        $this->sqlStatement->shouldReceive('fetch')->once()->andReturn(new stdClass);
52 52
 
53
-    	$this->assertInstanceOf('stdClass', $this->model->get(1));
53
+        $this->assertInstanceOf('stdClass', $this->model->get(1));
54 54
     }
55 55
     /**
56 56
      * @expectedException Pyjac\ORM\Exception\ModelNotFoundException
57 57
      */
58 58
     public function testGetThrowsModelNotFoundExceptionWhenIdNotFoundInDatabase()
59 59
     {
60
-    	$this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
61
-    	$this->sqlStatement->shouldReceive('setFetchMode');
62
-    	$this->sqlStatement->shouldReceive('execute');
63
-    	$this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(0);
60
+        $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
61
+        $this->sqlStatement->shouldReceive('setFetchMode');
62
+        $this->sqlStatement->shouldReceive('execute');
63
+        $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(0);
64 64
     	
65
-    	$this->assertInstanceOf('stdClass', $this->model->get(1));
65
+        $this->assertInstanceOf('stdClass', $this->model->get(1));
66 66
     }
67 67
 
68 68
     public function testAllReturnsAnArrayOfObjectsWhenValuesAreInDatabase()
69 69
     {
70
-    	$this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
71
-    	$this->sqlStatement->shouldReceive('execute');
72
-    	$this->sqlStatement->shouldReceive('fetchAll')->once()->andReturn([new stdClass,new stdClass]);
73
-    	$this->assertContainsOnlyInstancesOf('stdClass', $this->model->all());
70
+        $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
71
+        $this->sqlStatement->shouldReceive('execute');
72
+        $this->sqlStatement->shouldReceive('fetchAll')->once()->andReturn([new stdClass,new stdClass]);
73
+        $this->assertContainsOnlyInstancesOf('stdClass', $this->model->all());
74 74
     }
75 75
 
76 76
     public function testUpdateChangesTheValueOfObjectInDatabase()
77 77
     {
78
-    	$this->model->setProperties(['id' => 2, 'name' => 'pyjac', 'age' => '419']);
79
-    	$this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
80
-    	$this->sqlStatement->shouldReceive('execute');
81
-    	$this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1);
78
+        $this->model->setProperties(['id' => 2, 'name' => 'pyjac', 'age' => '419']);
79
+        $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
80
+        $this->sqlStatement->shouldReceive('execute');
81
+        $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1);
82 82
     
83
-    	$this->assertEquals(1, $this->model->update());
83
+        $this->assertEquals(1, $this->model->update());
84 84
     }
85 85
 
86 86
     public function testCreateObjectInDatabase()
87 87
     {
88
-    	$this->model->setProperties(['id' => 2, 'name' => 'pyjac', 'age' => '419']);
89
-    	$this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
90
-    	$this->sqlStatement->shouldReceive('execute');
91
-    	$this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1);
88
+        $this->model->setProperties(['id' => 2, 'name' => 'pyjac', 'age' => '419']);
89
+        $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
90
+        $this->sqlStatement->shouldReceive('execute');
91
+        $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1);
92 92
     
93
-    	$this->assertEquals(1, $this->model->create());
93
+        $this->assertEquals(1, $this->model->create());
94 94
     }
95 95
 
96 96
     public function testSaveShouldCreateNewModelInDatabaseWhenIdNotPresent()
97 97
     {
98
-    	$this->model->setProperties(['name' => 'pyjac', 'age' => '419']);
99
-    	$this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
100
-    	$this->sqlStatement->shouldReceive('execute');
101
-    	$this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1);
102
-    	$this->assertEquals(1, $this->model->save());
98
+        $this->model->setProperties(['name' => 'pyjac', 'age' => '419']);
99
+        $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
100
+        $this->sqlStatement->shouldReceive('execute');
101
+        $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1);
102
+        $this->assertEquals(1, $this->model->save());
103 103
     }
104 104
 
105 105
     public function testSaveShouldUpdateModelInDatabaseIfIdIsPresent()
106 106
     {
107
-    	$this->model->setProperties(['id' => 2,'name' => 'pyjac', 'age' => '419']);
108
-    	$this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
109
-    	$this->sqlStatement->shouldReceive('execute');
110
-    	$this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1);
111
-    	$this->assertEquals(1, $this->model->save());
107
+        $this->model->setProperties(['id' => 2,'name' => 'pyjac', 'age' => '419']);
108
+        $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
109
+        $this->sqlStatement->shouldReceive('execute');
110
+        $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1);
111
+        $this->assertEquals(1, $this->model->save());
112 112
     }
113 113
 
114 114
 
115 115
 
116 116
     public function testDeleteReturnsTrueWhenModelIsSuccessfullyRemovedFromDatabase()
117 117
     {
118
-    	$this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
119
-    	$this->sqlStatement->shouldReceive('execute');
120
-    	$this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1);
118
+        $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
119
+        $this->sqlStatement->shouldReceive('execute');
120
+        $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1);
121 121
     	
122
-    	$this->assertEquals(true, $this->model->delete(1));
122
+        $this->assertEquals(true, $this->model->delete(1));
123 123
     }
124 124
 
125 125
     public function testDeleteReturnsFalseWhenModelWasNotDeletedFromDatabase()
126 126
     {
127
-    	$this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
128
-    	$this->sqlStatement->shouldReceive('execute');
129
-    	$this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(0);
127
+        $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
128
+        $this->sqlStatement->shouldReceive('execute');
129
+        $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(0);
130 130
     	
131
-    	$this->assertEquals(false, $this->model->delete(1));
131
+        $this->assertEquals(false, $this->model->delete(1));
132 132
     }
133 133
 
134 134
     public function testMagicMethodsReturnCorrectResult() {
135
-	    /*$this->model->setReturnValue('__get', 'Pyjac', array('name'));
135
+        /*$this->model->setReturnValue('__get', 'Pyjac', array('name'));
136 136
 	    $this->model->setReturnValue('__get', '10', array('id'));
137 137
 	    $this->model->setReturnValue('__get', '60', array('age'));*/
138
-	    $this->model->id = '10';
139
-	    $this->model->name = 'Pyjac';
140
-	    $this->model->age = '60';
141
-
142
-	    $this->assertEquals($this->model->name, 'Pyjac');
143
-	    $this->assertEquals($this->model->id , '10');
144
-	    $this->assertEquals($this->model->age, '60');
145
-	}
138
+        $this->model->id = '10';
139
+        $this->model->name = 'Pyjac';
140
+        $this->model->age = '60';
141
+
142
+        $this->assertEquals($this->model->name, 'Pyjac');
143
+        $this->assertEquals($this->model->id , '10');
144
+        $this->assertEquals($this->model->age, '60');
145
+    }
146 146
 
147 147
 }
148 148
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 
15 15
 	protected $sqlStatement;
16 16
 
17
-	public function setUp(){
17
+	public function setUp() {
18 18
 		
19 19
 
20 20
 		$databaseConnectionStringFactory =
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
         $this->sqlStatement = m::mock('\PDOStatement');
29 29
 
30 30
         /*$this->databaseConnection = m::mock('Pyjac\ORM\DatabaseConnection[getInstance,createConnection]',array($databaseConnectionStringFactory));*/
31
-        $this->model =  $this->getMockForAbstractClass('Pyjac\ORM\Model',[$this->databaseConnection]);
31
+        $this->model = $this->getMockForAbstractClass('Pyjac\ORM\Model', [$this->databaseConnection]);
32 32
         //= new DatabaseConnection($databaseConnectionStringFactory);
33 33
 	}
34 34
 
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
     	$this->databaseConnection->shouldReceive('createConnection')->with('sqlite::memory:')->once()->andReturn("");
38 38
         $this->model->expects($this->any())
39 39
              ->method('getTableName')
40
-             ->will($this->returnValue(strtolower(get_class($this->model).'s')));
40
+             ->will($this->returnValue(strtolower(get_class($this->model) . 's')));
41 41
 
42
-        $this->assertEquals($this->model->getTableName(), strtolower(get_class($this->model).'s'));
42
+        $this->assertEquals($this->model->getTableName(), strtolower(get_class($this->model) . 's'));
43 43
     }
44 44
 
45 45
     public function testGetReturnsAnObjectWhenIdIsFoundInDatabase()
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
     {
70 70
     	$this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
71 71
     	$this->sqlStatement->shouldReceive('execute');
72
-    	$this->sqlStatement->shouldReceive('fetchAll')->once()->andReturn([new stdClass,new stdClass]);
72
+    	$this->sqlStatement->shouldReceive('fetchAll')->once()->andReturn([new stdClass, new stdClass]);
73 73
     	$this->assertContainsOnlyInstancesOf('stdClass', $this->model->all());
74 74
     }
75 75
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 
105 105
     public function testSaveShouldUpdateModelInDatabaseIfIdIsPresent()
106 106
     {
107
-    	$this->model->setProperties(['id' => 2,'name' => 'pyjac', 'age' => '419']);
107
+    	$this->model->setProperties(['id' => 2, 'name' => 'pyjac', 'age' => '419']);
108 108
     	$this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement);
109 109
     	$this->sqlStatement->shouldReceive('execute');
110 110
     	$this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1);
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 	    $this->model->age = '60';
141 141
 
142 142
 	    $this->assertEquals($this->model->name, 'Pyjac');
143
-	    $this->assertEquals($this->model->id , '10');
143
+	    $this->assertEquals($this->model->id, '10');
144 144
 	    $this->assertEquals($this->model->age, '60');
145 145
 	}
146 146
 
Please login to merge, or discard this patch.