Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
19 / 19 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_storage_adapter_local_test | |
100.00% |
19 / 19 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| setUp | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_delete_file | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| test_read | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_write | |
100.00% |
7 / 7 |
|
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 | require_once __DIR__ . '/local_test_case.php'; |
| 15 | |
| 16 | class phpbb_storage_adapter_local_test extends phpbb_local_test_case |
| 17 | { |
| 18 | protected function setUp(): void |
| 19 | { |
| 20 | parent::setUp(); |
| 21 | |
| 22 | $this->adapter->configure(['path' => 'test_path']); |
| 23 | } |
| 24 | |
| 25 | public function test_delete_file(): void |
| 26 | { |
| 27 | // Given |
| 28 | touch($this->path . 'file.txt'); |
| 29 | $this->assertFileExists($this->path . 'file.txt'); |
| 30 | |
| 31 | // When |
| 32 | $this->adapter->delete('file.txt'); |
| 33 | |
| 34 | // Then |
| 35 | $this->assertFileDoesNotExist($this->path . 'file.txt'); |
| 36 | } |
| 37 | |
| 38 | public function test_read() |
| 39 | { |
| 40 | // Given |
| 41 | file_put_contents($this->path . 'file.txt', 'abc'); |
| 42 | |
| 43 | // When |
| 44 | $stream = $this->adapter->read('file.txt'); |
| 45 | |
| 46 | // Then |
| 47 | $this->assertIsResource($stream); |
| 48 | $this->assertEquals('abc', stream_get_contents($stream)); |
| 49 | |
| 50 | // Clean test |
| 51 | fclose($stream); |
| 52 | unlink($this->path . 'file.txt'); |
| 53 | } |
| 54 | |
| 55 | public function test_write() |
| 56 | { |
| 57 | // Given |
| 58 | file_put_contents($this->path . 'file.txt', 'abc'); |
| 59 | $stream = fopen($this->path . 'file.txt', 'rb'); |
| 60 | |
| 61 | // When |
| 62 | $this->adapter->write('file2.txt', $stream); |
| 63 | fclose($stream); |
| 64 | |
| 65 | // Then |
| 66 | $this->assertFileContains($this->path . 'file2.txt', 'abc'); |
| 67 | |
| 68 | // Clean test |
| 69 | unlink($this->path . 'file.txt'); |
| 70 | unlink($this->path . 'file2.txt'); |
| 71 | } |
| 72 | } |