Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DefinedClassesTest.php
Go to the documentation of this file.
1 <?php
2 /***
3  * Copyright © Magento, Inc. All rights reserved.
4  * See COPYING.txt for license details.
5  */
6 
7 // @codingStandardsIgnoreStart
9  use Magento\Framework\Code\Test\Unit\Generator\DefinedClassesTest;
10 
16  {
17  return DefinedClassesTest::$definedClassesTestActive
18  ? $className === DefinedClassesTest::$classInMemory
20  }
21 }
22 
27 
28  // @codingStandardsIgnoreEnd
29 
30  class DefinedClassesTest extends \PHPUnit\Framework\TestCase
31  {
33  public static $definedClassesTestActive = false;
34 
35  public static $classInMemory = 'Class\That\Exists\In\Memory';
36 
38  private $model;
39 
41  private $initAutoloader;
42 
43  protected function setUp()
44  {
45  $this->model = new DefinedClasses();
46  self::$definedClassesTestActive = true;
47  $this->initAutoloader = AutoloaderRegistry::getAutoloader();
48  }
49 
50  public function tearDown()
51  {
52  self::$definedClassesTestActive = false;
53  AutoloaderRegistry::registerAutoloader($this->initAutoloader);
54  }
55 
56  public function testClassLoadableFromMemory()
57  {
58  $this->assertTrue($this->model->isClassLoadable(self::$classInMemory));
59  }
60 
61  public function testClassLoadableFromDisc()
62  {
63  $classOnDisc = 'Class\That\Exists\On\Disc';
67  $autoloaderMock = $this->createMock(\Magento\Framework\Autoload\AutoloaderInterface::class);
68  $autoloaderMock->expects($this->once())->method('findFile')->with($classOnDisc)->willReturn(true);
69  AutoloaderRegistry::registerAutoloader($autoloaderMock);
70  $this->assertTrue($this->model->isClassLoadable($classOnDisc));
71  }
72 
73  public function testClassNotLoadable()
74  {
75  $this->assertFalse($this->model->isClassLoadable('Class\Does\Not\Exist'));
76  }
77  }
78 }
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31