CopyrightTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Tests to ensure that all files has up to date copyright info
  8. */
  9. namespace Magento\Test\Legacy;
  10. class CopyrightTest extends \PHPUnit\Framework\TestCase
  11. {
  12. public function testCopyright()
  13. {
  14. $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
  15. $invoker(
  16. function ($filename) {
  17. $fileText = file_get_contents($filename);
  18. if (strpos($fileText, 'Copyright © Magento, Inc. All rights reserved.') === false) {
  19. $this->fail('Copyright is missing or has wrong format ' . $filename);
  20. }
  21. },
  22. $this->copyrightDataProvider()
  23. );
  24. }
  25. public function copyrightDataProvider()
  26. {
  27. $blackList = $this->getFilesData('blacklist*.php');
  28. $changedFiles = [];
  29. foreach (glob(__DIR__ . '/../_files/changed_files*') as $listFile) {
  30. $changedFiles = array_merge($changedFiles, file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
  31. }
  32. array_walk(
  33. $changedFiles,
  34. function (&$file) {
  35. $file = [BP . '/' . $file];
  36. }
  37. );
  38. $changedFiles = array_filter(
  39. $changedFiles,
  40. function ($path) use ($blackList) {
  41. if (!file_exists($path[0]) || !is_readable($path[0])) {
  42. return false;
  43. }
  44. $path[0] = realpath($path[0]);
  45. foreach ($blackList as $item) {
  46. if (preg_match($item, $path[0])) {
  47. return false;
  48. }
  49. }
  50. return true;
  51. }
  52. );
  53. return $changedFiles;
  54. }
  55. /**
  56. * @param string $filePattern
  57. * @return array
  58. */
  59. protected function getFilesData($filePattern)
  60. {
  61. $result = [];
  62. foreach (glob(__DIR__ . '/_files/copyright/' . $filePattern) as $file) {
  63. $fileData = include $file;
  64. $result = array_merge($result, $fileData);
  65. }
  66. return $result;
  67. }
  68. }