Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to lock a table before and after the database transaction.
- Loading branch information
Nick Bedford
committed
Sep 23, 2021
1 parent
62bc7c3
commit 0ae66aa
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** @noinspection PhpUnhandledExceptionInspection */ | ||
|
||
namespace YetAnother\Tests; | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
use YetAnother\Tests\Transactions\TableLockTransaction; | ||
|
||
class TableLockTransactonTests extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Schema::create(TableLockTransaction::TableName, function(Blueprint $table) | ||
{ | ||
$table->integer('a'); | ||
$table->integer('b'); | ||
$table->integer('c'); | ||
}); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
Schema::drop(TableLockTransaction::TableName); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
function testLockedTableInsertDoesNotThrow() | ||
{ | ||
(new TableLockTransaction())->execute(); | ||
|
||
/** @noinspection SqlNoDataSourceInspection */ | ||
$row = DB::selectOne('SELECT * FROM `' . TableLockTransaction::TableName . '`'); | ||
|
||
$this->assertEquals(1, $row->a); | ||
$this->assertEquals(2, $row->b); | ||
$this->assertEquals(3, $row->c); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
namespace YetAnother\Tests\Transactions; | ||
|
||
use Illuminate\Support\Facades\DB; | ||
use YetAnother\Laravel\Transaction; | ||
|
||
class TableLockTransaction extends Transaction | ||
{ | ||
const TableName = 'LockedTable'; | ||
|
||
public function __construct() | ||
{ | ||
$this->lockTableName = self::TableName; | ||
} | ||
|
||
protected function perform(): void | ||
{ | ||
/** @noinspection SqlNoDataSourceInspection */ | ||
DB::insert("INSERT INTO `$this->lockTableName` VALUES(1, 2, 3)"); | ||
} | ||
} |