Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
20.43% |
19 / 93 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_attachment_manager_test | |
20.43% |
19 / 93 |
|
75.00% |
3 / 4 |
12.06 | |
0.00% |
0 / 1 |
| setUp | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
| get_manager | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| data_manager | |
0.00% |
0 / 74 |
|
0.00% |
0 / 1 |
2 | |||
| test_manager | |
100.00% |
6 / 6 |
|
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_attachment_manager_test extends \phpbb_test_case |
| 15 | { |
| 16 | protected $delete; |
| 17 | protected $resync; |
| 18 | protected $upload; |
| 19 | |
| 20 | protected function setUp(): void |
| 21 | { |
| 22 | $this->delete = $this->getMockBuilder('\phpbb\attachment\delete') |
| 23 | ->disableOriginalConstructor() |
| 24 | ->onlyMethods(['delete', 'unlink_attachment']) |
| 25 | ->getMock(); |
| 26 | $this->resync = $this->getMockBuilder('\phpbb\attachment\resync') |
| 27 | ->disableOriginalConstructor() |
| 28 | ->onlyMethods(['resync']) |
| 29 | ->getMock(); |
| 30 | $this->upload = $this->getMockBuilder('\phpbb\attachment\upload') |
| 31 | ->disableOriginalConstructor() |
| 32 | ->onlyMethods(['upload']) |
| 33 | ->getMock(); |
| 34 | } |
| 35 | |
| 36 | protected function get_manager() |
| 37 | { |
| 38 | return new \phpbb\attachment\manager($this->delete, $this->resync, $this->upload); |
| 39 | } |
| 40 | |
| 41 | public static function data_manager() |
| 42 | { |
| 43 | return array( |
| 44 | array( |
| 45 | 'delete', |
| 46 | 'unlink_attachment', |
| 47 | 'unlink', |
| 48 | ['foo'], |
| 49 | ['foo', 'file', false], |
| 50 | true, |
| 51 | true, |
| 52 | ), |
| 53 | array( |
| 54 | 'delete', |
| 55 | 'unlink_attachment', |
| 56 | 'unlink', |
| 57 | ['foo', 'bar'], |
| 58 | ['foo', 'bar', false], |
| 59 | true, |
| 60 | true, |
| 61 | ), |
| 62 | array( |
| 63 | 'delete', |
| 64 | 'unlink_attachment', |
| 65 | 'unlink', |
| 66 | ['foo', 'bar', true], |
| 67 | ['foo', 'bar', true], |
| 68 | true, |
| 69 | true, |
| 70 | ), |
| 71 | array( |
| 72 | 'delete', |
| 73 | 'delete', |
| 74 | 'delete', |
| 75 | ['foo', [1, 2, 3]], |
| 76 | ['foo', [1, 2, 3], true], |
| 77 | 5, |
| 78 | 5, |
| 79 | ), |
| 80 | array( |
| 81 | 'delete', |
| 82 | 'delete', |
| 83 | 'delete', |
| 84 | ['foo', [1, 2, 3], false], |
| 85 | ['foo', [1, 2, 3], false], |
| 86 | 2, |
| 87 | 2, |
| 88 | ), |
| 89 | array( |
| 90 | 'resync', |
| 91 | 'resync', |
| 92 | 'resync', |
| 93 | ['foo', [1, 2, 3]], |
| 94 | ['foo', [1, 2, 3]], |
| 95 | true, |
| 96 | null, |
| 97 | ), |
| 98 | array( |
| 99 | 'upload', |
| 100 | 'upload', |
| 101 | 'upload', |
| 102 | ['foo', 1], |
| 103 | ['foo', 1, false, '', false, []], |
| 104 | true, |
| 105 | true, |
| 106 | ), |
| 107 | array( |
| 108 | 'upload', |
| 109 | 'upload', |
| 110 | 'upload', |
| 111 | ['foo', 1, true, 'bar', true, ['filename' => 'foobar']], |
| 112 | ['foo', 1, true, 'bar', true, ['filename' => 'foobar']], |
| 113 | true, |
| 114 | true, |
| 115 | ), |
| 116 | ); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * @dataProvider data_manager |
| 121 | */ |
| 122 | public function test_manager($class, $method_class, $method_manager, $input_manager, $input_method, $return, $output) |
| 123 | { |
| 124 | $mock = call_user_func_array([$this->{$class}, 'expects'], [$this->atLeastOnce()]); |
| 125 | $mock = $mock->method($method_class); |
| 126 | $mock = call_user_func_array([$mock, 'with'], $input_method); |
| 127 | $mock->willReturn($return); |
| 128 | $manager = $this->get_manager(); |
| 129 | $this->assertSame($output, call_user_func_array([$manager, $method_manager], $input_manager)); |
| 130 | } |
| 131 | } |