summaryrefslogtreecommitdiff
path: root/test/ORMTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'test/ORMTest.php')
-rw-r--r--test/ORMTest.php68
1 files changed, 68 insertions, 0 deletions
diff --git a/test/ORMTest.php b/test/ORMTest.php
index e0e4900..3df3a73 100644
--- a/test/ORMTest.php
+++ b/test/ORMTest.php
@@ -99,4 +99,72 @@ class ORMTest extends PHPUnit_Framework_TestCase {
$resultSet = ORM::for_table('test')->find_result_set();
$resultSet->invalidFunctionCall();
}
+
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage Primary key ID missing from row or is null
+ * These next two tests are needed because if you have select()ed some fields,
+ * but not the primary key, then the primary key is not available for the
+ * update/delete query - see issue #203.
+ * We need to change the primary key here to something other than `id`
+ * becuase MockPDOStatement->fetch() always returns an id.
+ */
+ public function testUpdateNullPrimaryKey() {
+ $widget = ORM::for_table('widget')
+ ->use_id_column('primary')
+ ->select('foo')
+ ->where('primary', 1)
+ ->find_one()
+ ;
+
+ $widget->foo = 'bar';
+ $widget->save();
+ }
+
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage Primary key ID missing from row or is null
+ */
+ public function testDeleteNullPrimaryKey() {
+ $widget = ORM::for_table('widget')
+ ->use_id_column('primary')
+ ->select('foo')
+ ->where('primary', 1)
+ ->find_one()
+ ;
+
+ $widget->delete();
+ }
+
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage Primary key ID missing from row or is null
+ */
+ public function testNullPrimaryKey() {
+ $widget = ORM::for_table('widget')
+ ->use_id_column('primary')
+ ->select('foo')
+ ->where('primary', 1)
+ ->find_one()
+ ;
+
+ $widget->id(true);
+ }
+
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage Primary key ID contains null value(s)
+ */
+ public function testNullPrimaryKeyPart() {
+ $widget = ORM::for_table('widget')
+ ->use_id_column(array('id', 'primary'))
+ ->select('foo')
+ ->where('id', 1)
+ ->where('primary', 1)
+ ->find_one()
+ ;
+
+ $widget->id(true);
+
+ }
} \ No newline at end of file