Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_lock_posting_test | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| setUp | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_lock_acquire | |
100.00% |
11 / 11 |
|
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 | use phpbb\cache\driver\file as file_cache; |
| 15 | use phpbb\config\config; |
| 16 | use phpbb\lock\posting; |
| 17 | |
| 18 | class phpbb_lock_posting_test extends phpbb_test_case |
| 19 | { |
| 20 | /** @var \phpbb\cache\driver\file */ |
| 21 | protected $cache; |
| 22 | |
| 23 | /** @var config */ |
| 24 | protected $config; |
| 25 | |
| 26 | /** @var posting */ |
| 27 | protected $lock; |
| 28 | |
| 29 | public function setUp(): void |
| 30 | { |
| 31 | $this->cache = new file_cache(__DIR__ . '/../tmp/'); |
| 32 | $this->cache->purge(); // ensure cache is clean |
| 33 | $this->config = new config([ |
| 34 | 'flood_interval' => 15, |
| 35 | ]); |
| 36 | $this->lock = new posting($this->cache, $this->config); |
| 37 | } |
| 38 | |
| 39 | public function test_lock_acquire() |
| 40 | { |
| 41 | $this->assertTrue($this->lock->acquire(100, 'foo')); |
| 42 | $this->assertFalse($this->lock->acquire(100, 'foo')); |
| 43 | |
| 44 | $this->assertTrue($this->cache->_exists(sha1('100foo') . '_posting_lock')); |
| 45 | $this->assertFalse($this->lock->acquire(100, 'foo')); |
| 46 | $this->cache->put(sha1('100foo') . '_posting_lock', 'foo', -30); |
| 47 | |
| 48 | $this->assertTrue($this->lock->acquire(100, 'foo')); |
| 49 | $this->assertTrue($this->cache->_exists(sha1('100foo') . '_posting_lock')); |
| 50 | $this->config->offsetSet('ci_tests_no_lock_posting', true); |
| 51 | $this->assertTrue($this->lock->acquire(100, 'foo')); |
| 52 | $this->assertTrue($this->cache->_exists(sha1('100foo') . '_posting_lock')); |
| 53 | // Multiple acquires possible due to special ci test flag |
| 54 | $this->assertTrue($this->lock->acquire(100, 'foo')); |
| 55 | } |
| 56 | } |