[ 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\RemoteObjectFactory; 23 use ProxyManager\Generator\ClassGenerator; 24 use ProxyManager\Generator\Util\UniqueIdentifierGenerator; 25 26 /** 27 * Tests for {@see \ProxyManager\Factory\RemoteObjectFactory} 28 * 29 * @author Vincent Blanchon <blanchon.vincent@gmail.com> 30 * @license MIT 31 * 32 * @group Coverage 33 */ 34 class RemoteObjectFactoryTest 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\RemoteObjectFactory::__construct 89 * @covers \ProxyManager\Factory\RemoteObjectFactory::createProxy 90 * @covers \ProxyManager\Factory\RemoteObjectFactory::getGenerator 91 */ 92 public function testWillSkipAutoGeneration() 93 { 94 $this 95 ->inflector 96 ->expects($this->once()) 97 ->method('getProxyClassName') 98 ->with('ProxyManagerTestAsset\\BaseInterface') 99 ->will($this->returnValue('StdClass')); 100 101 $adapter = $this->getMock('ProxyManager\Factory\RemoteObject\AdapterInterface'); 102 $factory = new RemoteObjectFactory($adapter, $this->config); 103 /* @var $proxy \stdClass */ 104 $proxy = $factory->createProxy('ProxyManagerTestAsset\\BaseInterface', $adapter); 105 106 $this->assertInstanceOf('stdClass', $proxy); 107 } 108 109 /** 110 * {@inheritDoc} 111 * 112 * @covers \ProxyManager\Factory\RemoteObjectFactory::__construct 113 * @covers \ProxyManager\Factory\RemoteObjectFactory::createProxy 114 * @covers \ProxyManager\Factory\RemoteObjectFactory::getGenerator 115 * 116 * NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful 117 */ 118 public function testWillTryAutoGeneration() 119 { 120 $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar'); 121 $generator = $this->getMock('ProxyManager\GeneratorStrategy\\GeneratorStrategyInterface'); 122 $autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface'); 123 124 $this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator)); 125 $this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader)); 126 127 $generator 128 ->expects($this->once()) 129 ->method('generate') 130 ->with( 131 $this->callback( 132 function (ClassGenerator $targetClass) use ($proxyClassName) { 133 return $targetClass->getName() === $proxyClassName; 134 } 135 ) 136 ); 137 138 // simulate autoloading 139 $autoloader 140 ->expects($this->once()) 141 ->method('__invoke') 142 ->with($proxyClassName) 143 ->will( 144 $this->returnCallback( 145 function () use ($proxyClassName) { 146 eval( 147 'class ' . $proxyClassName 148 . ' extends stdClass {}' 149 ); 150 } 151 ) 152 ); 153 154 $this 155 ->inflector 156 ->expects($this->once()) 157 ->method('getProxyClassName') 158 ->with('ProxyManagerTestAsset\\BaseInterface') 159 ->will($this->returnValue($proxyClassName)); 160 161 $this 162 ->inflector 163 ->expects($this->once()) 164 ->method('getUserClassName') 165 ->with('ProxyManagerTestAsset\\BaseInterface') 166 ->will($this->returnValue('stdClass')); 167 168 $this->signatureChecker->expects($this->atLeastOnce())->method('checkSignature'); 169 $this->classSignatureGenerator->expects($this->once())->method('addSignature')->will($this->returnArgument(0)); 170 171 $adapter = $this->getMock('ProxyManager\Factory\RemoteObject\AdapterInterface'); 172 $factory = new RemoteObjectFactory($adapter, $this->config); 173 /* @var $proxy \stdClass */ 174 $proxy = $factory->createProxy('ProxyManagerTestAsset\\BaseInterface', $adapter); 175 176 $this->assertInstanceOf($proxyClassName, $proxy); 177 } 178 }
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 |