Ejemplo n.º 1
0
 public function testInsertRecordInReadonly()
 {
     return;
     $logs = new LogSql('unit', Relation::r()->findByName('logs.Logs'), array('DEFAULT', 'DEFAULT', 'TG_OP::"logs"."enum_op_type"'));
     $db = Connection::factory('RW');
     $logs->build($db);
     // insert
     $this->assertSame($this->getNumberRowsInTable('unit.readonly'), 0);
     $this->assertSame($this->getNumberRowsInTable('logs.readonly'), 0);
     $db->query(new Raw("INSERT INTO readonly( name ) VALUES ( 'peter' );"));
     $this->assertSame($this->getNumberRowsInTable('unit.readonly'), 1);
     $this->assertSame($this->getNumberRowsInTable('logs.readonly'), 1);
     $db->query(new Raw("UPDATE readonly SET name = 'matt'"));
     $this->assertSame($this->getNumberRowsInTable('unit.readonly'), 1);
     $this->assertSame($this->getNumberRowsInTable('logs.readonly'), 2);
     $db->query(new Raw("DELETE FROM readonly WHERE name = 'matt'"));
     $this->assertSame($this->getNumberRowsInTable('unit.readonly'), 0);
     $this->assertSame($this->getNumberRowsInTable('logs.readonly'), 3);
     try {
         $db->query(new Raw("DELETE FROM \"logs\".readonly"));
         $this->fail("Exception expected");
     } catch (\Exception $e) {
     }
     $this->assertSame($this->getNumberRowsInTable('logs.readonly'), 3);
     try {
         $db->query(new Raw("UPDATE \"logs\".readonly SET name = 'jim'"));
         $this->fail("Exception expected");
     } catch (\Exception $e) {
     }
     $this->assertSame($this->getNumberRowsInTable('logs.readonly'), 3);
 }
Ejemplo n.º 2
0
 public function testInsertRecordInReadonly()
 {
     return true;
     $db = Connection::factory('RW');
     $notify = new Notify('unitTest');
     $db->query($notify);
     $db->listen('bond');
     // insert
     $this->assertSame($this->getNumberRowsInTable('unit.a2'), 0);
     $db->query(new Raw("INSERT INTO a2( name ) VALUES ( 'peter1' );"));
     $db->query(new Raw("INSERT INTO a2( name ) VALUES ( 'peter2' );"));
     $this->assertSame($this->getNumberRowsInTable('unit.a2'), 2);
     $notifications = $db->getNotifications();
     $this->assertSame(count($notifications), 2);
     $notification = array_shift($notifications);
     $notification["payload"] = json_decode($notification["payload"], true);
     $this->assertSame($notification['payload']['op'], "INSERT");
     $this->assertSame($notification['payload']['table'], "a2");
     $this->assertSame($notification['payload']['pk'], array(1));
     // update
     $db->query(new Raw("UPDATE a2 SET name = 'peter3' WHERE name = 'peter2';"));
     $notifications = $db->getNotifications(true);
     $this->assertSame(count($notifications), 1);
     $notification = array_shift($notifications);
     $this->assertSame($notification['payload']['op'], "UPDATE");
     $this->assertSame($notification['payload']['table'], "a2");
     $this->assertSame($notification['payload']['pk'], array(2));
     $db->query(new Raw("UPDATE a2 SET name = 'peter3' WHERE name = 'peter3';"));
     $notifications = $db->getNotifications(true);
     $this->assertSame(count($notifications), 0);
     // changeing primary key
     $db->query(new Raw("UPDATE a2 SET id = 3000 WHERE id = 1;"));
     $notifications = $db->getNotifications(true);
     $this->assertSame(count($notifications), 2);
     $this->assertSame($notifications[0]["payload"]['pk'][0], 1);
     $this->assertSame($notifications[1]["payload"]['pk'][0], 3000);
     $this->assertSame($notifications[0]["payload"]['op'], 'DELETE');
     $this->assertSame($notifications[1]["payload"]['op'], 'INSERT');
     // delete
     $db->query(new Raw("DELETE FROM a2 WHERE id = 3000;"));
     $notifications = $db->getNotifications(true);
     $this->assertSame(count($notifications), 1);
     $this->assertSame($notifications[0]["payload"]['pk'][0], 3000);
     $this->assertSame($notifications[0]["payload"]['op'], 'DELETE');
 }