Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
[zendframework/zendframework#5379] Move test assets to separate files
Browse files Browse the repository at this point in the history
- Moved classes, functions used by test case to separate files
  • Loading branch information
weierophinney committed Oct 30, 2013
1 parent 6c7b1b9 commit cf6868a
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 89 deletions.
109 changes: 20 additions & 89 deletions test/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Zend\Json\Server\Request;
use Zend\Json\Server\Response;

require_once __DIR__ . '/TestAsset/FooFunc.php';

/**
* Test class for Zend_JSON_Server
*
Expand Down Expand Up @@ -236,8 +238,8 @@ public function testSmdObjectRetrievedFromServerShouldReflectServerState()

public function testHandleValidMethodShouldWork()
{
$this->server->setClass('ZendTest\\Json\\Foo')
->addFunction('ZendTest\\Json\\FooFunc')
$this->server->setClass('ZendTest\\Json\\TestAsset\\Foo')
->addFunction('ZendTest\\Json\\TestAsset\\FooFunc')
->setReturnResponse(true);
$request = $this->server->getRequest();
$request->setMethod('bar')
Expand All @@ -248,7 +250,7 @@ public function testHandleValidMethodShouldWork()
$this->assertFalse($response->isError());


$request->setMethod('ZendTest\\Json\\FooFunc')
$request->setMethod('ZendTest\\Json\\TestAsset\\FooFunc')
->setId('foo');
$response = $this->server->handle();
$this->assertTrue($response instanceof Response);
Expand All @@ -257,8 +259,8 @@ public function testHandleValidMethodShouldWork()

public function testHandleValidMethodWithNULLParamValueShouldWork()
{
$this->server->setClass('ZendTest\\Json\\Foo')
->addFunction('ZendTest\\Json\\FooFunc')
$this->server->setClass('ZendTest\\Json\\TestAsset\\Foo')
->addFunction('ZendTest\\Json\\TestAsset\\FooFunc')
->setReturnResponse(true);
$request = $this->server->getRequest();
$request->setMethod('bar')
Expand All @@ -271,7 +273,7 @@ public function testHandleValidMethodWithNULLParamValueShouldWork()

public function testHandleValidMethodWithTooFewParamsShouldPassDefaultsOrNullsForMissingParams()
{
$this->server->setClass('ZendTest\Json\Foo')
$this->server->setClass('ZendTest\Json\TestAsset\Foo')
->setReturnResponse(true);
$request = $this->server->getRequest();
$request->setMethod('bar')
Expand All @@ -289,7 +291,7 @@ public function testHandleValidMethodWithTooFewParamsShouldPassDefaultsOrNullsFo

public function testHandleValidMethodWithTooFewAssociativeParamsShouldPassDefaultsOrNullsForMissingParams()
{
$this->server->setClass('ZendTest\Json\Foo')
$this->server->setClass('ZendTest\Json\TestAsset\Foo')
->setReturnResponse(true);
$request = $this->server->getRequest();
$request->setMethod('bar')
Expand All @@ -307,7 +309,7 @@ public function testHandleValidMethodWithTooFewAssociativeParamsShouldPassDefaul

public function testHandleValidMethodWithTooManyParamsShouldWork()
{
$this->server->setClass('ZendTest\Json\Foo')
$this->server->setClass('ZendTest\Json\TestAsset\Foo')
->setReturnResponse(true);
$request = $this->server->getRequest();
$request->setMethod('bar')
Expand All @@ -325,7 +327,7 @@ public function testHandleValidMethodWithTooManyParamsShouldWork()

public function testHandleShouldAllowNamedParamsInAnyOrder1()
{
$this->server->setClass('ZendTest\Json\Foo')
$this->server->setClass('ZendTest\Json\TestAsset\Foo')
->setReturnResponse(true);
$request = $this->server->getRequest();
$request->setMethod('bar')
Expand All @@ -346,7 +348,7 @@ public function testHandleShouldAllowNamedParamsInAnyOrder1()

public function testHandleShouldAllowNamedParamsInAnyOrder2()
{
$this->server->setClass('ZendTest\Json\Foo')
$this->server->setClass('ZendTest\Json\TestAsset\Foo')
->setReturnResponse(true);
$request = $this->server->getRequest();
$request->setMethod('bar')
Expand All @@ -367,7 +369,7 @@ public function testHandleShouldAllowNamedParamsInAnyOrder2()

public function testHandleValidWithoutRequiredParamShouldReturnError()
{
$this->server->setClass('ZendTest\Json\Foo')
$this->server->setClass('ZendTest\Json\TestAsset\Foo')
->setReturnResponse(true);
$request = $this->server->getRequest();
$request->setMethod('bar')
Expand All @@ -385,7 +387,7 @@ public function testHandleValidWithoutRequiredParamShouldReturnError()

public function testHandleRequestWithErrorsShouldReturnErrorResponse()
{
$this->server->setClass('ZendTest\Json\Foo')
$this->server->setClass('ZendTest\Json\TestAsset\Foo')
->setReturnResponse(true);
$response = $this->server->handle();
$this->assertTrue($response instanceof Response);
Expand All @@ -395,7 +397,7 @@ public function testHandleRequestWithErrorsShouldReturnErrorResponse()

public function testHandleRequestWithInvalidMethodShouldReturnErrorResponse()
{
$this->server->setClass('ZendTest\Json\Foo')
$this->server->setClass('ZendTest\Json\TestAsset\Foo')
->setReturnResponse(true);
$request = $this->server->getRequest();
$request->setMethod('bogus')
Expand All @@ -408,7 +410,7 @@ public function testHandleRequestWithInvalidMethodShouldReturnErrorResponse()

public function testHandleRequestWithExceptionShouldReturnErrorResponse()
{
$this->server->setClass('ZendTest\Json\Foo')
$this->server->setClass('ZendTest\Json\TestAsset\Foo')
->setReturnResponse(true);
$request = $this->server->getRequest();
$request->setMethod('baz')
Expand All @@ -422,7 +424,7 @@ public function testHandleRequestWithExceptionShouldReturnErrorResponse()

public function testHandleShouldEmitResponseByDefault()
{
$this->server->setClass('ZendTest\Json\Foo');
$this->server->setClass('ZendTest\Json\TestAsset\Foo');
$request = $this->server->getRequest();
$request->setMethod('bar')
->setParams(array(true, 'foo', 'bar'))
Expand All @@ -443,7 +445,7 @@ public function testHandleShouldEmitResponseByDefault()

public function testResponseShouldBeEmptyWhenRequestHasNoId()
{
$this->server->setClass('ZendTest\Json\Foo');
$this->server->setClass('ZendTest\Json\TestAsset\Foo');
$request = $this->server->getRequest();
$request->setMethod('bar')
->setParams(array(true, 'foo', 'bar'));
Expand All @@ -456,7 +458,7 @@ public function testResponseShouldBeEmptyWhenRequestHasNoId()

public function testLoadFunctionsShouldLoadResultOfGetFunctions()
{
$this->server->setClass('ZendTest\Json\Foo');
$this->server->setClass('ZendTest\Json\TestAsset\Foo');
$functions = $this->server->getFunctions();
$server = new Server\Server();
$server->loadFunctions($functions);
Expand All @@ -468,7 +470,7 @@ public function testLoadFunctionsShouldLoadResultOfGetFunctions()
*/
public function testAddFunctionAndClassThatContainsConstructor()
{
$bar = new Bar('unique');
$bar = new TestAsset\Bar('unique');

$this->server->addFunction(array($bar, 'foo'));

Expand All @@ -493,74 +495,3 @@ public function testAddFunctionAndClassThatContainsConstructor()

}
}

/**
* Class for testing JSON-RPC server
*/
class Foo
{
/**
* Bar
*
* @param bool $one
* @param string $two
* @param mixed $three
* @return array
*/
public function bar($one, $two = 'two', $three = null)
{
return array($one, $two, $three);
}

/**
* Baz
*
* @return void
*/
public function baz()
{
throw new \Exception('application error');
}
}

class Bar
{
protected $val;

public function __construct($someval)
{
$this->val = $someval;
}
/**
* Bar
*
* @param bool $one
* @param string $two
* @param mixed $three
* @return array
*/
public function foo($one, $two = 'two', $three = null)
{
return array($one, $two, $three, $this->val);
}

/**
* Baz
*
* @return void
*/
public function baz()
{
throw new \Exception('application error');
}
}

/**
* Test function for JSON-RPC server
*
* @return bool
*/
function FooFunc()
{
return true;
}
42 changes: 42 additions & 0 deletions test/TestAsset/Bar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Json\TestAsset;

class Bar
{
protected $val;

public function __construct($someval)
{
$this->val = $someval;
}
/**
* Bar
*
* @param bool $one
* @param string $two
* @param mixed $three
* @return array
*/
public function foo($one, $two = 'two', $three = null)
{
return array($one, $two, $three, $this->val);
}

/**
* Baz
*
* @return void
*/
public function baz()
{
throw new \Exception('application error');
}
}
39 changes: 39 additions & 0 deletions test/TestAsset/Foo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Json\TestAsset;

/**
* Class for testing JSON-RPC server
*/
class Foo
{
/**
* Bar
*
* @param bool $one
* @param string $two
* @param mixed $three
* @return array
*/
public function bar($one, $two = 'two', $three = null)
{
return array($one, $two, $three);
}

/**
* Baz
*
* @return void
*/
public function baz()
{
throw new \Exception('application error');
}
}
20 changes: 20 additions & 0 deletions test/TestAsset/FooFunc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Json\TestAsset;

/**
* Test function for JSON-RPC server
*
* @return bool
*/
function FooFunc()
{
return true;
}

0 comments on commit cf6868a

Please sign in to comment.