8000 Merge tag 'v0.11.1' into develop · PXLbros/laravel-json-api@5f2347e · GitHub
[go: up one dir, main page]

Skip to content

Commit 5f2347e

Browse files
committed
Merge tag 'v0.11.1' into develop
Fix response content-type header.
2 parents 7ced632 + 5aab3dd commit 5f2347e

File tree

7 files changed

+85
-11
lines changed

7 files changed

+85
-11
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

docs/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Install using [Composer](http://getcomposer.org):
66

77
``` bash
88
$ composer require cloudcreativity/laravel-json-api
9-
$ composer require --dev cloucdreativity/json-api-testing
9+
$ composer require --dev cloudcreativity/json-api-testing
1010
```
1111

1212
This package's service provider and facade will be automatically added using package discovery. You will
@@ -18,7 +18,7 @@ Install using [Composer](http://getcomposer.org):
1818

1919
``` bash
2020
$ composer require cloudcreativity/laravel-json-api
21-
$ composer require --dev cloucdreativity/json-api-testing
21+
$ composer require --dev cloudcreativity/json-api-testing
2222
```
2323

2424
Add the package service provider to your `config/app.php` providers array.

docs/upgrade.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@ config file.
2020
### Testing
2121

2222
The test helper classes have been extracted to a separate package to allow us to support both PHPUnit 5.7 and 6.
23-
The new package can be installed using composer:
23+
The new package can be installed using composer.
24+
25+
For PHPUnit 5.7:
26+
27+
```bash
28+
$ composer require --dev cloudcreativity/json-api-testing:^0.1
29+
```
30+
31+
For PHPUnit 6:
2432

2533
```bash
26-
$ composer require --dev cloudcreativity/json-api-testing
34+
$ composer require --dev cloudcreativity/json-api-testing:^0.2
2735
```
2836

2937
We have removed all test helper methods on the `TestResponse` class that were marked as deprecated in `0.10`.

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()

src/Store/EloquentAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ protected function newQuery()
192192
* @param Builder $query
193193
* @param Collection $includePaths
194194
* the paths for resources that will be included.
195-
* @return array
195+
* @return void
196196
*/
197197
protected function with(Builder $query, Collection $includePaths)
198198
{

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
/**

tests/Integration/Eloquent/PostsTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,25 @@ class PostsTest extends TestCase
1313
*/
1414
protected $resourceType = 'posts';
1515

16-
public function testSearch()
16+
/**
17+
* Test searching with a sort parameter.
18+
*/
19+
public function testSortedSearch()
1720
{
18-
factory(Post::class, 3)->create();
21+
$a = factory(Post::class)->create([
22+
'title' => 'Title A',
23+
]);
24+
25+
$b = factory(Post::class)->create([
26+
'title' => 'Title B',
27+
]);
28+
29+
$response = $this->doSearch(['sort' => '-title']);
30+
$response->assertSearchResponse()->assertContainsOnly(['posts' => [$a->getKey(), $b->getKey()]]);
1931

20-
$this->doSearch(['sort' => '-created-at'])->assertSearchResponse();
32+
$json = $response->decodeResponseJson();
33+
$actual = [array_get($json, 'data.0.id'), array_get($json, 'data.1.id')];
34+
$this->assertEquals([$b->getKey(), $a->getKey()], $actual);
2135
}
2236

2337
/**

0 commit comments

Comments
 (0)
0