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

Commit c28689a

Browse files
committed
Added test with should confirm that body can be string
1 parent 7d840a5 commit c28689a

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

test/Controller/RestfulControllerTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Zend\Http\Response;
1717
use Zend\Mvc\MvcEvent;
1818
use Zend\Mvc\Router\RouteMatch;
19+
use ZendTest\Mvc\Controller\TestAsset\RestfulContentTypeTestController;
1920

2021
class RestfulControllerTest extends TestCase
2122
{
@@ -76,6 +77,22 @@ public function testDispatchInvokesCreateMethodWhenNoActionPresentAndPostInvoked
7677
$this->assertEquals('create', $this->routeMatch->getParam('action'));
7778
}
7879

80+
public function testCanReceiveStringAsRequestContent()
81+
{
82+
$string = "any content";
83+
$this->request->setMethod('PUT');
84+
$this->request->setContent($string);
85+
$this->routeMatch->setParam('id', $id = 1);
86+
87+
$controller = new RestfulContentTypeTestController();
88+
$controller->setEvent($this->event);
89+
$result = $controller->dispatch($this->request, $this->response);
90+
91+
$this->assertEquals($id, $result['id']);
92+
$this->assertEquals($string, $result['data']);
93+
$this->assertEquals('update', $this->routeMatch->getParam('action'));
94+
}
95+
7996
public function testDispatchInvokesUpdateMethodWhenNoActionPresentAndPutInvokedWithIdentifier()
8097
{
8198
$entity = ['name' => __FUNCTION__];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
namespace ZendTest\Mvc\Controller\TestAsset;
11+
12+
use Zend\Mvc\Controller\AbstractRestfulController;
13+
14+
class RestfulContentTypeTestController extends AbstractRestfulController
15+
{
16+
/**
17+
* Update an existing resource
18+
*
19+
* @param mixed $id
20+
* @param mixed $data
21+
* @return array
22+
*/
23+
public function update($id, $data)
24+
{
25+
return [
26+
'id' => $id,
27+
'data' => $data
28+
];
29+
}
30+
}

0 commit comments

Comments
 (0)