Skip to content

Commit 89b5665

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

File tree

4 files changed

+96
-1
lines changed

4 files changed

+96
-1
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Magento\SemanticVersionChecker\Reporter;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
8+
class HtmlTargetDecoratorTest extends TestCase
9+
{
10+
/**
11+
* @dataProvider dataProviderTestUrl
12+
*/
13+
public function testUrl(string $target, string $context, string $urlJson, string $expected): void
14+
{
15+
$input = $this->getMockBuilder(InputInterface::class)->getMockForAbstractClass();
16+
$input->expects($this->once())->method('getOption')->with('report-html-target-url')->willReturn($urlJson);
17+
$result = HtmlTargetDecorator::url($target, $context, $input);
18+
$this->assertEquals($expected, $result);
19+
}
20+
21+
public function dataProviderTestUrl()
22+
{
23+
return [
24+
'target-context-class' => [
25+
'Magento\Framework\Registry',
26+
'class',
27+
'[{"reportTypes": ["interface", "class"], "url": "https://localhost/?target=%s"}]',
28+
'<a href="https://localhost/?target=TWFnZW50b1xGcmFtZXdvcmtcUmVnaXN0cnk=" target="_blank">Magento\Framework\Registry</a>'
29+
],
30+
'target-context-class-array' => [
31+
'Magento\Framework\Registry',
32+
'class',
33+
'[{"reportTypes": ["mftf"], "url": "https://localhost/?target=%s"}, {"reportTypes": ["class"], "url": "https://localhost/?target=%s"}]',
34+
'<a href="https://localhost/?target=TWFnZW50b1xGcmFtZXdvcmtcUmVnaXN0cnk=" target="_blank">Magento\Framework\Registry</a>'
35+
],
36+
'target-context-mftf' => [
37+
'Magento\Framework\Registry',
38+
'mftf',
39+
'[{"reportTypes": ["interface", "class"], "url": "https://localhost/?target=%s"}]',
40+
'Magento\Framework\Registry'
41+
],
42+
'empty-json' => [
43+
'Magento\Framework\Registry',
44+
'class',
45+
'',
46+
'Magento\Framework\Registry'
47+
],
48+
'broken-json' => [
49+
'Magento\Framework\Registry',
50+
'class',
51+
'[{"reportTypes": ["interface", "class"]',
52+
'Magento\Framework\Registry'
53+
],
54+
];
55+
}
56+
}

src/Console/Command/CompareSourceCommand.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ protected function configure()
9797
. '. Example: --report-type=' . ReportTypes::MFTF . PHP_EOL,
9898
[]
9999
),
100+
new InputOption(
101+
'report-html-target-url',
102+
'',
103+
InputOption::VALUE_OPTIONAL,
104+
'Json data to create url for Target field in HTML report of a specific type. Example: [{"reportTypes": ["interface", "class"], "url": "https://example.com/?target=%s"}]',
105+
''
106+
),
100107
]);
101108
}
102109

src/Reporter/HtmlDbSchemaReporter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected function outputTable(OutputInterface $output, Report $report, $context
137137
} elseif (substr($location, 0, strlen($sourceAfterDir)) == $sourceAfterDir) {
138138
$location = substr($location, strlen($sourceAfterDir));
139139
}
140-
140+
$target = HtmlTargetDecorator::url($target, $context, $this->input);
141141
$output->writeln(
142142
'<tr class="text-' . ($level > $allowedChangeLevel ? 'danger' : 'success') .
143143
'"><td>' . $levelStr . '</td><td>' . $target . '<br/>' . $location . '</td><td>' . $code . ' ' .

src/Reporter/HtmlTargetDecorator.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Magento\SemanticVersionChecker\Reporter;
4+
5+
use Symfony\Component\Console\Input\InputInterface;
6+
7+
/**
8+
* Html decorator for Target field of the report
9+
*/
10+
class HtmlTargetDecorator
11+
{
12+
/**
13+
* Create a link tag for specific report types
14+
*
15+
* @param string $target
16+
* @param string $context
17+
* @param InputInterface $input
18+
* @return string
19+
*/
20+
public static function url(string $target, string $context, InputInterface $input): string
21+
{
22+
$urlContextJson = $input->getOption('report-html-target-url');
23+
foreach (@json_decode($urlContextJson, true) ?? [] as $urlContext) {
24+
if (!in_array($context, $urlContext['reportTypes']) || !$urlContext['url']) {
25+
continue;
26+
}
27+
$href = sprintf($urlContext['url'], base64_encode($target));
28+
$target = sprintf('<a href="%s" target="_blank">%s</a>', $href, $target);
29+
}
30+
return $target;
31+
}
32+
}

0 commit comments

Comments
 (0)