[ 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\Factory; 20 21 use PHPUnit_Framework_TestCase; 22 use ProxyManager\Factory\LazyLoadingGhostFactory; 23 use ProxyManager\Generator\ClassGenerator; 24 use ProxyManager\Generator\Util\UniqueIdentifierGenerator; 25 26 /** 27 * Tests for {@see \ProxyManager\Factory\LazyLoadingGhostFactory} 28 * 29 * @author Marco Pivetta <ocramius@gmail.com> 30 * @license MIT 31 * 32 * @group Coverage 33 */ 34 class LazyLoadingGhostFactoryTest extends PHPUnit_Framework_TestCase 35 { 36 /** 37 * @var \PHPUnit_Framework_MockObject_MockObject 38 */ 39 protected $inflector; 40 41 /** 42 * @var \PHPUnit_Framework_MockObject_MockObject 43 */ 44 protected $signatureChecker; 45 46 /** 47 * @var \ProxyManager\Signature\ClassSignatureGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject 48 */ 49 private $classSignatureGenerator; 50 51 /** 52 * @var \ProxyManager\Configuration|\PHPUnit_Framework_MockObject_MockObject 53 */ 54 protected $config; 55 56 /** 57 * {@inheritDoc} 58 */ 59 public function setUp() 60 { 61 $this->config = $this->getMock('ProxyManager\\Configuration'); 62 $this->inflector = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface'); 63 $this->signatureChecker = $this->getMock('ProxyManager\\Signature\\SignatureCheckerInterface'); 64 $this->classSignatureGenerator = $this->getMock('ProxyManager\\Signature\\ClassSignatureGeneratorInterface'); 65 66 $this 67 ->config 68 ->expects($this->any()) 69 ->method('getClassNameInflector') 70 ->will($this->returnValue($this->inflector)); 71 72 $this 73 ->config 74 ->expects($this->any()) 75 ->method('getSignatureChecker') 76 ->will($this->returnValue($this->signatureChecker)); 77 78 $this 79 ->config 80 ->expects($this->any()) 81 ->method('getClassSignatureGenerator') 82 ->will($this->returnValue($this->classSignatureGenerator)); 83 } 84 85 /** 86 * {@inheritDoc} 87 * 88 * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::__construct 89 */ 90 public function testWithOptionalFactory() 91 { 92 $factory = new LazyLoadingGhostFactory(); 93 $this->assertAttributeNotEmpty('configuration', $factory); 94 $this->assertAttributeInstanceOf('ProxyManager\Configuration', 'configuration', $factory); 95 } 96 97 /** 98 * {@inheritDoc} 99 * 100 * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::__construct 101 * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::createProxy 102 */ 103 public function testWillSkipAutoGeneration() 104 { 105 $className = UniqueIdentifierGenerator::getIdentifier('foo'); 106 107 $this 108 ->inflector 109 ->expects($this->once()) 110 ->method('getProxyClassName') 111 ->with($className) 112 ->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock')); 113 114 $factory = new LazyLoadingGhostFactory($this->config); 115 $initializer = function () { 116 }; 117 /* @var $proxy \ProxyManagerTestAsset\LazyLoadingMock */ 118 $proxy = $factory->createProxy($className, $initializer); 119 120 $this->assertInstanceOf('ProxyManagerTestAsset\\LazyLoadingMock', $proxy); 121 $this->assertSame($initializer, $proxy->initializer); 122 } 123 124 /** 125 * {@inheritDoc} 126 * 127 * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::__construct 128 * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::createProxy 129 * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::getGenerator 130 * 131 * NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful 132 */ 133 public function testWillTryAutoGeneration() 134 { 135 $className = UniqueIdentifierGenerator::getIdentifier('foo'); 136 $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar'); 137 $generator = $this->getMock('ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface'); 138 $autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface'); 139 140 $this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator)); 141 $this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader)); 142 143 $generator 144 ->expects($this->once()) 145 ->method('generate') 146 ->with( 147 $this->callback( 148 function (ClassGenerator $targetClass) use ($proxyClassName) { 149 return $targetClass->getName() === $proxyClassName; 150 } 151 ) 152 ); 153 154 // simulate autoloading 155 $autoloader 156 ->expects($this->once()) 157 ->method('__invoke') 158 ->with($proxyClassName) 159 ->will( 160 $this->returnCallback( 161 function () use ($proxyClassName) { 162 eval('class ' . $proxyClassName . ' extends \\ProxyManagerTestAsset\\LazyLoadingMock {}'); 163 } 164 ) 165 ); 166 167 $this 168 ->inflector 169 ->expects($this->once()) 170 ->method('getProxyClassName') 171 ->with($className) 172 ->will($this->returnValue($proxyClassName)); 173 174 $this 175 ->inflector 176 ->expects($this->once()) 177 ->method('getUserClassName') 178 ->with($className) 179 ->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock')); 180 181 $this->signatureChecker->expects($this->atLeastOnce())->method('checkSignature'); 182 $this->classSignatureGenerator->expects($this->once())->method('addSignature')->will($this->returnArgument(0)); 183 184 $factory = new LazyLoadingGhostFactory($this->config); 185 $initializer = function () { 186 }; 187 /* @var $proxy \ProxyManagerTestAsset\LazyLoadingMock */ 188 $proxy = $factory->createProxy($className, $initializer); 189 190 $this->assertInstanceOf($proxyClassName, $proxy); 191 $this->assertSame($initializer, $proxy->initializer); 192 } 193 }
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 |