[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 14 * 15 * This software consists of voluntary contributions made by many individuals 16 * and is licensed under the MIT license. 17 */ 18 19 namespace ProxyManagerTest\Autoloader; 20 21 use PHPUnit_Framework_TestCase; 22 use ProxyManager\Autoloader\Autoloader; 23 use ProxyManager\Generator\Util\UniqueIdentifierGenerator; 24 25 /** 26 * Tests for {@see \ProxyManager\Autoloader\Autoloader} 27 * 28 * @author Marco Pivetta <ocramius@gmail.com> 29 * @license MIT 30 * 31 * @covers \ProxyManager\Autoloader\Autoloader 32 * @group Coverage 33 */ 34 class AutoloaderTest extends PHPUnit_Framework_TestCase 35 { 36 /** 37 * @var \ProxyManager\Autoloader\Autoloader 38 */ 39 protected $autoloader; 40 41 /** 42 * @var \ProxyManager\FileLocator\FileLocatorInterface|\PHPUnit_Framework_MockObject_MockObject 43 */ 44 protected $fileLocator; 45 46 /** 47 * @var \ProxyManager\Inflector\ClassNameInflectorInterface|\PHPUnit_Framework_MockObject_MockObject 48 */ 49 protected $classNameInflector; 50 51 /** 52 * @covers \ProxyManager\Autoloader\Autoloader::__construct 53 */ 54 public function setUp() 55 { 56 $this->fileLocator = $this->getMock('ProxyManager\\FileLocator\\FileLocatorInterface'); 57 $this->classNameInflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface'); 58 $this->autoloader = new Autoloader($this->fileLocator, $this->classNameInflector); 59 } 60 61 /** 62 * @covers \ProxyManager\Autoloader\Autoloader::__invoke 63 */ 64 public function testWillNotAutoloadUserClasses() 65 { 66 $className = 'Foo\\' . UniqueIdentifierGenerator::getIdentifier('Bar'); 67 $this 68 ->classNameInflector 69 ->expects($this->once()) 70 ->method('isProxyClassName') 71 ->with($className) 72 ->will($this->returnValue(false)); 73 74 $this->assertFalse($this->autoloader->__invoke($className)); 75 } 76 77 /** 78 * @covers \ProxyManager\Autoloader\Autoloader::__invoke 79 */ 80 public function testWillNotAutoloadNonExistingClass() 81 { 82 $className = 'Foo\\' . UniqueIdentifierGenerator::getIdentifier('Bar'); 83 $this 84 ->classNameInflector 85 ->expects($this->once()) 86 ->method('isProxyClassName') 87 ->with($className) 88 ->will($this->returnValue(true)); 89 $this 90 ->fileLocator 91 ->expects($this->once()) 92 ->method('getProxyFileName') 93 ->will($this->returnValue(__DIR__ . '/non-existing')); 94 95 $this->assertFalse($this->autoloader->__invoke($className)); 96 } 97 98 /** 99 * @covers \ProxyManager\Autoloader\Autoloader::__invoke 100 */ 101 public function testWillNotAutoloadExistingClass() 102 { 103 $this->assertFalse($this->autoloader->__invoke(__CLASS__)); 104 } 105 106 /** 107 * @covers \ProxyManager\Autoloader\Autoloader::__invoke 108 */ 109 public function testWillAutoloadExistingFile() 110 { 111 $namespace = 'Foo'; 112 $className = UniqueIdentifierGenerator::getIdentifier('Bar'); 113 $fqcn = $namespace . '\\' . $className; 114 $fileName = sys_get_temp_dir() . '/foo_' . uniqid() . '.php'; 115 116 file_put_contents($fileName, '<?php namespace ' . $namespace . '; class ' . $className . '{}'); 117 118 $this 119 ->classNameInflector 120 ->expects($this->once()) 121 ->method('isProxyClassName') 122 ->with($fqcn) 123 ->will($this->returnValue(true)); 124 $this 125 ->fileLocator 126 ->expects($this->once()) 127 ->method('getProxyFileName') 128 ->will($this->returnValue($fileName)); 129 130 $this->assertTrue($this->autoloader->__invoke($fqcn)); 131 $this->assertTrue(class_exists($fqcn, false)); 132 } 133 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |