savepointRelease->thenReturn(true); \Phake::when($drv)->savepointUndo->thenReturn(true); \Phake::when($drv)->savepointCreate->thenReturn(1)->thenReturn(2); $this->drv = $drv; } public function testManipulateTransactions(): void { $drv = $this->drv; $tr1 = new Transaction($drv); $tr2 = new Transaction($drv); \Phake::verify($this->drv, \Phake::times(2))->savepointCreate(\Phake::anyParameters()); $this->assertSame(1, $tr1->getIndex()); $this->assertSame(2, $tr2->getIndex()); unset($tr1); unset($tr2); \Phake::verify($this->drv)->savepointUndo(1); \Phake::verify($this->drv)->savepointUndo(2); } public function testCloseTransactions(): void { $drv = $this->drv; $tr1 = new Transaction($drv); $tr2 = new Transaction($drv); $this->assertTrue($tr1->isPending()); $this->assertTrue($tr2->isPending()); $tr1->commit(); $this->assertFalse($tr1->isPending()); $this->assertTrue($tr2->isPending()); \Phake::verify($this->drv)->savepointRelease(1); $tr2->rollback(); $this->assertFalse($tr1->isPending()); $this->assertFalse($tr2->isPending()); \Phake::verify($this->drv)->savepointUndo(2); } public function testIgnoreRollbackErrors(): void { // FIXME: This test segfaults when both transactions are checked. // It appears to be a wonky interaction with Phake, and not a problem // with the actual code. \Phake::when($this->drv)->savepointUndo->thenThrow(new Exception("savepointStale")); $tr1 = new Transaction($this->drv); //$tr2 = new Transaction($this->drv); unset($tr1); // no exception should bubble up //unset($tr2); // no exception should bubble up \Phake::verify($this->drv)->savepointUndo(1); //\Phake::verify($this->drv)->savepointUndo(2); } }