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

api-platform / core / 17738646910

15 Sep 2025 03:40PM UTC coverage: 22.156% (-0.07%) from 22.227%
17738646910

Pull #7380

github

web-flow
Merge e3d95e940 into 4abec444e
Pull Request #7380: fix(laravel): http cache compatibility

0 of 152 new or added lines in 9 files covered. (0.0%)

4 existing lines in 4 files now uncovered.

11127 of 50221 relevant lines covered (22.16%)

23.41 hits per line

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

0.0
/src/Laravel/Tests/PurgerTest.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\Foundation\Testing\RefreshDatabase;
18
use Orchestra\Testbench\Concerns\WithWorkbench;
19
use Orchestra\Testbench\TestCase;
20
use Workbench\App\Models\Author;
21
use Workbench\App\Models\Book;
22
use Workbench\App\Purger\MockPurger;
23
use Workbench\Database\Factories\AuthorFactory;
24
use Workbench\Database\Factories\BookFactory;
25

26
class PurgerTest extends TestCase
27
{
28
    use ApiTestAssertionsTrait;
29
    use RefreshDatabase;
30
    use WithWorkbench;
31

32
    protected function getEnvironmentSetUp($app): void
33
    {
NEW
34
        $app['config']->set('api-platform.http_cache.invalidation.purger', MockPurger::class);
×
35
    }
36

37
    protected function setUp(): void
38
    {
NEW
39
        parent::setUp();
×
NEW
40
        MockPurger::reset();
×
41
    }
42

43
    public function testPurgeOnCreate(): void
44
    {
NEW
45
        AuthorFactory::new()->create();
×
NEW
46
        $author = Author::first();
×
47

NEW
48
        $r = $this->postJson('/api/books', [
×
NEW
49
            'isbn' => '9783161484100',
×
NEW
50
            'name' => 'The Test Book',
×
NEW
51
            'author' => '/api/authors/'.$author->id,
×
NEW
52
        ], ['Accept' => 'application/ld+json', 'content-type' => 'application/ld+json']);
×
53

NEW
54
        $this->assertTagsWerePurged([
×
NEW
55
            $r->json()['@id'],
×
NEW
56
            '/api/books',
×
NEW
57
        ]);
×
58
    }
59

60
    public function testPurgeOnUpdate(): void
61
    {
NEW
62
        BookFactory::new()->has(AuthorFactory::new())->create();
×
NEW
63
        $book = Book::first();
×
64

NEW
65
        $this->patchJson('/api/books/'.$book->id, [
×
NEW
66
            'name' => 'An Updated Name',
×
NEW
67
        ], [
×
NEW
68
            'Accept' => 'application/ld+json',
×
NEW
69
            'Content-Type' => 'application/merge-patch+json',
×
NEW
70
        ]);
×
71

NEW
72
        $this->assertTagsWerePurged([
×
NEW
73
            '/api/books',
×
NEW
74
            '/api/books/'.$book->id,
×
NEW
75
        ]);
×
76
    }
77

78
    public function testPurgeOnDelete(): void
79
    {
NEW
80
        BookFactory::new()->has(AuthorFactory::new())->create();
×
NEW
81
        $book = Book::first();
×
NEW
82
        $this->delete('/api/books/'.$book->id, headers: ['accept' => 'application/ld+json']);
×
83

NEW
84
        $this->assertTagsWerePurged([
×
NEW
85
            '/api/books',
×
NEW
86
            '/api/books/'.$book->id,
×
NEW
87
        ]);
×
88
    }
89

90
    /**
91
     * @param string[] $expectedTags
92
     */
93
    private function assertTagsWerePurged(array $expectedTags): void
94
    {
NEW
95
        sort($expectedTags);
×
NEW
96
        $this->assertEquals($expectedTags, MockPurger::getPurgedTags());
×
97
    }
98
}
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