Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ClassLoaderWrapperTest.php
Go to the documentation of this file.
1 <?php
8 
9 use Composer\Autoload\ClassLoader;
11 
12 class ClassLoaderWrapperTest extends \PHPUnit\Framework\TestCase
13 {
14  const PREFIX = 'Namespace\\Prefix\\';
15 
16  const DIR = '/path/to/class/';
17 
18  const DEFAULT_PREPEND = false;
19 
23  protected $autoloaderMock;
24 
28  protected $model;
29 
30  protected function setUp()
31  {
32  $this->autoloaderMock = $this->createMock(\Composer\Autoload\ClassLoader::class);
33  $this->model = (new ObjectManager($this))->getObject(
34  \Magento\Framework\Autoload\ClassLoaderWrapper::class,
35  [
36  'autoloader' => $this->autoloaderMock
37  ]
38  );
39  }
40 
41  public function testAdd()
42  {
43  $prepend = true;
44 
45  $this->autoloaderMock->expects($this->once())
46  ->method('add')
47  ->with(self::PREFIX, self::DIR, $prepend);
48 
49  $this->model->addPsr0(self::PREFIX, self::DIR, $prepend);
50  }
51 
52  public function testAddPsr4()
53  {
54  $prepend = true;
55 
56  $this->autoloaderMock->expects($this->once())
57  ->method('addPsr4')
58  ->with(self::PREFIX, self::DIR, $prepend);
59 
60  $this->model->addPsr4(self::PREFIX, self::DIR, $prepend);
61  }
62 
63  public function testAddDefault()
64  {
65  $this->autoloaderMock->expects($this->once())
66  ->method('add')
67  ->with(self::PREFIX, self::DIR, self::DEFAULT_PREPEND);
68 
69  $this->model->addPsr0(self::PREFIX, self::DIR);
70  }
71 
72  public function testAddPsr4Default()
73  {
74  $this->autoloaderMock->expects($this->once())
75  ->method('addPsr4')
76  ->with(self::PREFIX, self::DIR, self::DEFAULT_PREPEND);
77 
78  $this->model->addPsr4(self::PREFIX, self::DIR);
79  }
80 
81  public function testSet()
82  {
83  $paths = [self::DIR];
84  $this->autoloaderMock->expects($this->once())
85  ->method('set')
86  ->with(self::PREFIX, $paths);
87 
88  $this->model->setPsr0(self::PREFIX, $paths);
89  }
90 
91  public function testSetPsr4()
92  {
93  $paths = [self::DIR];
94  $this->autoloaderMock->expects($this->once())
95  ->method('setPsr4')
96  ->with(self::PREFIX, $paths);
97 
98  $this->model->setPsr4(self::PREFIX, $paths);
99  }
100 }
$paths
Definition: _bootstrap.php:83