[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/ -> MagicGetTest.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\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
  20  
  21  use ReflectionClass;
  22  use PHPUnit_Framework_TestCase;
  23  use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet;
  24  
  25  /**
  26   * Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet}
  27   *
  28   * @author Marco Pivetta <ocramius@gmail.com>
  29   * @license MIT
  30   *
  31   * @group Coverage
  32   */
  33  class MagicGetTest extends PHPUnit_Framework_TestCase
  34  {
  35      /**
  36       * @var \Zend\Code\Generator\PropertyGenerator|\PHPUnit_Framework_MockObject_MockObject
  37       */
  38      protected $initializer;
  39  
  40      /**
  41       * @var \Zend\Code\Generator\MethodGenerator|\PHPUnit_Framework_MockObject_MockObject
  42       */
  43      protected $initMethod;
  44  
  45      /**
  46       * @var \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap|\PHPUnit_Framework_MockObject_MockObject
  47       */
  48      protected $publicProperties;
  49  
  50      /**
  51       * {@inheritDoc}
  52       */
  53      protected function setUp()
  54      {
  55          $this->initializer      = $this->getMock('Zend\\Code\\Generator\\PropertyGenerator');
  56          $this->initMethod       = $this->getMock('Zend\\Code\\Generator\\MethodGenerator');
  57          $this->publicProperties = $this
  58              ->getMockBuilder('ProxyManager\\ProxyGenerator\\PropertyGenerator\\PublicPropertiesMap')
  59              ->disableOriginalConstructor()
  60              ->getMock();
  61  
  62          $this->initializer->expects($this->any())->method('getName')->will($this->returnValue('foo'));
  63          $this->initMethod->expects($this->any())->method('getName')->will($this->returnValue('baz'));
  64          $this->publicProperties->expects($this->any())->method('isEmpty')->will($this->returnValue(false));
  65          $this->publicProperties->expects($this->any())->method('getName')->will($this->returnValue('bar'));
  66      }
  67  
  68      /**
  69       * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet::__construct
  70       */
  71      public function testBodyStructure()
  72      {
  73          $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
  74          $magicGet   = new MagicGet($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
  75  
  76          $this->assertSame('__get', $magicGet->getName());
  77          $this->assertCount(1, $magicGet->getParameters());
  78          $this->assertStringMatchesFormat(
  79              "\$this->foo && \$this->baz('__get', array('name' => \$name));\n\n"
  80              . "if (isset(self::\$bar[\$name])) {\n    return \$this->\$name;\n}\n\n"
  81              . "%a",
  82              $magicGet->getBody()
  83          );
  84      }
  85  
  86      /**
  87       * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet::__construct
  88       */
  89      public function testBodyStructureWithPublicProperties()
  90      {
  91          $reflection = new ReflectionClass(
  92              'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties'
  93          );
  94  
  95          $magicGet = new MagicGet($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
  96  
  97          $this->assertSame('__get', $magicGet->getName());
  98          $this->assertCount(1, $magicGet->getParameters());
  99          $this->assertStringMatchesFormat(
 100              "\$this->foo && \$this->baz('__get', array('name' => \$name));\n\n"
 101              . "if (isset(self::\$bar[\$name])) {\n    return \$this->\$name;\n}\n\n"
 102              . "%a",
 103              $magicGet->getBody()
 104          );
 105      }
 106  
 107      /**
 108       * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicGet::__construct
 109       */
 110      public function testBodyStructureWithOverriddenMagicGet()
 111      {
 112          $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods');
 113          $magicGet   = new MagicGet($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
 114  
 115          $this->assertSame('__get', $magicGet->getName());
 116          $this->assertCount(1, $magicGet->getParameters());
 117          $this->assertSame(
 118              "\$this->foo && \$this->baz('__get', array('name' => \$name));\n\n"
 119              . "if (isset(self::\$bar[\$name])) {\n    return \$this->\$name;\n}\n\n"
 120              . "return parent::__get(\$name);",
 121              $magicGet->getBody()
 122          );
 123      }
 124  }


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