123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- /***
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Framework\App\Utility;
- use Magento\Framework\App\Utility\Files;
- use Magento\Framework\Component\ComponentRegistrar;
- class FilesTest extends \PHPUnit\Framework\TestCase
- {
- /** @var \Magento\Framework\App\Utility\Files */
- protected $model;
- /** @var array */
- protected $moduleTests = [];
- /** @var array */
- protected $frameworkTests = [];
- /** @var array */
- protected $libTests = [];
- /** @var string */
- protected $rootTestsDir = '#dev/tests/#';
- /** @var string */
- protected $setupTestsDir = '#setup/src/Magento/Setup/Test#';
- public function setUp()
- {
- $componentRegistrar = new ComponentRegistrar();
- $dirSearch = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
- ->create(\Magento\Framework\Component\DirSearch::class);
- $themePackageList = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
- ->create(\Magento\Framework\View\Design\Theme\ThemePackageList::class);
- $this->model = new Files($componentRegistrar, $dirSearch, $themePackageList);
- foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleDir) {
- $this->moduleTests[] = '#' . $moduleDir . '/Test#';
- }
- foreach ($componentRegistrar->getPaths(ComponentRegistrar::LIBRARY) as $libraryDir) {
- $this->libTests[] = '#' . $libraryDir . '/Test#';
- $this->frameworkTests[] = '#' . $libraryDir . '/[\\w]+/Test#';
- }
- }
- public function testGetPhpFilesExcludeTests()
- {
- $this->assertNoTestDirs(
- $this->model->getPhpFiles(
- Files::INCLUDE_APP_CODE
- | Files::INCLUDE_PUB_CODE
- | Files::INCLUDE_DEV_TOOLS
- | Files::INCLUDE_LIBS
- | Files::INCLUDE_TEMPLATES
- | Files::INCLUDE_NON_CLASSES
- )
- );
- }
- public function testGetComposerExcludeTests()
- {
- $this->assertNoTestDirs(
- $this->model->getComposerFiles(ComponentRegistrar::MODULE, false)
- );
- }
- public function testGetPhpFilesOnlyTests()
- {
- $classFiles = $this->model->getPhpFiles(Files::INCLUDE_TESTS);
- foreach ($this->moduleTests as $moduleTest) {
- $classFiles = preg_grep($moduleTest, $classFiles, PREG_GREP_INVERT);
- }
- foreach ($this->libTests as $libraryTest) {
- $classFiles = preg_grep($libraryTest, $classFiles, PREG_GREP_INVERT);
- }
- foreach ($this->frameworkTests as $frameworkTest) {
- $classFiles = preg_grep($frameworkTest, $classFiles, PREG_GREP_INVERT);
- }
- $classFiles = preg_grep($this->rootTestsDir, $classFiles, PREG_GREP_INVERT);
- $classFiles = preg_grep($this->setupTestsDir, $classFiles, PREG_GREP_INVERT);
- $this->assertEmpty($classFiles);
- }
- public function testGetConfigFiles()
- {
- $actual = $this->model->getConfigFiles('*.xml');
- $this->assertNotEmpty($actual);
- foreach ($actual as $file) {
- $this->assertStringEndsWith('.xml', $file[0]);
- }
- }
- public function testGetLayoutConfigFiles()
- {
- $actual = $this->model->getLayoutConfigFiles('*.xml');
- $this->assertNotEmpty($actual);
- foreach ($actual as $file) {
- $this->assertStringEndsWith('.xml', $file[0]);
- }
- }
- public function testGetXmlCatalogFiles()
- {
- $actual = $this->model->getXmlCatalogFiles('*.xml');
- $this->assertNotEmpty($actual);
- foreach ($actual as $file) {
- $this->assertStringEndsWith('.xml', $file[0]);
- }
- $actual = $this->model->getXmlCatalogFiles('*.xsd');
- $this->assertNotEmpty($actual);
- foreach ($actual as $file) {
- $this->assertStringEndsWith('.xsd', $file[0]);
- }
- }
- /**
- * Verify that the given array of files does not contain anything in test directories
- *
- * @param array $files
- */
- protected function assertNoTestDirs($files)
- {
- foreach ($this->moduleTests as $moduleTest) {
- $this->assertEmpty(preg_grep($moduleTest, $files));
- }
- foreach ($this->frameworkTests as $frameworkTest) {
- $this->assertEmpty(preg_grep($frameworkTest, $files));
- }
- foreach ($this->libTests as $libTest) {
- $this->assertEmpty(preg_grep($libTest, $files));
- }
- }
- /**
- * @magentoComponentsDir Magento/Framework/App/Utility/_files/fixtures
- */
- public function testReadLists()
- {
- $fixtureDir = str_replace('\\', '/', __DIR__) . '/_files/fixtures/';
- $expected = [
- $fixtureDir . 'language/One.php',
- $fixtureDir . 'language/registration.php',
- $fixtureDir . 'library/One.php',
- $fixtureDir . 'module/One.php',
- $fixtureDir . 'module/registration.php',
- $fixtureDir . 'theme/One.php',
- ];
- $actual = $this->model->readLists(__DIR__ . '/_files/patterns/paths*.txt');
- sort($actual);
- foreach ($actual as &$file) {
- $file = str_replace('\\', '/', $file);
- }
- $this->assertSame($expected, $actual);
- }
- }
|