Completed
Push — qa-cumulative-ezp-31278-31279-... ( f57b9c...05fe70 )
by
unknown
14:35
created

IOConfigResolverTest::testGetRootDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
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
    private const DEFAULT_NAMESPACE = 'ezsettings';
21
22
    /** @var \eZ\Publish\Core\MVC\ConfigResolverInterface|\PHPUnit\Framework\MockObject\MockObject */
23
    private $configResolver;
24
25
    /** @var \eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessService|\PHPUnit\Framework\MockObject\MockObject */
26
    private $siteAccessService;
27
28
    protected function setUp(): void
29
    {
30
        parent::setUp();
31
        $this->configResolver = $this->createMock(ConfigResolverInterface::class);
32
        $this->siteAccessService = $this->createMock(SiteAccessService::class);
33
    }
34
35
    /**
36
     * @covers \eZ\Bundle\EzPublishCoreBundle\SiteAccess\Config\IOConfigResolver::getUrlPrefix
37
     */
38
    public function testGetUrlPrefix(): void
39
    {
40
        $this->siteAccessService
41
            ->method('getCurrent')
42
            ->willReturn(new SiteAccess('ezdemo_site'));
43
44
        $this->configResolver
45
            ->method('hasParameter')
46
            ->with('io.url_prefix', null, 'ezdemo_site')
47
            ->willReturn(true);
48
        $this->configResolver
49
            ->method('getParameter')
50
            ->willReturnMap([
51
                ['io.url_prefix', null, 'ezdemo_site', '$var_dir$/ezdemo_site/$storage_dir$'],
52
                ['var_dir', self::DEFAULT_NAMESPACE, 'ezdemo_site', 'var'],
53
                ['storage_dir', self::DEFAULT_NAMESPACE, 'ezdemo_site', 'storage'],
54
            ]);
55
56
        $complexConfigProcessor = new ComplexConfigProcessor(
57
            $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...
58
            $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...
59
        );
60
61
        $ioConfigResolver = new IOConfigResolver(
62
            $complexConfigProcessor
63
        );
64
65
        $this->assertEquals('var/ezdemo_site/storage', $ioConfigResolver->getUrlPrefix());
66
    }
67
68
    /**
69
     * @covers \eZ\Bundle\EzPublishCoreBundle\SiteAccess\Config\IOConfigResolver::getUrlPrefix
70
     */
71
    public function testGetLegacyUrlPrefix(): void
72
    {
73
        $this->siteAccessService
74
            ->method('getCurrent')
75
            ->willReturn(new SiteAccess('ezdemo_site'));
76
77
        $this->configResolver
78
            ->method('hasParameter')
79
            ->with('io.legacy_url_prefix', null, 'ezdemo_site')
80
            ->willReturn(true);
81
        $this->configResolver
82
            ->method('getParameter')
83
            ->willReturnMap([
84
                ['io.legacy_url_prefix', null, 'ezdemo_site', '$var_dir$/ezdemo_site/$storage_dir$'],
85
                ['var_dir', self::DEFAULT_NAMESPACE, 'ezdemo_site', 'var'],
86
                ['storage_dir', self::DEFAULT_NAMESPACE, 'ezdemo_site', 'legacy_storage'],
87
            ]);
88
89
        $complexConfigProcessor = new ComplexConfigProcessor(
90
            $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...
91
            $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...
92
        );
93
94
        $ioConfigResolver = new IOConfigResolver(
95
            $complexConfigProcessor
96
        );
97
98
        $this->assertEquals('var/ezdemo_site/legacy_storage', $ioConfigResolver->getLegacyUrlPrefix());
99
    }
100
101
    /**
102
     * @covers \eZ\Bundle\EzPublishCoreBundle\SiteAccess\Config\IOConfigResolver::getUrlPrefix
103
     */
104
    public function testGetRootDir(): void
105
    {
106
        $this->siteAccessService
107
            ->method('getCurrent')
108
            ->willReturn(new SiteAccess('ezdemo_site'));
109
110
        $this->configResolver
111
            ->method('hasParameter')
112
            ->with('io.root_dir', null, 'ezdemo_site')
113
            ->willReturn(true);
114
        $this->configResolver
115
            ->method('getParameter')
116
            ->willReturnMap([
117
                ['io.root_dir', null, 'ezdemo_site', '/path/to/ezpublish/web/$var_dir$/ezdemo_site/$storage_dir$'],
118
                ['var_dir', self::DEFAULT_NAMESPACE, 'ezdemo_site', 'var'],
119
                ['storage_dir', self::DEFAULT_NAMESPACE, 'ezdemo_site', 'legacy_storage'],
120
            ]);
121
122
        $complexConfigProcessor = new ComplexConfigProcessor(
123
            $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...
124
            $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...
125
        );
126
127
        $ioConfigResolver = new IOConfigResolver(
128
            $complexConfigProcessor
129
        );
130
131
        $this->assertEquals('/path/to/ezpublish/web/var/ezdemo_site/legacy_storage', $ioConfigResolver->getRootDir());
132
    }
133
}
134