Repository navigation
Expand file tree
/
Copy pathOperationTest.php
More file actions
78 lines (66 loc) · 2.41 KB
/
Copy pathOperationTest.php
File metadata and controls
78 lines (66 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace ApiPlatform\Metadata\Tests\Resource;
use ApiPlatform\Metadata\CollectionOperationInterface;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\GraphQl\Mutation;
use ApiPlatform\Metadata\GraphQl\Query;
use ApiPlatform\Metadata\GraphQl\QueryCollection;
use ApiPlatform\Metadata\GraphQl\Subscription;
use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
final class OperationTest extends TestCase
{
public function testWithResourceTrait(): void
{
$operation = (new GetCollection())->withOperation((new HttpOperation())->withShortName('test')->withRead(false));
$this->assertSame($operation->getShortName(), 'test');
$this->assertSame($operation->canRead(), false);
$this->assertInstanceOf(CollectionOperationInterface::class, $operation);
}
public function testWithOperationCopiesContentNegotiation(): void
{
$operation = (new Get())->withOperation(new Get(contentNegotiation: false));
$this->assertFalse($operation->canNegotiateContent());
}
#[DataProvider('operationProvider')]
public function testOperationConstructor(Operation $operation): void
{
$this->assertInstanceOf(Operation::class, $operation);
}
public static function operationProvider(): \Generator
{
$args = [];
yield [new Get(...$args)];
yield [new GetCollection(...$args)];
yield [new Post(...$args)];
yield [new Put(...$args)];
yield [new Patch(...$args)];
yield [new Delete(...$args)];
yield [new Query(...$args)];
yield [new QueryCollection(...$args)];
yield [new Mutation(...$args)];
yield [new Subscription(...$args)];
}
public function testPaginationViaCursor(): void
{
$a = [];
$operation = (new GetCollection())->withPaginationViaCursor($a);
$this->assertEquals($a, $operation->getPaginationViaCursor());
}
}