[ 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 PHPUnit_Util_PHP; 23 use ReflectionClass; 24 25 /** 26 * Verifies that proxy-manager will not attempt to `eval()` code that will cause fatal errors 27 * 28 * @author Marco Pivetta <ocramius@gmail.com> 29 * @license MIT 30 * 31 * @group Functional 32 * @coversNothing 33 */ 34 class FatalPreventionFunctionalTest extends PHPUnit_Framework_TestCase 35 { 36 private $template = <<<'PHP' 37 <?php 38 39 require_once %s; 40 41 $className = %s; 42 $generatedClass = new ProxyManager\Generator\ClassGenerator(uniqid('generated')); 43 $generatorStrategy = new ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy(); 44 $classGenerator = new %s; 45 $classSignatureGenerator = new ProxyManager\Signature\ClassSignatureGenerator( 46 new ProxyManager\Signature\SignatureGenerator() 47 ); 48 49 try { 50 $classGenerator->generate(new ReflectionClass($className), $generatedClass); 51 $classSignatureGenerator->addSignature($generatedClass, array('eval tests')); 52 $generatorStrategy->generate($generatedClass); 53 } catch (ProxyManager\Exception\ExceptionInterface $e) { 54 } catch (ReflectionException $e) { 55 } 56 57 echo 'SUCCESS: ' . %s; 58 PHP; 59 60 /** 61 * Verifies that code generation and evaluation will not cause fatals with any given class 62 * 63 * @param string $generatorClass an instantiable class (no arguments) implementing 64 * the {@see \ProxyManager\ProxyGenerator\ProxyGeneratorInterface} 65 * @param string $className a valid (existing/autoloadable) class name 66 * 67 * @dataProvider getTestedClasses 68 */ 69 public function testCodeGeneration($generatorClass, $className) 70 { 71 if (defined('HHVM_VERSION')) { 72 $this->markTestSkipped('HHVM is just too slow for this kind of test right now.'); 73 } 74 75 if (PHP_VERSION_ID < 50401) { 76 $this->markTestSkipped('Can\'t run this test suite on php < 5.4.1'); 77 } 78 79 $runner = PHPUnit_Util_PHP::factory(); 80 81 $code = sprintf( 82 $this->template, 83 var_export(realpath(__DIR__ . '/../../../vendor/autoload.php'), true), 84 var_export($className, true), 85 $generatorClass, 86 var_export($className, true) 87 ); 88 89 $result = $runner->runJob($code, array('-n')); 90 91 if (('SUCCESS: ' . $className) !== $result['stdout']) { 92 $this->fail(sprintf( 93 "Crashed with class '%s' and generator '%s'.\n\nStdout:\n%s\nStderr:\n%s\nGenerated code:\n%s'", 94 $generatorClass, 95 $className, 96 $result['stdout'], 97 $result['stderr'], 98 $code 99 )); 100 } 101 102 $this->assertSame('SUCCESS: ' . $className, $result['stdout']); 103 } 104 105 /** 106 * @return string[][] 107 */ 108 public function getTestedClasses() 109 { 110 $that = $this; 111 112 return call_user_func_array( 113 'array_merge', 114 array_map( 115 function ($generator) use ($that) { 116 return array_map( 117 function ($class) use ($generator) { 118 return array($generator, $class); 119 }, 120 $that->getProxyTestedClasses() 121 ); 122 }, 123 array( 124 'ProxyManager\\ProxyGenerator\\AccessInterceptorScopeLocalizerGenerator', 125 'ProxyManager\\ProxyGenerator\\AccessInterceptorValueHolderGenerator', 126 'ProxyManager\\ProxyGenerator\\LazyLoadingGhostGenerator', 127 'ProxyManager\\ProxyGenerator\\LazyLoadingValueHolderGenerator', 128 'ProxyManager\\ProxyGenerator\\NullObjectGenerator', 129 'ProxyManager\\ProxyGenerator\\RemoteObjectGenerator', 130 ) 131 ) 132 ); 133 } 134 135 /** 136 * @private (public only for PHP 5.3 compatibility) 137 * 138 * @return string[] 139 */ 140 public function getProxyTestedClasses() 141 { 142 $skippedPaths = array( 143 realpath(__DIR__ . '/../../src'), 144 realpath(__DIR__ . '/../../vendor'), 145 realpath(__DIR__ . '/../../tests/ProxyManagerTest'), 146 ); 147 148 return array_filter( 149 get_declared_classes(), 150 function ($className) use ($skippedPaths) { 151 $reflectionClass = new ReflectionClass($className); 152 $fileName = $reflectionClass->getFileName(); 153 154 if (! $fileName) { 155 return false; 156 } 157 158 $realPath = realpath($fileName); 159 160 foreach ($skippedPaths as $skippedPath) { 161 if (0 === strpos($realPath, $skippedPath)) { 162 // skip classes defined within ProxyManager, vendor or the test suite 163 return false; 164 } 165 } 166 167 return true; 168 } 169 ); 170 } 171 }
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 |