Skip to content

Commit 6540495

Browse files
author
Yuri Kovsher
committed
MAGETWO-33063: Replace usage of __() to Phrase object in library
1 parent d71e45b commit 6540495

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

dev/tests/static/testsuite/Magento/Test/Legacy/ObsoleteCodeTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*/
1111
namespace Magento\Test\Legacy;
1212

13+
use Magento\Framework\Test\Utility\Files;
14+
1315
class ObsoleteCodeTest extends \PHPUnit_Framework_TestCase
1416
{
1517
/**
@@ -129,6 +131,7 @@ function ($file) {
129131
$this->_testObsoleteActions($content);
130132
$this->_testObsoleteConstants($content);
131133
$this->_testObsoletePropertySkipCalculate($content);
134+
$this->checkLibraryDependence($content, $file);
132135
},
133136
\Magento\TestFramework\Utility\ChangedFiles::getPhpFiles(__DIR__ . '/_files/changed_files*')
134137
);
@@ -491,6 +494,25 @@ protected function _testObsoletePropertySkipCalculate($content)
491494
);
492495
}
493496

497+
/**
498+
* Checks that library is not using app defined code
499+
*
500+
* @param string $content
501+
* @param string $file
502+
*/
503+
protected function checkLibraryDependence($content, $file)
504+
{
505+
$path = Files::init()->getPathToSource();
506+
if (strpos($file, $path . '/lib/') === 0) {
507+
$this->_assertNotRegexp(
508+
'~(?<![a-z\\d_:]|->|function\\s)__\\s*\\(~iS',
509+
$content,
510+
'Function __() is defined outside of the library and must not be used there. ' .
511+
'Replacement suggestion: new \\Magento\\Framework\\Phrase()'
512+
);
513+
}
514+
}
515+
494516
/**
495517
* Analyze contents to determine whether this is declaration of specified class/interface
496518
*

lib/internal/Magento/Framework/App/Response/Http/FileFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function create(
6767
$isFile = true;
6868
$file = $content['value'];
6969
if (!$dir->isFile($file)) {
70-
throw new \Exception(__('File not found'));
70+
throw new \Exception((string)new \Magento\Framework\Phrase('File not found'));
7171
}
7272
$contentLength = $dir->stat($file)['size'];
7373
}

0 commit comments

Comments
 (0)