[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Functional/ -> MultipleProxyGenerationTest.php (source)

   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\Factory\AccessInterceptorScopeLocalizerFactory;
  23  use ProxyManager\Factory\AccessInterceptorValueHolderFactory;
  24  use ProxyManager\Factory\LazyLoadingGhostFactory;
  25  use ProxyManager\Factory\LazyLoadingValueHolderFactory;
  26  use ReflectionClass;
  27  use ReflectionProperty;
  28  
  29  /**
  30   * Verifies that proxy factories don't conflict with each other when generating proxies
  31   *
  32   * @author Marco Pivetta <ocramius@gmail.com>
  33   * @license MIT
  34   *
  35   * @link https://github.com/Ocramius/ProxyManager/issues/10
  36   *
  37   * @group Functional
  38   * @group issue-10
  39   * @coversNothing
  40   */
  41  class MultipleProxyGenerationTest extends PHPUnit_Framework_TestCase
  42  {
  43      /**
  44       * Verifies that proxies generated from different factories will retain their specific implementation
  45       * and won't conflict
  46       *
  47       * @dataProvider getTestedClasses
  48       */
  49      public function testCanGenerateMultipleDifferentProxiesForSameClass($className)
  50      {
  51          $skipScopeLocalizerTests                = false;
  52          $ghostProxyFactory                      = new LazyLoadingGhostFactory();
  53          $virtualProxyFactory                    = new LazyLoadingValueHolderFactory();
  54          $accessInterceptorFactory               = new AccessInterceptorValueHolderFactory();
  55          $accessInterceptorScopeLocalizerFactory = new AccessInterceptorScopeLocalizerFactory();
  56          $initializer                            = function () {
  57          };
  58  
  59          $reflectionClass = new ReflectionClass($className);
  60  
  61          if ((! method_exists('Closure', 'bind')) && $reflectionClass->getProperties(ReflectionProperty::IS_PRIVATE)) {
  62              $skipScopeLocalizerTests = true;
  63          }
  64  
  65          $generated = array(
  66              $ghostProxyFactory->createProxy($className, $initializer),
  67              $virtualProxyFactory->createProxy($className, $initializer),
  68              $accessInterceptorFactory->createProxy(new $className()),
  69          );
  70  
  71          if (! $skipScopeLocalizerTests) {
  72              $generated[] = $accessInterceptorScopeLocalizerFactory->createProxy(new $className());
  73          }
  74  
  75          foreach ($generated as $key => $proxy) {
  76              $this->assertInstanceOf($className, $proxy);
  77  
  78              foreach ($generated as $comparedKey => $comparedProxy) {
  79                  if ($comparedKey === $key) {
  80                      continue;
  81                  }
  82  
  83                  $this->assertNotSame(get_class($comparedProxy), get_class($proxy));
  84              }
  85          }
  86  
  87          $this->assertInstanceOf('ProxyManager\Proxy\GhostObjectInterface', $generated[0]);
  88          $this->assertInstanceOf('ProxyManager\Proxy\VirtualProxyInterface', $generated[1]);
  89          $this->assertInstanceOf('ProxyManager\Proxy\AccessInterceptorInterface', $generated[2]);
  90          $this->assertInstanceOf('ProxyManager\Proxy\ValueHolderInterface', $generated[2]);
  91  
  92          if (! $skipScopeLocalizerTests) {
  93              $this->assertInstanceOf('ProxyManager\Proxy\AccessInterceptorInterface', $generated[3]);
  94          }
  95      }
  96  
  97      /**
  98       * @return string[][]
  99       */
 100      public function getTestedClasses()
 101      {
 102          $data = array(
 103              array('ProxyManagerTestAsset\\BaseClass'),
 104              array('ProxyManagerTestAsset\\ClassWithMagicMethods'),
 105              array('ProxyManagerTestAsset\\ClassWithFinalMethods'),
 106              array('ProxyManagerTestAsset\\ClassWithFinalMagicMethods'),
 107              array('ProxyManagerTestAsset\\ClassWithByRefMagicMethods'),
 108              array('ProxyManagerTestAsset\\ClassWithMixedProperties'),
 109              array('ProxyManagerTestAsset\\ClassWithPrivateProperties'),
 110              array('ProxyManagerTestAsset\\ClassWithProtectedProperties'),
 111              array('ProxyManagerTestAsset\\ClassWithPublicProperties'),
 112              array('ProxyManagerTestAsset\\EmptyClass'),
 113              array('ProxyManagerTestAsset\\HydratedObject'),
 114          );
 115  
 116          if (PHP_VERSION_ID >= 50401) {
 117              // PHP < 5.4.1 misbehaves, throwing strict standards, see https://bugs.php.net/bug.php?id=60573
 118              $data[] = array('ProxyManagerTestAsset\\ClassWithSelfHint');
 119          }
 120  
 121          return $data;
 122      }
 123  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1