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

NullObjectFactoryTest.php

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