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

LazyLoadingGhostFactoryTest.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 6.93 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\Factory;
 020   
 021  use PHPUnit_Framework_TestCase;
 022  use ProxyManager\Factory\LazyLoadingGhostFactory;
 023  use ProxyManager\Generator\ClassGenerator;
 024  use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
 025   
 026  /**
 027   * Tests for {@see \ProxyManager\Factory\LazyLoadingGhostFactory}
 028   *
 029   * @author Marco Pivetta <ocramius@gmail.com>
 030   * @license MIT
 031   *
 032   * @group Coverage
 033   */
 034  class LazyLoadingGhostFactoryTest extends PHPUnit_Framework_TestCase
 035  {
 036      /**
 037       * @var \PHPUnit_Framework_MockObject_MockObject
 038       */
 039      protected $inflector;
 040   
 041      /**
 042       * @var \PHPUnit_Framework_MockObject_MockObject
 043       */
 044      protected $signatureChecker;
 045   
 046      /**
 047       * @var \ProxyManager\Signature\ClassSignatureGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
 048       */
 049      private $classSignatureGenerator;
 050   
 051      /**
 052       * @var \ProxyManager\Configuration|\PHPUnit_Framework_MockObject_MockObject
 053       */
 054      protected $config;
 055   
 056      /**
 057       * {@inheritDoc}
 058       */
 059      public function setUp()
 060      {
 061          $this->config                  = $this->getMock('ProxyManager\\Configuration');
 062          $this->inflector               = $this->getMock('ProxyManager\\Inflector\\ClassNameInflectorInterface');
 063          $this->signatureChecker        = $this->getMock('ProxyManager\\Signature\\SignatureCheckerInterface');
 064          $this->classSignatureGenerator = $this->getMock('ProxyManager\\Signature\\ClassSignatureGeneratorInterface');
 065   
 066          $this
 067              ->config
 068              ->expects($this->any())
 069              ->method('getClassNameInflector')
 070              ->will($this->returnValue($this->inflector));
 071   
 072          $this
 073              ->config
 074              ->expects($this->any())
 075              ->method('getSignatureChecker')
 076              ->will($this->returnValue($this->signatureChecker));
 077   
 078          $this
 079              ->config
 080              ->expects($this->any())
 081              ->method('getClassSignatureGenerator')
 082              ->will($this->returnValue($this->classSignatureGenerator));
 083      }
 084   
 085      /**
 086       * {@inheritDoc}
 087       *
 088       * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::__construct
 089       */
 090      public function testWithOptionalFactory()
 091      {
 092          $factory = new LazyLoadingGhostFactory();
 093          $this->assertAttributeNotEmpty('configuration', $factory);
 094          $this->assertAttributeInstanceOf('ProxyManager\Configuration', 'configuration', $factory);
 095      }
 096   
 097      /**
 098       * {@inheritDoc}
 099       *
 100       * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::__construct
 101       * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::createProxy
 102       */
 103      public function testWillSkipAutoGeneration()
 104      {
 105          $className = UniqueIdentifierGenerator::getIdentifier('foo');
 106   
 107          $this
 108              ->inflector
 109              ->expects($this->once())
 110              ->method('getProxyClassName')
 111              ->with($className)
 112              ->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock'));
 113   
 114          $factory     = new LazyLoadingGhostFactory($this->config);
 115          $initializer = function () {
 116          };
 117          /* @var $proxy \ProxyManagerTestAsset\LazyLoadingMock */
 118          $proxy       = $factory->createProxy($className, $initializer);
 119   
 120          $this->assertInstanceOf('ProxyManagerTestAsset\\LazyLoadingMock', $proxy);
 121          $this->assertSame($initializer, $proxy->initializer);
 122      }
 123   
 124      /**
 125       * {@inheritDoc}
 126       *
 127       * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::__construct
 128       * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::createProxy
 129       * @covers \ProxyManager\Factory\LazyLoadingGhostFactory::getGenerator
 130       *
 131       * NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful
 132       */
 133      public function testWillTryAutoGeneration()
 134      {
 135          $className      = UniqueIdentifierGenerator::getIdentifier('foo');
 136          $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar');
 137          $generator      = $this->getMock('ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface');
 138          $autoloader     = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
 139   
 140          $this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator));
 141          $this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader));
 142   
 143          $generator
 144              ->expects($this->once())
 145              ->method('generate')
 146              ->with(
 147                  $this->callback(
 148                      function (ClassGenerator $targetClass) use ($proxyClassName) {
 149                          return $targetClass->getName() === $proxyClassName;
 150                      }
 151                  )
 152              );
 153   
 154          // simulate autoloading
 155          $autoloader
 156              ->expects($this->once())
 157              ->method('__invoke')
 158              ->with($proxyClassName)
 159              ->will(
 160                  $this->returnCallback(
 161                      function () use ($proxyClassName) {
 162                          eval('class ' . $proxyClassName . ' extends \\ProxyManagerTestAsset\\LazyLoadingMock {}');
 163                      }
 164                  )
 165              );
 166   
 167          $this
 168              ->inflector
 169              ->expects($this->once())
 170              ->method('getProxyClassName')
 171              ->with($className)
 172              ->will($this->returnValue($proxyClassName));
 173   
 174          $this
 175              ->inflector
 176              ->expects($this->once())
 177              ->method('getUserClassName')
 178              ->with($className)
 179              ->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock'));
 180   
 181          $this->signatureChecker->expects($this->atLeastOnce())->method('checkSignature');
 182          $this->classSignatureGenerator->expects($this->once())->method('addSignature')->will($this->returnArgument(0));
 183   
 184          $factory     = new LazyLoadingGhostFactory($this->config);
 185          $initializer = function () {
 186          };
 187          /* @var $proxy \ProxyManagerTestAsset\LazyLoadingMock */
 188          $proxy       = $factory->createProxy($className, $initializer);
 189   
 190          $this->assertInstanceOf($proxyClassName, $proxy);
 191          $this->assertSame($initializer, $proxy->initializer);
 192      }
 193  }
 194