1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-24 17:42:40 +00:00
Arsse/tests/cases/Db/TestTransaction.php

62 lines
2.1 KiB
PHP
Raw Normal View History

<?php
/** @license MIT
* Copyright 2017 J. King, Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
2017-12-22 03:47:19 +00:00
namespace JKingWeb\Arsse\TestCase\Db;
2017-08-29 14:50:31 +00:00
use JKingWeb\Arsse\Db\Transaction;
2017-12-22 03:47:19 +00:00
use JKingWeb\Arsse\Db\Exception;
2017-08-29 15:16:37 +00:00
/**
* @covers \JKingWeb\Arsse\Db\Transaction */
2017-12-22 03:47:19 +00:00
class TestTransaction extends \JKingWeb\Arsse\Test\AbstractTest {
protected $drv;
2017-08-29 14:50:31 +00:00
public function setUp() {
2018-11-23 15:01:17 +00:00
self::clearData();
2019-09-05 14:03:32 +00:00
$drv = \Phake::mock(\JKingWeb\Arsse\Db\SQLite3\Driver::class);
\Phake::when($drv)->savepointRelease->thenReturn(true);
\Phake::when($drv)->savepointUndo->thenReturn(true);
\Phake::when($drv)->savepointCreate->thenReturn(1)->thenReturn(2);
$this->drv = $drv;
}
2017-08-29 14:50:31 +00:00
public function testManipulateTransactions() {
$tr1 = new Transaction($this->drv);
$tr2 = new Transaction($this->drv);
2019-09-05 14:03:32 +00:00
\Phake::verify($this->drv, \Phake::times(2))->savepointCreate;
$this->assertSame(1, $tr1->getIndex());
$this->assertSame(2, $tr2->getIndex());
unset($tr1);
2019-09-05 14:03:32 +00:00
\Phake::verify($this->drv)->savepointUndo(1);
unset($tr2);
2019-09-05 14:03:32 +00:00
\Phake::verify($this->drv)->savepointUndo(2);
}
2017-08-29 14:50:31 +00:00
public function testCloseTransactions() {
$tr1 = new Transaction($this->drv);
$tr2 = new Transaction($this->drv);
$this->assertTrue($tr1->isPending());
$this->assertTrue($tr2->isPending());
$tr1->commit();
$this->assertFalse($tr1->isPending());
$this->assertTrue($tr2->isPending());
2019-09-05 14:03:32 +00:00
\Phake::verify($this->drv)->savepointRelease(1);
$tr2->rollback();
$this->assertFalse($tr1->isPending());
$this->assertFalse($tr2->isPending());
2019-09-05 14:03:32 +00:00
\Phake::verify($this->drv)->savepointUndo(2);
}
2017-08-29 14:50:31 +00:00
public function testIgnoreRollbackErrors() {
2019-09-05 14:03:32 +00:00
\Phake::when($this->drv)->savepointUndo->thenThrow(new Exception("savepointStale"));
$tr1 = new Transaction($this->drv);
$tr2 = new Transaction($this->drv);
unset($tr1, $tr2); // no exception should bubble up
2019-09-05 14:03:32 +00:00
\Phake::verify($this->drv)->savepointUndo(1);
\Phake::verify($this->drv)->savepointUndo(2);
}
2017-08-29 14:50:31 +00:00
}