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