Skip to content

Commit

Permalink
EZP-32164: Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
webhdx committed Nov 17, 2020
1 parent 51614da commit d2efa7b
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 4 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
},
"autoload-dev": {
"psr-4": {
"EzSystems\\Tests\\EzPlatformCoreBundle\\": "tests/EzPlatformCoreBundle/bundle/"
"EzSystems\\Tests\\EzPlatformCoreBundle\\": "tests/EzPlatformCoreBundle/bundle/",
"Ibexa\\Platform\\Tests\\Assets\\": "tests/IbexaPlatformAssetsBundle/lib/"
}
},
"require": {
Expand Down
13 changes: 10 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
convertWarningsToExceptions="true"
beStrictAboutTestsThatDoNotTestAnything="true"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
</php>
<testsuite name="EzPlatformCoreBundle">
<directory>tests/EzPlatformCoreBundle/bundle</directory>
</testsuite>
<testsuites>
<testsuite name="EzPlatformCoreBundle">
<directory>tests/EzPlatformCoreBundle/bundle</directory>
</testsuite>
<testsuite name="IbexaPlatformAssetsBundle">
<directory>tests/IbexaPlatformAssetsBundle/bundle</directory>
<directory>tests/IbexaPlatformAssetsBundle/lib</directory>
</testsuite>
</testsuites>
</phpunit>
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Platform\Tests\Assets\Resolver;

use eZ\Publish\Core\MVC\ConfigResolverInterface;
use Ibexa\Platform\Assets\Resolver\IconPathResolver;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\Packages;

final class IconPathResolverTest extends TestCase
{
/** @var \eZ\Publish\Core\MVC\ConfigResolverInterface|\PHPUnit\Framework\MockObject\MockObject */
private $configResolver;

/** @var \PHPUnit\Framework\MockObject\MockObject|\Symfony\Component\Asset\Packages */
private $packages;

public function setUp(): void
{
$config = $this->getDefaultConfig();

$this->configResolver = $this->getConfigResolverMock($config);
$this->packages = $this->getPackagesMock($config);
}

/**
* @dataProvider testResolveDataProvider
*/
public function testResolve(string $icon, ?string $set, string $expectedPath): void
{
$iconPathResolver = new IconPathResolver($this->configRes, $packages);

self::assertEquals($expectedPath, $iconPathResolver->resolve($icon, $set));
}

public function testResolveDataProvider()
{
return [
[
'bookmark',
'my_icon_set',
'/bundles/mybundle/my-icons.svg#bookmark',
],
[
'folder',
null,
'/bundles/mybundle/my-icons.svg#folder',
],
[
'bookmark',
'my_other_icon_set',
'/bundles/my_other_icon_set/my-other-icons.svg#bookmark',
],
];
}

private function getDefaultConfig(): array
{
return [
'icon_sets' => [
'my_icon_set' => '/bundles/mybundle/my-icons.svg',
'my_other_icon_set' => '/bundles/my_other_icon_set/my-other-icons.svg',
],
'default_icon_set' => 'my_icon_set',
];
}

private function getConfigResolverMock(array $config): ConfigResolverInterface
{
$configResolver = $this->createMock(ConfigResolverInterface::class);
$configResolver->method('getParameter')->willReturnMap([
['assets.icon_sets', null, null, $config['icon_sets']],
['assets.default_icon_set', null, null, $config['default_icon_set']],
]);

return $configResolver;
}

private function getPackagesMock(array $config): Packages
{
$packages = $this->createMock(Packages::class);
$packages->method('getUrl')->willReturnMap([
[$config['icon_sets']['my_icon_set'], null, $config['icon_sets']['my_icon_set']],
[$config['icon_sets']['my_other_icon_set'], null, $config['icon_sets']['my_other_icon_set']],
]);

return $packages;
}
}

0 comments on commit d2efa7b

Please # to comment.