|
10 | 10 |
|
11 | 11 | namespace phpbb\ideas\tests; |
12 | 12 |
|
| 13 | +use PHPUnit\Framework\MockObject\MockObject; |
| 14 | +use phpbb\notification\manager; |
| 15 | +use phpbb\finder; |
| 16 | +use phpbb\db\migrator; |
| 17 | +use Symfony\Component\DependencyInjection\ContainerInterface; |
| 18 | +use phpbb\ideas\ext; |
| 19 | + |
13 | 20 | class ext_test extends \phpbb_test_case |
14 | 21 | { |
15 | | - public function test_ext() |
| 22 | + /** @var ext */ |
| 23 | + private $ext; |
| 24 | + |
| 25 | + /** @var MockObject|manager */ |
| 26 | + private $notification_manager; |
| 27 | + |
| 28 | + /** @var MockObject|ContainerInterface */ |
| 29 | + private $container; |
| 30 | + |
| 31 | + /** @var MockObject|finder */ |
| 32 | + private $extension_finder; |
| 33 | + |
| 34 | + /** @var MockObject|migrator */ |
| 35 | + private $migrator; |
| 36 | + |
| 37 | + protected function setUp(): void |
16 | 38 | { |
17 | | - /** @var \PHPUnit\Framework\MockObject\MockObject|\Symfony\Component\DependencyInjection\ContainerInterface $container */ |
18 | | - $container = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') |
19 | | - ->disableOriginalConstructor() |
20 | | - ->getMock(); |
21 | | - |
22 | | - /** @var \PHPUnit\Framework\MockObject\MockObject|\phpbb\finder $extension_finder */ |
23 | | - $extension_finder = $this->getMockBuilder('\phpbb\finder') |
24 | | - ->disableOriginalConstructor() |
25 | | - ->getMock(); |
26 | | - |
27 | | - /** @var \PHPUnit\Framework\MockObject\MockObject|\phpbb\db\migrator $migrator */ |
28 | | - $migrator = $this->getMockBuilder('\phpbb\db\migrator') |
29 | | - ->disableOriginalConstructor() |
30 | | - ->getMock(); |
31 | | - |
32 | | - $ext = new \phpbb\ideas\ext( |
33 | | - $container, |
34 | | - $extension_finder, |
35 | | - $migrator, |
| 39 | + parent::setUp(); |
| 40 | + $this->initialize_mocks(); |
| 41 | + $this->create_extension(); |
| 42 | + } |
| 43 | + |
| 44 | + private function initialize_mocks(): void |
| 45 | + { |
| 46 | + $this->notification_manager = $this->createMock(manager::class); |
| 47 | + $this->container = $this->createMock(ContainerInterface::class); |
| 48 | + $this->extension_finder = $this->createMock(finder::class); |
| 49 | + $this->migrator = $this->createMock(migrator::class); |
| 50 | + } |
| 51 | + |
| 52 | + private function create_extension(): void |
| 53 | + { |
| 54 | + $this->ext = new ext( |
| 55 | + $this->container, |
| 56 | + $this->extension_finder, |
| 57 | + $this->migrator, |
36 | 58 | 'phpbb/ideas', |
37 | 59 | '' |
38 | 60 | ); |
| 61 | + } |
39 | 62 |
|
40 | | - self::assertTrue($ext->is_enableable()); |
| 63 | + private function setup_notification_manager(string $method): void |
| 64 | + { |
| 65 | + $this->container->expects($this->once()) |
| 66 | + ->method('get') |
| 67 | + ->with('notification_manager') |
| 68 | + ->willReturn($this->notification_manager); |
| 69 | + |
| 70 | + $this->notification_manager->expects($this->once()) |
| 71 | + ->method($method) |
| 72 | + ->with('phpbb.ideas.notification.type.status'); |
| 73 | + } |
| 74 | + |
| 75 | + public function test_is_enableable(): void |
| 76 | + { |
| 77 | + $this->assertTrue($this->ext->is_enableable()); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * @dataProvider notification_step_provider |
| 82 | + */ |
| 83 | + public function test_notification_steps(string $method, string $step): void |
| 84 | + { |
| 85 | + $this->setup_notification_manager($method); |
| 86 | + |
| 87 | + $state = $this->ext->$step(false); |
| 88 | + $this->assertEquals('notification', $state); |
| 89 | + } |
| 90 | + |
| 91 | + public function notification_step_provider(): array |
| 92 | + { |
| 93 | + return [ |
| 94 | + 'enable step' => ['enable_notifications', 'enable_step'], |
| 95 | + 'disable step' => ['disable_notifications', 'disable_step'], |
| 96 | + 'purge step' => ['purge_notifications', 'purge_step'] |
| 97 | + ]; |
41 | 98 | } |
42 | 99 | } |
0 commit comments