[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
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\MagicUnset; 24 25 /** 26 * Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicUnset} 27 * 28 * @author Marco Pivetta <ocramius@gmail.com> 29 * @license MIT 30 * 31 * @group Coverage 32 */ 33 class MagicUnsetTest 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\MagicUnset::__construct 70 */ 71 public function testBodyStructure() 72 { 73 $reflection = new ReflectionClass('ProxyManagerTestAsset\\EmptyClass'); 74 $magicIsset = new MagicUnset($reflection, $this->initializer, $this->initMethod, $this->publicProperties); 75 76 $this->assertSame('__unset', $magicIsset->getName()); 77 $this->assertCount(1, $magicIsset->getParameters()); 78 $this->assertStringMatchesFormat( 79 "\$this->foo && \$this->baz('__unset', array('name' => \$name));\n\n" 80 . "if (isset(self::\$bar[\$name])) {\n unset(\$this->\$name);\n\n return;\n}" 81 . "%areturn %s;", 82 $magicIsset->getBody() 83 ); 84 } 85 86 /** 87 * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicUnset::__construct 88 */ 89 public function testBodyStructureWithPublicProperties() 90 { 91 $reflection = new ReflectionClass( 92 'ProxyManagerTestAsset\\ProxyGenerator\\LazyLoading\\MethodGenerator\\ClassWithTwoPublicProperties' 93 ); 94 95 $magicIsset = new MagicUnset($reflection, $this->initializer, $this->initMethod, $this->publicProperties); 96 97 $this->assertSame('__unset', $magicIsset->getName()); 98 $this->assertCount(1, $magicIsset->getParameters()); 99 $this->assertStringMatchesFormat( 100 "\$this->foo && \$this->baz('__unset', array('name' => \$name));\n\n" 101 . "if (isset(self::\$bar[\$name])) {\n unset(\$this->\$name);\n\n return;\n}" 102 . "%areturn %s;", 103 $magicIsset->getBody() 104 ); 105 } 106 107 /** 108 * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\MagicUnset::__construct 109 */ 110 public function testBodyStructureWithOverriddenMagicGet() 111 { 112 $reflection = new ReflectionClass('ProxyManagerTestAsset\\ClassWithMagicMethods'); 113 $magicIsset = new MagicUnset($reflection, $this->initializer, $this->initMethod, $this->publicProperties); 114 115 $this->assertSame('__unset', $magicIsset->getName()); 116 $this->assertCount(1, $magicIsset->getParameters()); 117 $this->assertSame( 118 "\$this->foo && \$this->baz('__unset', array('name' => \$name));\n\n" 119 . "if (isset(self::\$bar[\$name])) {\n unset(\$this->\$name);\n\n return;\n}\n\n" 120 . "return parent::__unset(\$name);", 121 $magicIsset->getBody() 122 ); 123 } 124 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |