Skip to content

Commit 3083820

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-62497-static-test' into MAGETWO-59761-n-MAGETWO-62497
2 parents 07a83bd + 4d25859 commit 3083820

File tree

13 files changed

+252
-2
lines changed

13 files changed

+252
-2
lines changed

dev/tests/static/framework/Magento/TestFramework/Utility/CodeCheck.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static function isClassUsed($className, $content)
2222
{
2323
/* avoid matching namespace instead of class */
2424
$content = preg_replace('/namespace[^;]+;/', '', $content);
25-
return self::_isRegexpMatched('/[^a-z\d_]' . preg_quote($className, '/') . '[^a-z\d_\\\\]/iS', $content);
25+
return self::_isRegexpMatched('/[^a-z\d_\$]' . preg_quote($className, '/') . '[^a-z\d_\\\\]/iS', $content);
2626
}
2727

2828
/**
@@ -126,7 +126,7 @@ public static function isDirectDescendant($content, $name)
126126
{
127127
$name = preg_quote($name, '/');
128128
return self::_isRegexpMatched(
129-
'/\s+extends\s+' . $name . '\b|\s+implements\s+[^{]*\b' . $name . '\b[^{^\\\\]*\{/iS',
129+
'/\s+extends\s+\\\\?' . $name . '\b|\s+implements\s+[^{]*\b' . $name . '\b[^{^\\\\]*\{/iS',
130130
$content
131131
);
132132
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Test\Utility\File;
7+
8+
use Magento\TestFramework\Utility\CodeCheck;
9+
10+
class CodeCheckTest extends \PHPUnit_Framework_TestCase
11+
{
12+
/**
13+
* @var CodeCheck
14+
*/
15+
private $codeCheck;
16+
17+
protected function setUp()
18+
{
19+
$this->codeCheck = new CodeCheck();
20+
}
21+
22+
/**
23+
* @param string $fileContent
24+
* @param bool $isClassUsed
25+
* @dataProvider isClassUsedDataProvider
26+
*/
27+
public function testIsClassUsed($fileContent, $isClassUsed)
28+
{
29+
$this->assertEquals(
30+
$isClassUsed,
31+
$this->codeCheck->isClassUsed('MyClass', $fileContent)
32+
);
33+
}
34+
35+
/**
36+
* @return array
37+
*/
38+
public function isClassUsedDataProvider()
39+
{
40+
return [
41+
[file_get_contents(__DIR__ . '/_files/create_new_instance.txt'), true],
42+
[file_get_contents(__DIR__ . '/_files/create_new_instance2.txt'), true],
43+
[file_get_contents(__DIR__ . '/_files/create_new_instance3.txt'), true],
44+
[file_get_contents(__DIR__ . '/_files/class_name_in_namespace_and_variable_name.txt'), false],
45+
[file_get_contents(__DIR__ . '/_files/extends.txt'), true],
46+
[file_get_contents(__DIR__ . '/_files/extends2.txt'), true],
47+
[file_get_contents(__DIR__ . '/_files/use.txt'), true],
48+
[file_get_contents(__DIR__ . '/_files/use2.txt'), true]
49+
];
50+
}
51+
52+
/**
53+
* @param string $fileContent
54+
* @param bool $isDirectDescendant
55+
* @dataProvider isDirectDescendantDataProvider
56+
*/
57+
public function testIsDirectDescendant($fileContent, $isDirectDescendant)
58+
{
59+
$this->assertEquals(
60+
$isDirectDescendant,
61+
$this->codeCheck->isDirectDescendant($fileContent, 'MyClass')
62+
);
63+
}
64+
65+
/**
66+
* @return array
67+
*/
68+
public function isDirectDescendantDataProvider()
69+
{
70+
return [
71+
[file_get_contents(__DIR__ . '/_files/extends.txt'), true],
72+
[file_get_contents(__DIR__ . '/_files/extends2.txt'), true],
73+
[file_get_contents(__DIR__ . '/_files/implements.txt'), true],
74+
[file_get_contents(__DIR__ . '/_files/implements2.txt'), true]
75+
];
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\MyClass;
7+
8+
$myClass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
$myClass = new MyClass();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
$myClass = new MyClass;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
$myClass = new \MyClass();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
MyClassChild extends MyClass
8+
{
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
MyClassChild extends \MyClass
8+
{
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
MyClassChild implements MyClass
8+
{
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
MyClassChild implements \MyClass
8+
{

0 commit comments

Comments
 (0)