• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 10943531622

19 Sep 2024 02:54PM UTC coverage: 0.0% (-23.1%) from 23.085%
10943531622

push

github

soyuka
feat: api-platform/json-hal component (#6621)

* feat: add hal support for laravel

* feat: quick review

* fix: typo & cs-fixer

* fix: typo in composer.json

* fix: cs-fixer & phpstan

* fix: forgot about hal item normalizer, therefore there's no more createbook nor updatebook test as Hal is a readonly format

0 of 94 new or added lines in 2 files covered. (0.0%)

28 existing lines in 2 files now uncovered.

0 of 45221 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Laravel/Tests/HalTest.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Laravel\Tests;
15

16
use ApiPlatform\Laravel\Test\ApiTestAssertionsTrait;
17
use Illuminate\Contracts\Config\Repository;
18
use Illuminate\Foundation\Application;
19
use Illuminate\Foundation\Testing\RefreshDatabase;
20
use Orchestra\Testbench\Concerns\WithWorkbench;
21
use Orchestra\Testbench\TestCase;
22
use Workbench\App\Models\Book;
23

24
class HalTest extends TestCase
25
{
26
    use ApiTestAssertionsTrait;
27
    use RefreshDatabase;
28
    use WithWorkbench;
29

30
    /**
31
     * @param Application $app
32
     */
33
    protected function defineEnvironment($app): void
34
    {
NEW
35
        tap($app['config'], function (Repository $config): void {
×
NEW
36
            $config->set('api-platform.formats', ['jsonhal' => ['application/hal+json']]);
×
NEW
37
            $config->set('api-platform.docs_formats', ['jsonhal' => ['application/hal+json']]);
×
NEW
38
        });
×
39
    }
40

41
    public function testGetEntrypoint(): void
42
    {
NEW
43
        $response = $this->get('/api/', ['accept' => ['application/hal+json']]);
×
NEW
44
        $response->assertStatus(200);
×
NEW
45
        $response->assertHeader('content-type', 'application/hal+json; charset=utf-8');
×
46

NEW
47
        $this->assertJsonContains(
×
NEW
48
            [
×
NEW
49
                '_links' => [
×
NEW
50
                    'self' => ['href' => '/api'],
×
NEW
51
                    'book' => ['href' => '/api/books'],
×
NEW
52
                    'post' => ['href' => '/api/posts'],
×
NEW
53
                    'sluggable' => ['href' => '/api/sluggables'],
×
NEW
54
                    'vault' => ['href' => '/api/vaults'],
×
NEW
55
                    'author' => ['href' => '/api/authors'],
×
NEW
56
                ],
×
NEW
57
            ],
×
NEW
58
            $response->json()
×
NEW
59
        );
×
60
    }
61

62
    public function testGetCollection(): void
63
    {
NEW
64
        $response = $this->get('/api/books', ['accept' => 'application/hal+json']);
×
NEW
65
        $response->assertStatus(200);
×
NEW
66
        $response->assertHeader('content-type', 'application/hal+json; charset=utf-8');
×
NEW
67
        $this->assertJsonContains(
×
NEW
68
            [
×
NEW
69
                '_links' => [
×
NEW
70
                    'first' => ['href' => '/api/books?page=1'],
×
NEW
71
                    'self' => ['href' => '/api/books?page=1'],
×
NEW
72
                    'last' => ['href' => '/api/books?page=2'],
×
NEW
73
                ],
×
NEW
74
                'totalItems' => 10,
×
NEW
75
            ],
×
NEW
76
            $response->json()
×
NEW
77
        );
×
78
    }
79

80
    public function testGetBook(): void
81
    {
NEW
82
        $book = Book::first();
×
NEW
83
        $iri = $this->getIriFromResource($book);
×
NEW
84
        $response = $this->get($iri, ['accept' => ['application/hal+json']]);
×
NEW
85
        $response->assertStatus(200);
×
NEW
86
        $response->assertHeader('content-type', 'application/hal+json; charset=utf-8');
×
NEW
87
        $this->assertJsonContains(
×
NEW
88
            [
×
NEW
89
                'name' => $book->name, // @phpstan-ignore-line
×
NEW
90
                'isbn' => $book->isbn, // @phpstan-ignore-line
×
NEW
91
                '_links' => [
×
NEW
92
                    'self' => [
×
NEW
93
                        'href' => $iri,
×
NEW
94
                    ],
×
NEW
95
                    'author' => [
×
NEW
96
                        'href' => '/api/authors/1',
×
NEW
97
                    ],
×
NEW
98
                ],
×
NEW
99
            ],
×
NEW
100
            $response->json()
×
NEW
101
        );
×
102
    }
103

104
    public function testDeleteBook(): void
105
    {
NEW
106
        $book = Book::first();
×
NEW
107
        $iri = $this->getIriFromResource($book);
×
NEW
108
        $response = $this->delete($iri, headers: ['accept' => 'application/hal+json']);
×
NEW
109
        $response->assertStatus(204);
×
NEW
110
        $this->assertNull(Book::find($book->id));
×
111
    }
112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc