Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
43 / 43 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_lock_db_test | |
100.00% |
43 / 43 |
|
100.00% |
6 / 6 |
6 | |
100.00% |
1 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setUp | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| test_new_lock | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| test_expire_lock | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_double_lock | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| test_double_unlock | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | class phpbb_lock_db_test extends phpbb_database_test_case |
| 15 | { |
| 16 | private $db; |
| 17 | private $config; |
| 18 | private $lock; |
| 19 | |
| 20 | public function getDataSet() |
| 21 | { |
| 22 | return $this->createXMLDataSet(__DIR__.'/fixtures/config.xml'); |
| 23 | } |
| 24 | |
| 25 | protected function setUp(): void |
| 26 | { |
| 27 | global $db, $config; |
| 28 | |
| 29 | $db = $this->db = $this->new_dbal(); |
| 30 | $config = $this->config = new \phpbb\config\config(array('rand_seed' => '', 'rand_seed_last_update' => '0')); |
| 31 | $this->lock = new \phpbb\lock\db('test_lock', $this->config, $this->db); |
| 32 | } |
| 33 | |
| 34 | public function test_new_lock() |
| 35 | { |
| 36 | $this->assertFalse($this->lock->owns_lock()); |
| 37 | |
| 38 | $this->assertTrue($this->lock->acquire()); |
| 39 | $this->assertTrue($this->lock->owns_lock()); |
| 40 | $this->assertTrue(isset($this->config['test_lock']), 'Lock was created'); |
| 41 | |
| 42 | $lock2 = new \phpbb\lock\db('test_lock', $this->config, $this->db); |
| 43 | $this->assertFalse($lock2->acquire()); |
| 44 | $this->assertFalse($lock2->owns_lock()); |
| 45 | |
| 46 | $this->lock->release(); |
| 47 | $this->assertFalse($this->lock->owns_lock()); |
| 48 | $this->assertEquals('0', $this->config['test_lock'], 'Lock was released'); |
| 49 | } |
| 50 | |
| 51 | public function test_expire_lock() |
| 52 | { |
| 53 | $lock = new \phpbb\lock\db('foo_lock', $this->config, $this->db); |
| 54 | $this->assertTrue($lock->acquire()); |
| 55 | } |
| 56 | |
| 57 | public function test_double_lock() |
| 58 | { |
| 59 | $this->assertFalse($this->lock->owns_lock()); |
| 60 | |
| 61 | $this->assertTrue($this->lock->acquire()); |
| 62 | $this->assertTrue($this->lock->owns_lock()); |
| 63 | $this->assertTrue(isset($this->config['test_lock']), 'Lock was created'); |
| 64 | |
| 65 | $value = $this->config['test_lock']; |
| 66 | |
| 67 | $this->assertFalse($this->lock->acquire()); |
| 68 | $this->assertTrue($this->lock->owns_lock()); |
| 69 | $this->assertEquals($value, $this->config['test_lock'], 'Second lock failed'); |
| 70 | |
| 71 | $this->lock->release(); |
| 72 | $this->assertFalse($this->lock->owns_lock()); |
| 73 | $this->assertEquals('0', $this->config['test_lock'], 'Lock was released'); |
| 74 | } |
| 75 | |
| 76 | public function test_double_unlock() |
| 77 | { |
| 78 | $this->assertTrue($this->lock->acquire()); |
| 79 | $this->assertTrue($this->lock->owns_lock()); |
| 80 | $this->assertFalse(empty($this->config['test_lock']), 'First lock is acquired'); |
| 81 | |
| 82 | $this->lock->release(); |
| 83 | $this->assertFalse($this->lock->owns_lock()); |
| 84 | $this->assertEquals('0', $this->config['test_lock'], 'First lock is released'); |
| 85 | |
| 86 | $lock2 = new \phpbb\lock\db('test_lock', $this->config, $this->db); |
| 87 | $this->assertTrue($lock2->acquire()); |
| 88 | $this->assertTrue($lock2->owns_lock()); |
| 89 | $this->assertFalse(empty($this->config['test_lock']), 'Second lock is acquired'); |
| 90 | |
| 91 | $this->lock->release(); |
| 92 | $this->assertTrue($lock2->owns_lock()); |
| 93 | $this->assertFalse(empty($this->config['test_lock']), 'Double release of first lock is ignored'); |
| 94 | |
| 95 | $lock2->release(); |
| 96 | $this->assertEquals('0', $this->config['test_lock'], 'Second lock is released'); |
| 97 | } |
| 98 | } |