Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

FatalPreventionFunctionalTest.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 5.80 KiB


001  <?php
002  /*
003   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
004   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
005   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
006   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
007   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
008   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
009   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
010   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
011   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
012   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
013   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
014   *
015   * This software consists of voluntary contributions made by many individuals
016   * and is licensed under the MIT license.
017   */
018   
019  namespace ProxyManagerTest\Functional;
020   
021  use PHPUnit_Framework_TestCase;
022  use PHPUnit_Util_PHP;
023  use ReflectionClass;
024   
025  /**
026   * Verifies that proxy-manager will not attempt to `eval()` code that will cause fatal errors
027   *
028   * @author Marco Pivetta <ocramius@gmail.com>
029   * @license MIT
030   *
031   * @group Functional
032   * @coversNothing
033   */
034  class FatalPreventionFunctionalTest extends PHPUnit_Framework_TestCase
035  {
036      private $template = <<<'PHP'
037  <?php
038   
039  require_once %s;
040   
041  $className               = %s;
042  $generatedClass          = new ProxyManager\Generator\ClassGenerator(uniqid('generated'));
043  $generatorStrategy       = new ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy();
044  $classGenerator          = new %s;
045  $classSignatureGenerator = new ProxyManager\Signature\ClassSignatureGenerator(
046      new ProxyManager\Signature\SignatureGenerator()
047  );
048   
049  try {
050      $classGenerator->generate(new ReflectionClass($className), $generatedClass);
051      $classSignatureGenerator->addSignature($generatedClass, array('eval tests'));
052      $generatorStrategy->generate($generatedClass);
053  } catch (ProxyManager\Exception\ExceptionInterface $e) {
054  } catch (ReflectionException $e) {
055  }
056   
057  echo 'SUCCESS: ' . %s;
058  PHP;
059   
060   
061      /**
062       * Verifies that code generation and evaluation will not cause fatals with any given class
063       *
064       * @param string $generatorClass an instantiable class (no arguments) implementing
065       *                               the {@see \ProxyManager\ProxyGenerator\ProxyGeneratorInterface}
066       * @param string $className      a valid (existing/autoloadable) class name
067       *
068       * @dataProvider getTestedClasses
069       */
070      public function testCodeGeneration($generatorClass, $className)
071      {
072          if (defined('HHVM_VERSION')) {
073              $this->markTestSkipped('HHVM is just too slow for this kind of test right now.');
074          }
075   
076          if (PHP_VERSION_ID < 50401) {
077              $this->markTestSkipped('Can\'t run this test suite on php < 5.4.1');
078          }
079   
080          $runner = PHPUnit_Util_PHP::factory();
081   
082          $code = sprintf(
083              $this->template,
084              var_export(realpath(__DIR__ . '/../../../vendor/autoload.php'), true),
085              var_export($className, true),
086              $generatorClass,
087              var_export($className, true)
088          );
089   
090          $result = $runner->runJob($code, array('-n'));
091   
092          if (('SUCCESS: ' . $className) !== $result['stdout']) {
093              $this->fail(sprintf(
094                  "Crashed with class '%s' and generator '%s'.\n\nStdout:\n%s\nStderr:\n%s\nGenerated code:\n%s'",
095                  $generatorClass,
096                  $className,
097                  $result['stdout'],
098                  $result['stderr'],
099                  $code
100              ));
101          }
102   
103          $this->assertSame('SUCCESS: ' . $className, $result['stdout']);
104      }
105   
106      /**
107       * @return string[][]
108       */
109      public function getTestedClasses()
110      {
111          $that = $this;
112   
113          return call_user_func_array(
114              'array_merge',
115              array_map(
116                  function ($generator) use ($that) {
117                      return array_map(
118                          function ($class) use ($generator) {
119                              return array($generator, $class);
120                          },
121                          $that->getProxyTestedClasses()
122                      );
123                  },
124                  array(
125                      'ProxyManager\\ProxyGenerator\\AccessInterceptorScopeLocalizerGenerator',
126                      'ProxyManager\\ProxyGenerator\\AccessInterceptorValueHolderGenerator',
127                      'ProxyManager\\ProxyGenerator\\LazyLoadingGhostGenerator',
128                      'ProxyManager\\ProxyGenerator\\LazyLoadingValueHolderGenerator',
129                      'ProxyManager\\ProxyGenerator\\NullObjectGenerator',
130                      'ProxyManager\\ProxyGenerator\\RemoteObjectGenerator',
131                  )
132              )
133          );
134      }
135   
136      /**
137       * @private (public only for PHP 5.3 compatibility)
138       *
139       * @return string[]
140       */
141      public function getProxyTestedClasses()
142      {
143          $skippedPaths = array(
144              realpath(__DIR__ . '/../../src'),
145              realpath(__DIR__ . '/../../vendor'),
146              realpath(__DIR__ . '/../../tests/ProxyManagerTest'),
147          );
148   
149          return array_filter(
150              get_declared_classes(),
151              function ($className) use ($skippedPaths) {
152                  $reflectionClass = new ReflectionClass($className);
153                  $fileName        = $reflectionClass->getFileName();
154   
155                  if (! $fileName) {
156                      return false;
157                  }
158   
159                  $realPath = realpath($fileName);
160   
161                  foreach ($skippedPaths as $skippedPath) {
162                      if (0 === strpos($realPath, $skippedPath)) {
163                          // skip classes defined within ProxyManager, vendor or the test suite
164                          return false;
165                      }
166                  }
167   
168                  return true;
169              }
170          );
171      }
172  }
173