1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* (c) Christian Gripp <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Core23\MenuBundle\Tests\Provider; |
11
|
|
|
|
12
|
|
|
use Core23\MenuBundle\Menu\ConfigBuilderInterface; |
13
|
|
|
use Core23\MenuBundle\Provider\ConfigProvider; |
14
|
|
|
use InvalidArgumentException; |
15
|
|
|
use Knp\Menu\ItemInterface; |
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
|
18
|
|
|
class ConfigProviderTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
private $configBuilder; |
21
|
|
|
|
22
|
|
|
protected function setUp(): void |
23
|
|
|
{ |
24
|
|
|
$this->configBuilder = $this->prophesize(ConfigBuilderInterface::class); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testGet(): void |
28
|
|
|
{ |
29
|
|
|
$menu = $this->prophesize(ItemInterface::class); |
30
|
|
|
|
31
|
|
|
$this->configBuilder->buildMenu(['name' => 'foo'], ['a' => 'b'])->willReturn($menu); |
32
|
|
|
|
33
|
|
|
$configProvider = new ConfigProvider($this->configBuilder->reveal(), [ |
34
|
|
|
'foo' => ['name' => 'foo'], |
35
|
|
|
'bar' => ['name' => 'bar'], |
36
|
|
|
]); |
37
|
|
|
$this->assertSame($menu->reveal(), $configProvider->get('foo', ['a' => 'b'])); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
View Code Duplication |
public function testGetDoesNotExist(): void |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
$this->expectException(InvalidArgumentException::class); |
43
|
|
|
|
44
|
|
|
$configProvider = new ConfigProvider($this->configBuilder->reveal(), [ |
45
|
|
|
'foo' => ['name' => 'foo'], |
46
|
|
|
'bar' => ['name' => 'bar'], |
47
|
|
|
]); |
48
|
|
|
$configProvider->get('baz'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
View Code Duplication |
public function testHas(): void |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$configProvider = new ConfigProvider($this->configBuilder->reveal(), [ |
54
|
|
|
'foo' => ['name' => 'foo'], |
55
|
|
|
'bar' => ['name' => 'bar'], |
56
|
|
|
]); |
57
|
|
|
|
58
|
|
|
$this->assertTrue($configProvider->has('foo')); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
View Code Duplication |
public function testHasNot(): void |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$configProvider = new ConfigProvider($this->configBuilder->reveal(), [ |
64
|
|
|
'foo' => ['name' => 'foo'], |
65
|
|
|
'bar' => ['name' => 'bar'], |
66
|
|
|
]); |
67
|
|
|
|
68
|
|
|
$this->assertFalse($configProvider->has('baz')); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.