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

api-platform / core / 13897184482

17 Mar 2025 10:29AM UTC coverage: 17.371% (+8.6%) from 8.768%
13897184482

Pull #7027

github

web-flow
Merge 6b496c593 into ba5cea729
Pull Request #7027: fix(laravel): json api default parameters

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

545 existing lines in 58 files now uncovered.

4729 of 27224 relevant lines covered (17.37%)

78.16 hits per line

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

0.0
/src/Laravel/workbench/app/Models/Book.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 Workbench\App\Models;
15

16
use ApiPlatform\JsonApi\Filter\SparseFieldset;
17
use ApiPlatform\Laravel\Eloquent\Filter\BooleanFilter;
18
use ApiPlatform\Laravel\Eloquent\Filter\DateFilter;
19
use ApiPlatform\Laravel\Eloquent\Filter\EqualsFilter;
20
use ApiPlatform\Laravel\Eloquent\Filter\JsonApi\SortFilter;
21
use ApiPlatform\Laravel\Eloquent\Filter\OrderFilter;
22
use ApiPlatform\Laravel\Eloquent\Filter\OrFilter;
23
use ApiPlatform\Laravel\Eloquent\Filter\PartialSearchFilter;
24
use ApiPlatform\Laravel\Eloquent\Filter\RangeFilter;
25
use ApiPlatform\Laravel\workbench\app\Enums\BookStatus;
26
use ApiPlatform\Metadata\ApiResource;
27
use ApiPlatform\Metadata\Delete;
28
use ApiPlatform\Metadata\Get;
29
use ApiPlatform\Metadata\GetCollection;
30
use ApiPlatform\Metadata\GraphQl\Mutation;
31
use ApiPlatform\Metadata\GraphQl\Query;
32
use ApiPlatform\Metadata\GraphQl\QueryCollection;
33
use ApiPlatform\Metadata\Patch;
34
use ApiPlatform\Metadata\Post;
35
use ApiPlatform\Metadata\Put;
36
use ApiPlatform\Metadata\QueryParameter;
37
use ApiPlatform\Serializer\Filter\PropertyFilter;
38
use Illuminate\Database\Eloquent\Concerns\HasUlids;
39
use Illuminate\Database\Eloquent\Factories\HasFactory;
40
use Illuminate\Database\Eloquent\Model;
41
use Illuminate\Database\Eloquent\Relations\BelongsTo;
42
use Workbench\App\Http\Requests\BookFormRequest;
43

44
#[ApiResource(
45
    paginationEnabled: true,
×
46
    paginationItemsPerPage: 5,
×
47
    paginationClientItemsPerPage: true,
×
48
    rules: BookFormRequest::class,
×
49
    operations: [
×
50
        new Put(),
×
51
        new Patch(),
×
52
        new Get(),
×
53
        new Post(),
×
54
        new Delete(),
×
55
        new GetCollection(),
×
56
    ],
×
57
    graphQlOperations: [
×
58
        new Query(),
×
59
        new QueryCollection(
×
60
            parameters: [
×
61
                new QueryParameter(key: 'order[:property]', filter: OrderFilter::class),
×
62
            ],
×
63
        ),
×
64
        new QueryCollection(
×
65
            paginationItemsPerPage: 3,
×
66
            name: 'simplePagination',
×
67
            paginationType: 'page',
×
68
        ),
×
69
        new Mutation(name: 'create'),
×
UNCOV
70
    ]
×
UNCOV
71
)]
×
72
#[QueryParameter(key: 'isbn', filter: PartialSearchFilter::class, constraints: 'min:2')]
73
#[QueryParameter(key: 'name', filter: PartialSearchFilter::class)]
74
#[QueryParameter(key: 'author', filter: EqualsFilter::class)]
75
#[QueryParameter(key: 'publicationDate', filter: DateFilter::class, property: 'publication_date')]
76
#[QueryParameter(key: 'publicationDateWithNulls', filter: DateFilter::class, property: 'publication_date', filterContext: ['include_nulls' => true])]
77
#[QueryParameter(key: 'isbn_range', filter: RangeFilter::class, property: 'isbn')]
78
#[QueryParameter(
79
    key: 'name2',
×
80
    filter: new OrFilter(new EqualsFilter()),
×
UNCOV
81
    property: 'name'
×
UNCOV
82
)]
×
83
#[QueryParameter(key: 'properties', filter: PropertyFilter::class)]
84
#[QueryParameter(key: 'published', filter: BooleanFilter::class)]
85
class Book extends Model
86
{
87
    use HasFactory;
88
    use HasUlids;
89

90
    protected $visible = ['name', 'author', 'isbn', 'status', 'publication_date', 'is_available', 'published'];
91
    protected $fillable = ['name', 'status', 'publication_date', 'isbn', 'is_available', 'published'];
92
    protected $casts = [
93
        'is_available' => 'boolean',
94
        'status' => BookStatus::class,
95
    ];
96

97
    public function author(): BelongsTo
98
    {
UNCOV
99
        return $this->belongsTo(Author::class);
×
100
    }
101
}
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

© 2025 Coveralls, Inc