Skip to content

Commit

Permalink
Fix GetTest::testHandleGet
Browse files Browse the repository at this point in the history
  • Loading branch information
nohponex committed Aug 6, 2016
1 parent 1fe9b83 commit 787ed8e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,16 @@ public static function viewData(
$viewParameters->meta = $meta;
}

$response->getBody()->write(json_encode($viewParameters));

return $response
$response = $response
->withStatus(200)
->withHeader(
'Content-Type',
'application/vnd.api+json;charset=utf-8'
);

$response->getBody()->write(json_encode($viewParameters));

return $response;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Controller/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ trait Get
* @param ResourceModel $model
* @param array $directives
* @return ResponseInterface
* @todo add links
*/
public static function handleGet(
ServerRequestInterface $request,
Expand Down
11 changes: 6 additions & 5 deletions src/Resource.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* Copyright 2015-2016 Xenofon Spafaridis
*
Expand All @@ -14,9 +15,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Phramework\JSONAPI;

use Directive\Model\Directives;
use Phramework\JSONAPI\Directive\Directive;
use Phramework\Util\Util;

Expand All @@ -31,8 +32,8 @@
* @property \stdClass $links
* @property \stdClass $attributes
* @property \stdClass $relationships
* @property \stdClass $data
* @property \stdClass $private-attributes
* @property \stdClass $'attributes-meta'
*/
class Resource extends \stdClass implements \JsonSerializable
{
Expand Down Expand Up @@ -73,10 +74,10 @@ class Resource extends \stdClass implements \JsonSerializable
* @param string $type
* @param string $id
*/
public function __construct($type, $id)
public function __construct(string $type, string $id)
{
$this->type = $type;
$this->id = (string) $id;
$this->id = $id;
}

/**
Expand All @@ -99,7 +100,7 @@ public function __set($name, $value)

$this->{$name} = $value;
} elseif (in_array($name, ['id', 'type'])) {
$this->{$name} = $value;
$this->{$name} = (string) $value;
} else {
throw new \Exception(sprintf(
'Undefined property via __set(): %s',
Expand Down
1 change: 1 addition & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* Copyright 2015-2016 Xenofon Spafaridis
*
Expand Down
31 changes: 31 additions & 0 deletions tests/public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

require __DIR__ . '/../bootstrap.php';
/*
var_dump(
);*/

class Ctrl
{
use \Phramework\JSONAPI\Controller\Get;
}

// Using the createServer factory, providing it with the various superglobals:
$server = Zend\Diactoros\Server::createServer(
function ($request, $response, $done) {
return Ctrl::handleGet(
$request,
$response,
\Phramework\JSONAPI\APP\Models\User::getResourceModel()
);

//$response->getBody()->write("Hello world!");
},
$_SERVER,
$_GET,
$_POST,
$_COOKIE,
$_FILES
);

$server->listen();
3 changes: 2 additions & 1 deletion tests/src/Controller/GetTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* Copyright 2015-2016 Xenofon Spafaridis
*
Expand Down Expand Up @@ -55,7 +56,7 @@ public function testHandleGet()
$response->getHeader('Content-Type')[0]
);

$body = $response->getBody()->getContents();
$body = $response->getBody()->__toString();

$this->assertTrue(Util::isJSON($body));

Expand Down

0 comments on commit 787ed8e

Please sign in to comment.