Skip to content

Commit b5f0478

Browse files
committed
ACP2E-932: [Infra] Integrate EAT and Jenkins SVC
1 parent 89b5665 commit b5f0478

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

dev/tests/Unit/Reporter/HtmlTargetDecoratorTest.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ class HtmlTargetDecoratorTest extends TestCase
1010
/**
1111
* @dataProvider dataProviderTestUrl
1212
*/
13-
public function testUrl(string $target, string $context, string $urlJson, string $expected): void
13+
public function testUrl(bool $hasOption, string $target, string $context, string $urlJson, string $expected): void
1414
{
1515
$input = $this->getMockBuilder(InputInterface::class)->getMockForAbstractClass();
16-
$input->expects($this->once())->method('getOption')->with('report-html-target-url')->willReturn($urlJson);
16+
$input->expects($this->once())->method('hasOption')->with('report-html-target-url')->willReturn($hasOption);
17+
if ($hasOption) {
18+
$input->expects($this->once())->method('getOption')->with('report-html-target-url')->willReturn($urlJson);
19+
} else {
20+
$input->expects($this->never())->method('getOption');
21+
}
1722
$result = HtmlTargetDecorator::url($target, $context, $input);
1823
$this->assertEquals($expected, $result);
1924
}
@@ -22,35 +27,47 @@ public function dataProviderTestUrl()
2227
{
2328
return [
2429
'target-context-class' => [
30+
true,
2531
'Magento\Framework\Registry',
2632
'class',
2733
'[{"reportTypes": ["interface", "class"], "url": "https://localhost/?target=%s"}]',
2834
'<a href="https://localhost/?target=TWFnZW50b1xGcmFtZXdvcmtcUmVnaXN0cnk=" target="_blank">Magento\Framework\Registry</a>'
2935
],
3036
'target-context-class-array' => [
37+
true,
3138
'Magento\Framework\Registry',
3239
'class',
3340
'[{"reportTypes": ["mftf"], "url": "https://localhost/?target=%s"}, {"reportTypes": ["class"], "url": "https://localhost/?target=%s"}]',
3441
'<a href="https://localhost/?target=TWFnZW50b1xGcmFtZXdvcmtcUmVnaXN0cnk=" target="_blank">Magento\Framework\Registry</a>'
3542
],
3643
'target-context-mftf' => [
44+
true,
3745
'Magento\Framework\Registry',
3846
'mftf',
3947
'[{"reportTypes": ["interface", "class"], "url": "https://localhost/?target=%s"}]',
4048
'Magento\Framework\Registry'
4149
],
4250
'empty-json' => [
43-
'Magento\Framework\Registry',
51+
true,
52+
'Magento\Framework\Registry::$someProperty',
4453
'class',
4554
'',
46-
'Magento\Framework\Registry'
55+
'Magento\Framework\Registry::$someProperty'
4756
],
4857
'broken-json' => [
58+
true,
4959
'Magento\Framework\Registry',
5060
'class',
5161
'[{"reportTypes": ["interface", "class"]',
5262
'Magento\Framework\Registry'
5363
],
64+
'has-no-option' => [
65+
false,
66+
'Magento\Framework\Registry',
67+
'class',
68+
'',
69+
'Magento\Framework\Registry'
70+
],
5471
];
5572
}
5673
}

src/Reporter/HtmlTargetDecorator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
class HtmlTargetDecorator
1111
{
12+
private static string $optionName = 'report-html-target-url';
13+
1214
/**
1315
* Create a link tag for specific report types
1416
*
@@ -19,7 +21,10 @@ class HtmlTargetDecorator
1921
*/
2022
public static function url(string $target, string $context, InputInterface $input): string
2123
{
22-
$urlContextJson = $input->getOption('report-html-target-url');
24+
if (!$input->hasOption(self::$optionName)) {
25+
return $target;
26+
}
27+
$urlContextJson = $input->getOption(self::$optionName);
2328
foreach (@json_decode($urlContextJson, true) ?? [] as $urlContext) {
2429
if (!in_array($context, $urlContext['reportTypes']) || !$urlContext['url']) {
2530
continue;

0 commit comments

Comments
 (0)