Skip to content

Loading…

Resolving ZF2-406: missing __isset / __unset in AbstractRowGateway. #1911

Merged
merged 2 commits into from

3 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 71 additions and 0 deletions.
  1. +22 −0 library/Zend/Db/RowGateway/AbstractRowGateway.php
  2. +49 −0 tests/Zend/Db/RowGateway/RowGatewayTest.php
View
22 library/Zend/Db/RowGateway/AbstractRowGateway.php
@@ -288,4 +288,26 @@ public function __set($name, $value)
{
$this->offsetSet($name, $value);
}
+
+ /**
+ * __isset
+ *
+ * @param string $name
+ * @return boolean
+ */
+ public function __isset($name)
+ {
+ return $this->offsetExists($name);
+ }
+
+ /**
+ * __unset
+ *
+ * @param string $name
+ * @return void
+ */
+ public function __unset($name)
+ {
+ $this->offsetUnset($name);
+ }
}
View
49 tests/Zend/Db/RowGateway/RowGatewayTest.php
@@ -53,4 +53,53 @@ public function test__set()
$this->assertEquals('test', $row['testColumn']);
}
+ public function test__isset()
+ {
+ // Test isset before and after assigning to a property:
+ $row = new RowGateway('id', 'fake', $this->mockAdapter);
+ $this->assertFalse(isset($row->foo));
+ $row->foo = 'bar';
+ $this->assertTrue(isset($row->foo));
+
+ // Test isset before and after assigning to an index:
+ $row = new RowGateway('id', 'fake', $this->mockAdapter);
+ $this->assertFalse(isset($row->foo));
+ $row['foo'] = 'bar';
+ $this->assertTrue(isset($row->foo));
+ }
+
+ public function testOffsetExists()
+ {
+ // Test isset before and after assigning to a property:
+ $row = new RowGateway('id', 'fake', $this->mockAdapter);
+ $this->assertFalse(isset($row['foo']));
+ $row->foo = 'bar';
+ $this->assertTrue(isset($row['foo']));
+
+ // Test isset before and after assigning to an index:
+ $row = new RowGateway('id', 'fake', $this->mockAdapter);
+ $this->assertFalse(isset($row['foo']));
+ $row['foo'] = 'bar';
+ $this->assertTrue(isset($row['foo']));
+ }
+
+ public function test__unset()
+ {
+ $row = new RowGateway('id', 'fake', $this->mockAdapter);
+ $row->foo = 'bar';
+ $this->assertEquals('bar', $row->foo);
+ unset($row->foo);
+ $this->assertEmpty($row->foo);
+ $this->assertEmpty($row['foo']);
+ }
+
+ public function testOffsetUnset()
+ {
+ $row = new RowGateway('id', 'fake', $this->mockAdapter);
+ $row['foo'] = 'bar';
+ $this->assertEquals('bar', $row['foo']);
+ unset($row['foo']);
+ $this->assertEmpty($row->foo);
+ $this->assertEmpty($row['foo']);
+ }
}
Something went wrong with that request. Please try again.