[ 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\Functional; 20 21 use PHPUnit_Framework_TestCase; 22 use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy; 23 use ProxyManager\ProxyGenerator\NullObjectGenerator; 24 use ProxyManagerTestAsset\BaseClass; 25 use ProxyManagerTestAsset\ClassWithSelfHint; 26 use ReflectionClass; 27 use ProxyManager\Generator\ClassGenerator; 28 use ProxyManager\Generator\Util\UniqueIdentifierGenerator; 29 30 /** 31 * Tests for {@see \ProxyManager\ProxyGenerator\NullObjectGenerator} produced objects 32 * 33 * @author Vincent Blanchon <blanchon.vincent@gmail.com> 34 * @license MIT 35 * 36 * @group Functional 37 * @coversNothing 38 */ 39 class NullObjectFunctionalTest extends PHPUnit_Framework_TestCase 40 { 41 /** 42 * @dataProvider getProxyMethods 43 */ 44 public function testMethodCalls($className, $instance, $method, $params, $expectedValue) 45 { 46 $proxyName = $this->generateProxy($className); 47 48 /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ 49 $proxy = new $proxyName(); 50 51 $this->assertSame(null, call_user_func_array(array($proxy, $method), $params)); 52 } 53 54 /** 55 * @dataProvider getProxyMethods 56 */ 57 public function testMethodCallsAfterUnSerialization($className, $instance, $method, $params, $expectedValue) 58 { 59 $proxyName = $this->generateProxy($className); 60 /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ 61 $proxy = unserialize(serialize(new $proxyName())); 62 63 $this->assertSame(null, call_user_func_array(array($proxy, $method), $params)); 64 } 65 66 /** 67 * @dataProvider getProxyMethods 68 */ 69 public function testMethodCallsAfterCloning($className, $instance, $method, $params, $expectedValue) 70 { 71 $proxyName = $this->generateProxy($className); 72 73 /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ 74 $proxy = new $proxyName(); 75 $cloned = clone $proxy; 76 77 $this->assertSame(null, call_user_func_array(array($cloned, $method), $params)); 78 } 79 80 /** 81 * @dataProvider getPropertyAccessProxies 82 */ 83 public function testPropertyReadAccess($instance, $proxy, $publicProperty, $propertyValue) 84 { 85 /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ 86 $this->assertSame(null, $proxy->$publicProperty); 87 } 88 89 /** 90 * @dataProvider getPropertyAccessProxies 91 */ 92 public function testPropertyWriteAccess($instance, $proxy, $publicProperty) 93 { 94 /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ 95 $newValue = uniqid(); 96 $proxy->$publicProperty = $newValue; 97 98 $this->assertSame($newValue, $proxy->$publicProperty); 99 } 100 101 /** 102 * @dataProvider getPropertyAccessProxies 103 */ 104 public function testPropertyExistence($instance, $proxy, $publicProperty) 105 { 106 /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ 107 $this->assertSame(null, $proxy->$publicProperty); 108 } 109 110 /** 111 * @dataProvider getPropertyAccessProxies 112 */ 113 public function testPropertyUnset($instance, $proxy, $publicProperty) 114 { 115 /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */ 116 unset($proxy->$publicProperty); 117 118 $this->assertTrue(isset($instance->$publicProperty)); 119 $this->assertFalse(isset($proxy->$publicProperty)); 120 } 121 122 /** 123 * Generates a proxy for the given class name, and retrieves its class name 124 * 125 * @param string $parentClassName 126 * 127 * @return string 128 */ 129 private function generateProxy($parentClassName) 130 { 131 $generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo'); 132 $generator = new NullObjectGenerator(); 133 $generatedClass = new ClassGenerator($generatedClassName); 134 $strategy = new EvaluatingGeneratorStrategy(); 135 136 $generator->generate(new ReflectionClass($parentClassName), $generatedClass); 137 $strategy->generate($generatedClass); 138 139 return $generatedClassName; 140 } 141 142 /** 143 * Generates a list of object | invoked method | parameters | expected result 144 * 145 * @return array 146 */ 147 public function getProxyMethods() 148 { 149 $selfHintParam = new ClassWithSelfHint(); 150 151 $data = array( 152 array( 153 'ProxyManagerTestAsset\\BaseClass', 154 new BaseClass(), 155 'publicMethod', 156 array(), 157 'publicMethodDefault' 158 ), 159 array( 160 'ProxyManagerTestAsset\\BaseClass', 161 new BaseClass(), 162 'publicTypeHintedMethod', 163 array('param' => new \stdClass()), 164 'publicTypeHintedMethodDefault' 165 ), 166 array( 167 'ProxyManagerTestAsset\\BaseClass', 168 new BaseClass(), 169 'publicByReferenceMethod', 170 array(), 171 'publicByReferenceMethodDefault' 172 ), 173 array( 174 'ProxyManagerTestAsset\\BaseInterface', 175 new BaseClass(), 176 'publicMethod', 177 array(), 178 'publicMethodDefault' 179 ), 180 ); 181 182 if (PHP_VERSION_ID >= 50401) { 183 // PHP < 5.4.1 misbehaves, throwing strict standards, see https://bugs.php.net/bug.php?id=60573 184 $data[] = array( 185 'ProxyManagerTestAsset\\ClassWithSelfHint', 186 new ClassWithSelfHint(), 187 'selfHintMethod', 188 array('parameter' => $selfHintParam), 189 $selfHintParam 190 ); 191 } 192 193 return $data; 194 } 195 196 /** 197 * Generates proxies and instances with a public property to feed to the property accessor methods 198 * 199 * @return array 200 */ 201 public function getPropertyAccessProxies() 202 { 203 $instance1 = new BaseClass(); 204 $proxyName1 = $this->generateProxy(get_class($instance1)); 205 $instance2 = new BaseClass(); 206 $proxyName2 = $this->generateProxy(get_class($instance2)); 207 208 return array( 209 array( 210 $instance1, 211 new $proxyName1($instance1), 212 'publicProperty', 213 'publicPropertyDefault', 214 ), 215 array( 216 $instance2, 217 unserialize(serialize(new $proxyName2($instance2))), 218 'publicProperty', 219 'publicPropertyDefault', 220 ), 221 ); 222 } 223 }
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 |