[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/LazyLoadingGhost/MethodGenerator/ -> MagicIssetTest.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\MagicIsset;
  24  
  25  /**
  26   * Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicIsset}
  27   *
  28   * @author Marco Pivetta <ocramius@gmail.com>
  29   * @license MIT
  30   *
  31   * @group Coverage
  32   */
  33  class MagicIssetTest 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\MagicIsset::__construct
  70       */
  71      public function testBodyStructure()
  72      {
  73          $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass');
  74          $magicIsset = new MagicIsset($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
  75  
  76          $this->assertSame('__isset', $magicIsset->getName());
  77          $this->assertCount(1, $magicIsset->getParameters());
  78          $this->assertStringMatchesFormat(
  79              "\$this->foo && \$this->baz('__isset', array('name' => \$name));\n\n"
  80              . "if (isset(self::\$bar[\$name])) {\n    return isset(\$this->\$name);\n}\n\n"
  81              . "%areturn %s;",
  82              $magicIsset->getBody()
  83          );
  84      }
  85  
  86      /**
  87       * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicIsset::__construct
  88       */
  89      public function testBodyStructureWithPublicProperties()
  90      {
  91          $reflection = new ReflectionClass(
  92              'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties'
  93          );
  94          $magicIsset = new MagicIsset($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
  95  
  96          $this->assertSame('__isset', $magicIsset->getName());
  97          $this->assertCount(1, $magicIsset->getParameters());
  98          $this->assertStringMatchesFormat(
  99              "\$this->foo && \$this->baz('__isset', array('name' => \$name));\n\n"
 100              . "if (isset(self::\$bar[\$name])) {\n    return isset(\$this->\$name);\n}\n\n"
 101              . "%areturn %s;",
 102              $magicIsset->getBody()
 103          );
 104      }
 105  
 106      /**
 107       * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicIsset::__construct
 108       */
 109      public function testBodyStructureWithOverriddenMagicGet()
 110      {
 111          $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods');
 112          $magicIsset = new MagicIsset($reflection, $this->initializer, $this->initMethod, $this->publicProperties);
 113  
 114          $this->assertSame('__isset', $magicIsset->getName());
 115          $this->assertCount(1, $magicIsset->getParameters());
 116          $this->assertSame(
 117              "\$this->foo && \$this->baz('__isset', array('name' => \$name));\n\n"
 118              . "if (isset(self::\$bar[\$name])) {\n    return isset(\$this->\$name);\n}\n\n"
 119              . "return parent::__isset(\$name);",
 120              $magicIsset->getBody()
 121          );
 122      }
 123  }


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