Test Setup Failed
Push — master ( 195648...185a1e )
by Craig
58s queued 15s
created

ExtensionMenuCollectorTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 38
c 1
b 0
f 1
dl 0
loc 85
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testGet() 0 4 2
A menuProvider() 0 8 1
A testAdd() 0 8 1
A testHas() 0 6 1
A setUp() 0 15 1
A allMenusProvider() 0 7 1
A testGetAllByType() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula Foundation - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\MenuModule\Tests\ExtensionMenu;
15
16
use Knp\Menu\MenuFactory;
17
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
19
use Zikula\MenuModule\ExtensionMenu\ExtensionMenuCollector;
20
use Zikula\MenuModule\ExtensionMenu\ExtensionMenuEvent;
21
use Zikula\MenuModule\ExtensionMenu\ExtensionMenuInterface;
22
use Zikula\MenuModule\Tests\ExtensionMenu\Fixtures\BarExtensionMenu;
23
use Zikula\MenuModule\Tests\ExtensionMenu\Fixtures\FooExtensionMenu;
24
25
class ExtensionMenuCollectorTest extends TestCase
26
{
27
    /**
28
     * @var ExtensionMenuCollector
29
     */
30
    private $collector;
31
32
    protected function setUp(): void
33
    {
34
        $dispatcher = $this
35
            ->getMockBuilder(EventDispatcherInterface::class)
36
            ->disableOriginalConstructor()
37
            ->getMock();
38
        $dispatcher
39
            ->method('dispatch')
40
            ->with($this->isInstanceOf(ExtensionMenuEvent::class), $this->anything())
41
            ->will($this->returnArgument(0));
42
        $this->collector = new ExtensionMenuCollector($dispatcher, []);
43
44
        $factory = new MenuFactory();
45
        $this->collector->add(new FooExtensionMenu($factory));
46
        $this->collector->add(new BarExtensionMenu($factory));
47
    }
48
49
    /**
50
     * @covers ExtensionMenuCollector::add
51
     */
52
    public function testAdd(): void
53
    {
54
        $menu = $this->getMockBuilder(ExtensionMenuInterface::class)->getMock();
55
        $menu
56
            ->method('getBundleName')
57
            ->willReturn('MockExtension');
58
        $this->collector->add($menu);
59
        $this->assertTrue($this->collector->has('MockExtension'));
60
    }
61
62
    /**
63
     * @covers ExtensionMenuCollector::has
64
     */
65
    public function testHas(): void
66
    {
67
        $this->assertTrue($this->collector->has('ZikulaFooExtension'));
68
        $this->assertTrue($this->collector->has('ZikulaBarExtension'));
69
        $this->assertFalse($this->collector->has('ZikulaFazExtension'));
70
        $this->assertFalse($this->collector->has('ZikulaBazExtension'));
71
    }
72
73
    /**
74
     * @covers ExtensionMenuCollector::get
75
     * @dataProvider menuProvider
76
     */
77
    public function testGet(string $extension, string $type, int $count): void
78
    {
79
        $menu = $this->collector->get($extension, $type);
80
        $this->assertEquals($count, $menu ? $menu->count() : 0);
81
    }
82
83
    public function menuProvider(): array
84
    {
85
        return [
86
            ['Unknown Extension', ExtensionMenuInterface::TYPE_ADMIN, 0],
87
            ['ZikulaFooExtension', 'UnknownType', 0],
88
            ['ZikulaFooExtension', ExtensionMenuInterface::TYPE_ADMIN, 3],
89
            ['ZikulaFooExtension', ExtensionMenuInterface::TYPE_USER, 1],
90
            ['ZikulaBarExtension', 'bar', 1],
91
        ];
92
    }
93
94
    /**
95
     * @covers ExtensionMenuCollector::getAllByType
96
     * @dataProvider allMenusProvider
97
     */
98
    public function testGetAllByType(string $type, array $expected = []): void
99
    {
100
        $this->assertEquals($expected, array_keys($this->collector->getAllByType($type)));
101
    }
102
103
    public function allMenusProvider(): array
104
    {
105
        return [
106
            [ExtensionMenuInterface::TYPE_ACCOUNT, ['ZikulaBarExtension']],
107
            [ExtensionMenuInterface::TYPE_USER, ['ZikulaFooExtension', 'ZikulaBarExtension']],
108
            [ExtensionMenuInterface::TYPE_ADMIN, ['ZikulaFooExtension']],
109
            ['bar', ['ZikulaBarExtension']],
110
        ];
111
    }
112
}
113