8000 Merge branch 'hotfix/0.11.1' · CodingSeo/laravel-json-api@5aab3dd · GitHub
[go: up one dir, main page]

Skip to content

Commit 5aab3dd

Browse files
committed
Merge branch 'hotfix/0.11.1'
Closes cloudcreativity#109
2 parents 84a96e5 + 966791a commit 5aab3dd

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project will be documented in this file. This project adheres to
33
[Semantic Versioning](http://semver.org/) and [this changelog format](http://keepachangelog.com/).
44

5+
## [0.11.1] - 2017-09-26
6+
7+
### Fixed
8+
- [#109] The matched media type is now set as the `Content-Type` header on a response.
9+
510
## [0.11.0] - 2017-09-02
611

712
### Added

src/Api/Api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public function response(
318318
return $this->factory->createResponses(
319319
$this->getSchemas(),
320320
$this->getErrors(),
321-
null,
321+
$this->getCodecMatcher(),
322322
$parameters,
323323
$extensions ?: $this->getSupportedExtensions(),
324324
(string) $this->getUrl()

tests/Integration/ContentNegotiationTest.php

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ protected function setUp()
2222

2323
public function testOkWithoutBody()
2424
{
25-
$this->getJsonApi('/api/v1/posts')->assertStatusCode(200);
25+
$this->getJsonApi('/api/v1/posts')
26+
->assertStatus(200)
27+
->assertHeader('Content-Type', 'application/vnd.api+json');
2628
}
2729

2830
public function testOkWithBody()
@@ -71,9 +73,54 @@ public function testUnsupportedMediaType()
7173
])->assertStatus(415);
7274
}
7375

76+
/**
77+
* Can request an alternative media-type that is in our configuration.
78+
* Note that the Symfony response automatically appends the charset to the
79+
* content-type header if it starts with `text/`.
80+
*/
81+
public function testAcceptable()
82+
{
83+
$this->get('/api/v1/posts', ['Accept' => 'text/plain'])
84+
->assertStatus(200)
85+
->assertHeader('Content-Type', 'text/plain; charset=UTF-8');
86+
}
87+
88+
/**
89+
* If we request a content type that is not in our codec configuration, we
90+
* expect a 406 response.
91+
*/
7492
public function testNotAcceptable()
7593
{
76-
$this->get('/api/v1/posts', ['Accept' => 'text/html'])->assertStatus(406);
94+
$this->get('/api/v1/posts', ['Accept' => 'application/json'])->assertStatus(406);
95+
}
96+
97+
/**
98+
* The codec configuration can be changed.
99+
*/
100+
public function testCanChangeMediaType1()
101+
{
102+
app('config')->set('json-api-default.codecs', [
103+
'encoders' => ['application/json'],
104+
'decoders' => ['application/json'],
105+
]);
106+
107+
$this->get('/api/v1/posts', ['Accept' => 'application/json'])
108+
->assertStatus(200)
109+
->assertHeader('Content-Type', 'application/json');
110+
}
111+
112+
/**
113+
* Not including the JSON API media type in our configuration results in a 406 response
114+
*/
115+
public function testCanChangeMediaType2()
116+
{
117+
app('config')->set('json-api-default.codecs', [
118+
'encoders' => ['application/json'],
119+
'decoders' => ['application/json'],
120+
]);
121+
122+
$this->get('/api/v1/posts', ['Accept' => 'application/vnd.api+json'])
123+
->assertStatus(406);
77124
}
78125

79126
/**

0 commit comments

Comments
 (0)
0