TestPlacementTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Test to ensure that readme file present in specified directories
  8. */
  9. namespace Magento\Test\Integrity;
  10. use Magento\Framework\App\Utility\Files;
  11. use \Magento\Framework\App\Bootstrap;
  12. class TestPlacementTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /** @var array */
  15. private $scanList = ['dev/tests/unit/testsuite/Magento'];
  16. /**
  17. * @var string Path to project root
  18. */
  19. private $root;
  20. protected function setUp()
  21. {
  22. $this->root = BP;
  23. }
  24. public function testUnitTestFilesPlacement()
  25. {
  26. $objectManager = Bootstrap::create(BP, $_SERVER)->getObjectManager();
  27. /** @var \Magento\Framework\Data\Collection\Filesystem $filesystem */
  28. $filesystem = $objectManager->get(\Magento\Framework\Data\Collection\Filesystem::class);
  29. $filesystem->setCollectDirs(false)
  30. ->setCollectFiles(true)
  31. ->setCollectRecursively(true);
  32. $targetsExist = false;
  33. foreach ($this->scanList as $dir) {
  34. if (realpath($this->root . DIRECTORY_SEPARATOR . $dir)) {
  35. $filesystem->addTargetDir($this->root . DIRECTORY_SEPARATOR . $dir);
  36. $targetsExist = true;
  37. }
  38. }
  39. if ($targetsExist) {
  40. $files = $filesystem->load()->toArray();
  41. $fileList = [];
  42. foreach ($files['items'] as $file) {
  43. $fileList[] = $file['filename'];
  44. }
  45. $this->assertEquals(
  46. 0,
  47. $files['totalRecords'],
  48. "The following files have been found in obsolete test directories: \n"
  49. . implode("\n", $fileList)
  50. );
  51. }
  52. }
  53. }