Skip to content

Commit 3c8c3b6

Browse files
committed
Update some tests
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent 0a0e5db commit 3c8c3b6

1 file changed

Lines changed: 78 additions & 21 deletions

File tree

tests/ext_test.php

Lines changed: 78 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,90 @@
1010

1111
namespace phpbb\ideas\tests;
1212

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+
1320
class ext_test extends \phpbb_test_case
1421
{
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
1638
{
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,
3658
'phpbb/ideas',
3759
''
3860
);
61+
}
3962

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+
];
4198
}
4299
}

0 commit comments

Comments
 (0)