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

RemoteObjectFactoryTest.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 6.44 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\RemoteObjectFactory;
 023  use ProxyManager\Generator\ClassGenerator;
 024  use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
 025   
 026  /**
 027   * Tests for {@see \ProxyManager\Factory\RemoteObjectFactory}
 028   *
 029   * @author Vincent Blanchon <blanchon.vincent@gmail.com>
 030   * @license MIT
 031   *
 032   * @group Coverage
 033   */
 034  class RemoteObjectFactoryTest 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\RemoteObjectFactory::__construct
 089       * @covers \ProxyManager\Factory\RemoteObjectFactory::createProxy
 090       * @covers \ProxyManager\Factory\RemoteObjectFactory::getGenerator
 091       */
 092      public function testWillSkipAutoGeneration()
 093      {
 094          $this
 095              ->inflector
 096              ->expects($this->once())
 097              ->method('getProxyClassName')
 098              ->with('ProxyManagerTestAsset\\BaseInterface')
 099              ->will($this->returnValue('StdClass'));
 100   
 101          $adapter = $this->getMock('ProxyManager\Factory\RemoteObject\AdapterInterface');
 102          $factory = new RemoteObjectFactory($adapter, $this->config);
 103          /* @var $proxy \stdClass */
 104          $proxy   = $factory->createProxy('ProxyManagerTestAsset\\BaseInterface', $adapter);
 105   
 106          $this->assertInstanceOf('stdClass', $proxy);
 107      }
 108   
 109      /**
 110       * {@inheritDoc}
 111       *
 112       * @covers \ProxyManager\Factory\RemoteObjectFactory::__construct
 113       * @covers \ProxyManager\Factory\RemoteObjectFactory::createProxy
 114       * @covers \ProxyManager\Factory\RemoteObjectFactory::getGenerator
 115       *
 116       * NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful
 117       */
 118      public function testWillTryAutoGeneration()
 119      {
 120          $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar');
 121          $generator      = $this->getMock('ProxyManager\GeneratorStrategy\\GeneratorStrategyInterface');
 122          $autoloader     = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
 123   
 124          $this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator));
 125          $this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader));
 126   
 127          $generator
 128              ->expects($this->once())
 129              ->method('generate')
 130              ->with(
 131                  $this->callback(
 132                      function (ClassGenerator $targetClass) use ($proxyClassName) {
 133                          return $targetClass->getName() === $proxyClassName;
 134                      }
 135                  )
 136              );
 137   
 138          // simulate autoloading
 139          $autoloader
 140              ->expects($this->once())
 141              ->method('__invoke')
 142              ->with($proxyClassName)
 143              ->will(
 144                  $this->returnCallback(
 145                      function () use ($proxyClassName) {
 146                          eval(
 147                              'class ' . $proxyClassName
 148                              . ' extends stdClass {}'
 149                          );
 150                      }
 151                  )
 152              );
 153   
 154          $this
 155              ->inflector
 156              ->expects($this->once())
 157              ->method('getProxyClassName')
 158              ->with('ProxyManagerTestAsset\\BaseInterface')
 159              ->will($this->returnValue($proxyClassName));
 160   
 161          $this
 162              ->inflector
 163              ->expects($this->once())
 164              ->method('getUserClassName')
 165              ->with('ProxyManagerTestAsset\\BaseInterface')
 166              ->will($this->returnValue('stdClass'));
 167   
 168          $this->signatureChecker->expects($this->atLeastOnce())->method('checkSignature');
 169          $this->classSignatureGenerator->expects($this->once())->method('addSignature')->will($this->returnArgument(0));
 170   
 171          $adapter = $this->getMock('ProxyManager\Factory\RemoteObject\AdapterInterface');
 172          $factory = new RemoteObjectFactory($adapter, $this->config);
 173          /* @var $proxy \stdClass */
 174          $proxy   = $factory->createProxy('ProxyManagerTestAsset\\BaseInterface', $adapter);
 175   
 176          $this->assertInstanceOf($proxyClassName, $proxy);
 177      }
 178  }
 179