[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/ProxyGenerator/Util/ -> PublicScopeSimulatorTest.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\Util;
  20  
  21  use PHPUnit_Framework_TestCase;
  22  use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
  23  use Zend\Code\Generator\PropertyGenerator;
  24  
  25  /**
  26   * Tests for {@see \ProxyManager\ProxyGenerator\Util\PublicScopeSimulator}
  27   *
  28   * @author Marco Pivetta <ocramius@gmail.com>
  29   * @license MIT
  30   *
  31   * @covers \ProxyManager\ProxyGenerator\Util\PublicScopeSimulator
  32   * @group Coverage
  33   */
  34  class PublicScopeSimulatorTest extends PHPUnit_Framework_TestCase
  35  {
  36      public function testSimpleGet()
  37      {
  38          $code = PublicScopeSimulator::getPublicAccessSimulationCode(
  39              PublicScopeSimulator::OPERATION_GET,
  40              'foo',
  41              null,
  42              null,
  43              'bar'
  44          );
  45  
  46          $this->assertStringMatchesFormat('%a{%areturn $%s->$foo;%a}%a$bar = %s;', $code);
  47      }
  48  
  49      public function testSimpleSet()
  50      {
  51          $code = PublicScopeSimulator::getPublicAccessSimulationCode(
  52              PublicScopeSimulator::OPERATION_SET,
  53              'foo',
  54              'baz',
  55              null,
  56              'bar'
  57          );
  58  
  59          $this->assertStringMatchesFormat('%a{%areturn $%s->$foo = $baz;%a}%a$bar = %s;', $code);
  60      }
  61  
  62      public function testSimpleIsset()
  63      {
  64          $code = PublicScopeSimulator::getPublicAccessSimulationCode(
  65              PublicScopeSimulator::OPERATION_ISSET,
  66              'foo',
  67              null,
  68              null,
  69              'bar'
  70          );
  71  
  72          $this->assertStringMatchesFormat('%a{%areturn isset($%s->$foo);%a}%a$bar = %s;', $code);
  73      }
  74  
  75      public function testSimpleUnset()
  76      {
  77          $code = PublicScopeSimulator::getPublicAccessSimulationCode(
  78              PublicScopeSimulator::OPERATION_UNSET,
  79              'foo',
  80              null,
  81              null,
  82              'bar'
  83          );
  84  
  85          $this->assertStringMatchesFormat('%a{%aunset($%s->$foo);%a}%a$bar = %s;', $code);
  86      }
  87  
  88      public function testSetRequiresValueParameterName()
  89      {
  90          $this->setExpectedException('InvalidArgumentException');
  91  
  92          PublicScopeSimulator::getPublicAccessSimulationCode(
  93              PublicScopeSimulator::OPERATION_SET,
  94              'foo',
  95              null,
  96              null,
  97              'bar'
  98          );
  99      }
 100  
 101      public function testDelegatesToValueHolderWhenAvailable()
 102      {
 103          $code = PublicScopeSimulator::getPublicAccessSimulationCode(
 104              PublicScopeSimulator::OPERATION_SET,
 105              'foo',
 106              'baz',
 107              new PropertyGenerator('valueHolder'),
 108              'bar'
 109          );
 110  
 111          $this->assertStringMatchesFormat(
 112              '%A$targetObject = $this->valueHolder;%a{%areturn $%s->$foo = $baz;%a}%a$bar = %s;',
 113              $code
 114          );
 115      }
 116  
 117      public function testSetRequiresValidOperation()
 118      {
 119          $this->setExpectedException('InvalidArgumentException');
 120  
 121          PublicScopeSimulator::getPublicAccessSimulationCode('invalid', 'foo');
 122      }
 123  
 124      public function testWillReturnDirectlyWithNoReturnParam()
 125      {
 126          $code = PublicScopeSimulator::getPublicAccessSimulationCode(
 127              PublicScopeSimulator::OPERATION_GET,
 128              'foo'
 129          );
 130  
 131          $this->assertStringMatchesFormat('%a{%areturn $%s->$foo;%a}%areturn %s;', $code);
 132      }
 133  }


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