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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
RemoteObjectFunctionalTest.php
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\Functional;
020
021 use PHPUnit_Framework_TestCase;
022 use ProxyManager\Factory\RemoteObject\Adapter\JsonRpc as JsonRpcAdapter;
023 use ProxyManager\Factory\RemoteObject\Adapter\XmlRpc as XmlRpcAdapter;
024 use ProxyManager\Generator\ClassGenerator;
025 use ProxyManager\Generator\Util\UniqueIdentifierGenerator;
026 use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
027 use ProxyManager\ProxyGenerator\RemoteObjectGenerator;
028 use ProxyManagerTestAsset\ClassWithSelfHint;
029 use ProxyManagerTestAsset\RemoteProxy\Foo;
030 use ReflectionClass;
031
032 /**
033 * Tests for {@see \ProxyManager\ProxyGenerator\RemoteObjectGenerator} produced objects
034 *
035 * @author Vincent Blanchon <blanchon.vincent@gmail.com>
036 * @license MIT
037 *
038 * @group Functional
039 * @coversNothing
040 */
041 class RemoteObjectFunctionalTest extends PHPUnit_Framework_TestCase
042 {
043 /**
044 * @param mixed $expectedValue
045 * @param string $method
046 * @param array $params
047 *
048 * @return XmlRpcAdapter
049 */
050 protected function getXmlRpcAdapter($expectedValue, $method, array $params)
051 {
052 $client = $this
053 ->getMockBuilder('Zend\Server\Client')
054 ->setMethods(array('call'))
055 ->getMock();
056
057 $client
058 ->expects($this->any())
059 ->method('call')
060 ->with($this->stringEndsWith($method), $params)
061 ->will($this->returnValue($expectedValue));
062
063 $adapter = new XmlRpcAdapter(
064 $client,
065 array(
066 'ProxyManagerTestAsset\RemoteProxy\Foo.foo'
067 => 'ProxyManagerTestAsset\RemoteProxy\FooServiceInterface.foo'
068 )
069 );
070
071 return $adapter;
072 }
073
074 /**
075 * @param mixed $expectedValue
076 * @param string $method
077 * @param array $params
078 *
079 * @return JsonRpcAdapter
080 */
081 protected function getJsonRpcAdapter($expectedValue, $method, array $params)
082 {
083 $client = $this
084 ->getMockBuilder('Zend\Server\Client')
085 ->setMethods(array('call'))
086 ->getMock();
087
088 $client
089 ->expects($this->any())
090 ->method('call')
091 ->with($this->stringEndsWith($method), $params)
092 ->will($this->returnValue($expectedValue));
093
094 $adapter = new JsonRpcAdapter(
095 $client,
096 array(
097 'ProxyManagerTestAsset\RemoteProxy\Foo.foo'
098 => 'ProxyManagerTestAsset\RemoteProxy\FooServiceInterface.foo'
099 )
100 );
101
102 return $adapter;
103 }
104
105 /**
106 * @dataProvider getProxyMethods
107 */
108 public function testXmlRpcMethodCalls($instanceOrClassname, $method, $params, $expectedValue)
109 {
110 $proxyName = $this->generateProxy($instanceOrClassname);
111
112 /* @var $proxy \ProxyManager\Proxy\RemoteObjectInterface */
113 $proxy = new $proxyName($this->getXmlRpcAdapter($expectedValue, $method, $params));
114
115 $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params));
116 }
117
118 /**
119 * @dataProvider getProxyMethods
120 */
121 public function testJsonRpcMethodCalls($instanceOrClassname, $method, $params, $expectedValue)
122 {
123 $proxyName = $this->generateProxy($instanceOrClassname);
124
125 /* @var $proxy \ProxyManager\Proxy\RemoteObjectInterface */
126 $proxy = new $proxyName($this->getJsonRpcAdapter($expectedValue, $method, $params));
127
128 $this->assertSame($expectedValue, call_user_func_array(array($proxy, $method), $params));
129 }
130
131 /**
132 * @dataProvider getPropertyAccessProxies
133 */
134 public function testJsonRpcPropertyReadAccess($instanceOrClassname, $publicProperty, $propertyValue)
135 {
136 $proxyName = $this->generateProxy($instanceOrClassname);
137
138 /* @var $proxy \ProxyManager\Proxy\RemoteObjectInterface */
139 $proxy = new $proxyName(
140 $this->getJsonRpcAdapter($propertyValue, '__get', array($publicProperty))
141 );
142
143 /* @var $proxy \ProxyManager\Proxy\NullObjectInterface */
144 $this->assertSame($propertyValue, $proxy->$publicProperty);
145 }
146
147 /**
148 * Generates a proxy for the given class name, and retrieves its class name
149 *
150 * @param string $parentClassName
151 *
152 * @return string
153 */
154 private function generateProxy($parentClassName)
155 {
156 $generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo');
157 $generator = new RemoteObjectGenerator();
158 $generatedClass = new ClassGenerator($generatedClassName);
159 $strategy = new EvaluatingGeneratorStrategy();
160
161 $generator->generate(new ReflectionClass($parentClassName), $generatedClass);
162 $strategy->generate($generatedClass);
163
164 return $generatedClassName;
165 }
166
167 /**
168 * Generates a list of object | invoked method | parameters | expected result
169 *
170 * @return array
171 */
172 public function getProxyMethods()
173 {
174 $selfHintParam = new ClassWithSelfHint();
175
176 $data = array(
177 array(
178 'ProxyManagerTestAsset\RemoteProxy\FooServiceInterface',
179 'foo',
180 array(),
181 'bar remote'
182 ),
183 array(
184 'ProxyManagerTestAsset\RemoteProxy\Foo',
185 'foo',
186 array(),
187 'bar remote'
188 ),
189 array(
190 new Foo(),
191 'foo',
192 array(),
193 'bar remote'
194 ),
195 array(
196 'ProxyManagerTestAsset\RemoteProxy\BazServiceInterface',
197 'baz',
198 array('baz'),
199 'baz remote'
200 ),
201 );
202
203 if (PHP_VERSION_ID >= 50401) {
204 // PHP < 5.4.1 misbehaves, throwing strict standards, see https://bugs.php.net/bug.php?id=60573
205 $data[] = array(
206 new ClassWithSelfHint(),
207 'selfHintMethod',
208 array($selfHintParam),
209 $selfHintParam
210 );
211 }
212
213 return $data;
214 }
215
216 /**
217 * Generates proxies and instances with a public property to feed to the property accessor methods
218 *
219 * @return array
220 */
221 public function getPropertyAccessProxies()
222 {
223 return array(
224 array(
225 'ProxyManagerTestAsset\RemoteProxy\FooServiceInterface',
226 'publicProperty',
227 'publicProperty remote',
228 ),
229 );
230 }
231 }
232