FileResolverTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Integration test for \Magento\Framework\Filesystem\FileResolver
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\Filesystem;
  9. use Magento\TestFramework\Helper\Bootstrap;
  10. class FileResolverTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * Path to add to include path
  14. */
  15. const FIRST_PATH = '/path/to/code/1/';
  16. /**
  17. * Path to add to include path
  18. */
  19. const SECOND_PATH = '/path/to/code/2/';
  20. /**
  21. * @var \Magento\Framework\Filesystem\FileResolver
  22. */
  23. protected $model;
  24. /**
  25. * @var string original include-path variable
  26. */
  27. protected $originalPath;
  28. public function setUp()
  29. {
  30. $this->model = Bootstrap::getObjectManager()->create(\Magento\Framework\Filesystem\FileResolver::class);
  31. $this->originalPath = get_include_path();
  32. set_include_path('/pre/existing/paths/');
  33. }
  34. public function tearDown()
  35. {
  36. set_include_path($this->originalPath);
  37. }
  38. public function testAddIncludePathPrepend()
  39. {
  40. $this->model->addIncludePath(self::FIRST_PATH);
  41. $this->model->addIncludePath(self::SECOND_PATH);
  42. $postIncludePath = get_include_path();
  43. $this->assertStringStartsWith(
  44. self::SECOND_PATH,
  45. $postIncludePath
  46. );
  47. }
  48. public function testAddIncludePathAppend()
  49. {
  50. $this->model->addIncludePath(self::FIRST_PATH, false);
  51. $this->model->addIncludePath(self::SECOND_PATH, false);
  52. $postIncludePath = get_include_path();
  53. $this->assertStringEndsWith(
  54. self::SECOND_PATH,
  55. $postIncludePath
  56. );
  57. }
  58. public function testGetFile()
  59. {
  60. $includePath = realpath(__DIR__ . '/_files/');
  61. $className = '\ClassToFind';
  62. $this->model->addIncludePath($includePath);
  63. $this->assertFileExists($this->model->getFile($className));
  64. }
  65. }