Permalink
Browse files

added FlyAdapter Tests

  • Loading branch information...
1 parent beb9d45 commit 7fa2dc80d3b64a8d8a715bcbf890b858340d8ae4 @tidal committed Jun 30, 2011
Showing with 56 additions and 6 deletions.
  1. +6 −6 src/Base/FlyAdapter.php
  2. +50 −0 tests/base/FlyAdapterTest.php
View
@@ -18,10 +18,6 @@
* @subpackage base
*/
-
-
-
-
class FlyAdapter {
@@ -30,7 +26,7 @@ class FlyAdapter {
* @param $methodMap
* @return
*/
- public function __construct(ArrayAccess $methodMap){
+ public function __construct(array $methodMap){
$this->methodMap = $methodMap;
}
@@ -54,8 +50,12 @@ public function setSubject($subject){
*/
public function __call($method, $arguments){
if(array_key_exists($method, $this->methodMap)){
- return call_user_func_array(array($this->subject, $this->methodMap[$method]), $arguments);
+ return call_user_func_array(
+ array($this->subject, $this->methodMap[$method]),
+ $arguments
+ );
}
+ return false;
}
}
@@ -0,0 +1,50 @@
+<?php
+
+
+
+require_once dirname(__FILE__).'/../../misc/bootstrap.php';
+
+PHPUnit_Util_Fileloader::checkAndLoad(dirname(__FILE__).'/../_files/HelloService.php');
+
+/**
+ * Test class for FlyAdapter.
+ * Generated by PHPUnit on 2011-07-01 at 01:02:31.
+ */
+class FlyAdapterTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @var FlyAdapter
+ */
+ protected $object;
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp() {
+ $map = array(
+ 'foo' => 'greet',
+ 'bar' => 'getName'
+ );
+ $this->object = new HelloService;
+ $this->adapter = new \PEIP\Base\FlyAdapter($map);
+ }
+
+
+ public function testCall() {
+ $this->assertEquals(
+ $this->object->greet(),
+ $this->adapter->setSubject($this->object)->foo()
+ );
+ $this->assertEquals(
+ $this->object->getName(),
+ $this->adapter->setSubject($this->object)->bar()
+ );
+ $this->assertFalse(
+ $this->adapter->setSubject($this->object)->foobar()
+ );
+ }
+
+}
+
+

0 comments on commit 7fa2dc8

Please sign in to comment.