Completed
Push — EZP-31267-io-config-resolver ( f10ddb )
by
unknown
18:38
created

IOConfigResolverTest::testGetRootDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 29
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 29
loc 29
rs 9.456
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Bundle\EzPublishCoreBundle\Tests\SiteAccess\Config;
10
11
use eZ\Bundle\EzPublishCoreBundle\SiteAccess\Config\ComplexConfigProcessor;
12
use eZ\Bundle\EzPublishCoreBundle\SiteAccess\Config\IOConfigResolver;
13
use eZ\Publish\Core\MVC\ConfigResolverInterface;
14
use eZ\Publish\Core\MVC\Symfony\SiteAccess;
15
use eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessService;
16
use PHPUnit\Framework\TestCase;
17
18
class IOConfigResolverTest extends TestCase
19
{
20
    /** @var \eZ\Publish\Core\MVC\ConfigResolverInterface|\PHPUnit\Framework\MockObject\MockObject */
21
    private $configResolver;
22
23
    /** @var \eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessService|\PHPUnit\Framework\MockObject\MockObject */
24
    private $siteAccessService;
25
26
    protected function setUp(): void
27
    {
28
        parent::setUp();
29
        $this->configResolver = $this->createMock(ConfigResolverInterface::class);
30
        $this->siteAccessService = $this->createMock(SiteAccessService::class);
31
    }
32
33
    /**
34
     * @covers \eZ\Bundle\EzPublishCoreBundle\SiteAccess\Config\IOConfigResolver::getUrlPrefix
35
     */
36 View Code Duplication
    public function testGetUrlPrefix(): void
37
    {
38
        $this->siteAccessService
39
            ->method('getCurrent')
40
            ->willReturn(new SiteAccess('ezdemo_site'));
41
42
        $this->configResolver
43
            ->method('hasParameter')
44
            ->with('io.url_prefix', null, 'ezdemo_site')
45
            ->willReturn(true);
46
        $this->configResolver
47
            ->method('getParameter')
48
            ->willReturnMap([
49
                ['io.url_prefix', null, 'ezdemo_site', '$var_dir$/ezdemo_site/$storage_dir$'],
50
                ['var_dir', 'ezsettings', 'ezdemo_site', 'var'],
51
                ['storage_dir', 'ezsettings', 'ezdemo_site', 'storage'],
52
            ]);
53
54
        $complexConfigProcessor = new ComplexConfigProcessor(
55
            $this->configResolver,
0 ignored issues
show
Bug introduced by
It seems like $this->configResolver can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, eZ\Bundle\EzPublishCoreB...rocessor::__construct() does only seem to accept object<eZ\Publish\Core\M...onfigResolverInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
56
            $this->siteAccessService
0 ignored issues
show
Bug introduced by
It seems like $this->siteAccessService can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, eZ\Bundle\EzPublishCoreB...rocessor::__construct() does only seem to accept object<eZ\Publish\Core\M...cess\SiteAccessService>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
57
        );
58
59
        $ioConfigResolver = new IOConfigResolver(
60
            $complexConfigProcessor
61
        );
62
63
        $this->assertEquals('var/ezdemo_site/storage', $ioConfigResolver->getUrlPrefix());
64
    }
65
66
    /**
67
     * @covers \eZ\Bundle\EzPublishCoreBundle\SiteAccess\Config\IOConfigResolver::getUrlPrefix
68
     */
69 View Code Duplication
    public function testGetLegacyUrlPrefix(): void
70
    {
71
        $this->siteAccessService
72
            ->method('getCurrent')
73
            ->willReturn(new SiteAccess('ezdemo_site'));
74
75
        $this->configResolver
76
            ->method('hasParameter')
77
            ->with('io.legacy_url_prefix', null, 'ezdemo_site')
78
            ->willReturn(true);
79
        $this->configResolver
80
            ->method('getParameter')
81
            ->willReturnMap([
82
                ['io.legacy_url_prefix', null, 'ezdemo_site', '$var_dir$/ezdemo_site/$storage_dir$'],
83
                ['var_dir', 'ezsettings', 'ezdemo_site', 'var'],
84
                ['storage_dir', 'ezsettings', 'ezdemo_site', 'legacy_storage'],
85
            ]);
86
87
        $complexConfigProcessor = new ComplexConfigProcessor(
88
            $this->configResolver,
0 ignored issues
show
Bug introduced by
It seems like $this->configResolver can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, eZ\Bundle\EzPublishCoreB...rocessor::__construct() does only seem to accept object<eZ\Publish\Core\M...onfigResolverInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
89
            $this->siteAccessService
0 ignored issues
show
Bug introduced by
It seems like $this->siteAccessService can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, eZ\Bundle\EzPublishCoreB...rocessor::__construct() does only seem to accept object<eZ\Publish\Core\M...cess\SiteAccessService>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
90
        );
91
92
        $ioConfigResolver = new IOConfigResolver(
93
            $complexConfigProcessor
94
        );
95
96
        $this->assertEquals('var/ezdemo_site/legacy_storage', $ioConfigResolver->getLegacyUrlPrefix());
97
    }
98
99
    /**
100
     * @covers \eZ\Bundle\EzPublishCoreBundle\SiteAccess\Config\IOConfigResolver::getUrlPrefix
101
     */
102 View Code Duplication
    public function testGetRootDir(): void
103
    {
104
        $this->siteAccessService
105
            ->method('getCurrent')
106
            ->willReturn(new SiteAccess('ezdemo_site'));
107
108
        $this->configResolver
109
            ->method('hasParameter')
110
            ->with('io.root_dir', null, 'ezdemo_site')
111
            ->willReturn(true);
112
        $this->configResolver
113
            ->method('getParameter')
114
            ->willReturnMap([
115
                ['io.root_dir', null, 'ezdemo_site', '/path/to/ezpublish/web/$var_dir$/ezdemo_site/$storage_dir$'],
116
                ['var_dir', 'ezsettings', 'ezdemo_site', 'var'],
117
                ['storage_dir', 'ezsettings', 'ezdemo_site', 'legacy_storage'],
118
            ]);
119
120
        $complexConfigProcessor = new ComplexConfigProcessor(
121
            $this->configResolver,
0 ignored issues
show
Bug introduced by
It seems like $this->configResolver can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, eZ\Bundle\EzPublishCoreB...rocessor::__construct() does only seem to accept object<eZ\Publish\Core\M...onfigResolverInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
122
            $this->siteAccessService
0 ignored issues
show
Bug introduced by
It seems like $this->siteAccessService can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, eZ\Bundle\EzPublishCoreB...rocessor::__construct() does only seem to accept object<eZ\Publish\Core\M...cess\SiteAccessService>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
123
        );
124
125
        $ioConfigResolver = new IOConfigResolver(
126
            $complexConfigProcessor
127
        );
128
129
        $this->assertEquals('/path/to/ezpublish/web/var/ezdemo_site/legacy_storage', $ioConfigResolver->getRootDir());
130
    }
131
}
132