ClassLoaderWrapperTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Autoload\Test\Unit;
  7. use Composer\Autoload\ClassLoader;
  8. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  9. class ClassLoaderWrapperTest extends \PHPUnit\Framework\TestCase
  10. {
  11. const PREFIX = 'Namespace\\Prefix\\';
  12. const DIR = '/path/to/class/';
  13. const DEFAULT_PREPEND = false;
  14. /**
  15. * @var ClassLoader | \PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $autoloaderMock;
  18. /**
  19. * @var \Magento\Framework\Autoload\ClassLoaderWrapper
  20. */
  21. protected $model;
  22. protected function setUp()
  23. {
  24. $this->autoloaderMock = $this->createMock(\Composer\Autoload\ClassLoader::class);
  25. $this->model = (new ObjectManager($this))->getObject(
  26. \Magento\Framework\Autoload\ClassLoaderWrapper::class,
  27. [
  28. 'autoloader' => $this->autoloaderMock
  29. ]
  30. );
  31. }
  32. public function testAdd()
  33. {
  34. $prepend = true;
  35. $this->autoloaderMock->expects($this->once())
  36. ->method('add')
  37. ->with(self::PREFIX, self::DIR, $prepend);
  38. $this->model->addPsr0(self::PREFIX, self::DIR, $prepend);
  39. }
  40. public function testAddPsr4()
  41. {
  42. $prepend = true;
  43. $this->autoloaderMock->expects($this->once())
  44. ->method('addPsr4')
  45. ->with(self::PREFIX, self::DIR, $prepend);
  46. $this->model->addPsr4(self::PREFIX, self::DIR, $prepend);
  47. }
  48. public function testAddDefault()
  49. {
  50. $this->autoloaderMock->expects($this->once())
  51. ->method('add')
  52. ->with(self::PREFIX, self::DIR, self::DEFAULT_PREPEND);
  53. $this->model->addPsr0(self::PREFIX, self::DIR);
  54. }
  55. public function testAddPsr4Default()
  56. {
  57. $this->autoloaderMock->expects($this->once())
  58. ->method('addPsr4')
  59. ->with(self::PREFIX, self::DIR, self::DEFAULT_PREPEND);
  60. $this->model->addPsr4(self::PREFIX, self::DIR);
  61. }
  62. public function testSet()
  63. {
  64. $paths = [self::DIR];
  65. $this->autoloaderMock->expects($this->once())
  66. ->method('set')
  67. ->with(self::PREFIX, $paths);
  68. $this->model->setPsr0(self::PREFIX, $paths);
  69. }
  70. public function testSetPsr4()
  71. {
  72. $paths = [self::DIR];
  73. $this->autoloaderMock->expects($this->once())
  74. ->method('setPsr4')
  75. ->with(self::PREFIX, $paths);
  76. $this->model->setPsr4(self::PREFIX, $paths);
  77. }
  78. }