Skip to content

Commit f48bbd0

Browse files
committed
MC-36802: SVC doesn't catch MINOR change in PATCH release when adding @api to a class
1 parent 60f485e commit f48bbd0

File tree

8 files changed

+97
-5
lines changed

8 files changed

+97
-5
lines changed

src/ClassHierarchy/Entity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function __construct(string $name, string $type)
124124
*/
125125
public function isApi(): bool
126126
{
127-
return $this->isApi;
127+
return (bool)$this->isApi;
128128
}
129129

130130
/**

src/Helper/Node.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
namespace Magento\SemanticVersionChecker\Helper;
1111

1212
use Magento\SemanticVersionChecker\SemanticVersionChecker;
13+
use PhpParser\Comment\Doc as DocComment;
1314
use PhpParser\Node as PhpNode;
14-
use PhpParser\Node\Stmt\TraitUse;
1515

1616
/**
1717
* Implements a helper that deals with nodes.
@@ -26,9 +26,18 @@ class Node
2626
*/
2727
public function isApiNode(PhpNode $node)
2828
{
29-
$comment = $node->getAttribute('comments');
29+
$comments = $node->getAttribute('comments');
3030

31-
return isset($comment[0])
32-
&& strpos($comment[0]->getText(), SemanticVersionChecker::ANNOTATION_API) !== false;
31+
$result = false;
32+
if (is_array($comments) && !empty($comments)) {
33+
foreach ($comments as $comment) {
34+
if ($comment instanceof DocComment) {
35+
$result = $result || (strpos($comment->getText(),
36+
SemanticVersionChecker::ANNOTATION_API) !== false);
37+
}
38+
}
39+
}
40+
41+
return $result;
3342
}
3443
}

tests/Unit/Console/Command/CompareSourceCommandApiClassesTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,14 @@ public function changesDataProvider()
479479
],
480480
'Major change is detected.',
481481
],
482+
'api-annotation-not-changed' => [
483+
$pathToFixtures . '/annotation-not-changed/source-code-before',
484+
$pathToFixtures . '/annotation-not-changed/source-code-after',
485+
[
486+
'Suggested semantic versioning change: NONE',
487+
],
488+
'Patch change is detected.',
489+
],
482490
];
483491
}
484492
}

tests/Unit/Console/Command/CompareSourceCommandApiInterfacesTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,14 @@ public function changesDataProvider()
250250
],
251251
'Major change is detected.',
252252
],
253+
'api-annotation-not-changed' => [
254+
$pathToFixtures . '/annotation-not-changed/source-code-before',
255+
$pathToFixtures . '/annotation-not-changed/source-code-after',
256+
[
257+
'Suggested semantic versioning change: NONE',
258+
],
259+
'Patch change is detected.',
260+
],
253261
];
254262
}
255263
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Test\Vcs;
8+
9+
// phpcs:disable Magento2.Classes.AbstractApi
10+
/**
11+
* Test class
12+
*
13+
* @api
14+
*/
15+
class TestClass
16+
{
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Test\Vcs;
8+
9+
/**
10+
* Test class
11+
*
12+
* @api
13+
*/
14+
class TestClass
15+
{
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Test\Vcs;
7+
8+
// phpcs:disable Magento2.Classes.AbstractApi
9+
/**
10+
* Test interface
11+
*
12+
* @api
13+
*/
14+
interface TestInterface
15+
{
16+
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Test\Vcs;
7+
8+
/**
9+
* Test interface
10+
*
11+
* @api
12+
*/
13+
interface TestInterface
14+
{
15+
16+
}

0 commit comments

Comments
 (0)