@@ -39,12 +39,12 @@ final class LinkFactoryTest extends TestCase
39
39
/**
40
40
* @dataProvider provideCreateLinksFromIdentifiersCases
41
41
*/
42
- public function testCreateLinksFromIdentifiers (array $ propertyNames , bool $ compositeIdentifier , array $ expectedLinks ): void
42
+ public function testCreateLinksFromIdentifiers (array $ propertyNames , bool $ compositeIdentifier , array $ expectedLinks, ? bool $ idAsIdentifier = null ): void
43
43
{
44
44
$ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
45
45
$ propertyNameCollectionFactoryProphecy ->create (Argument::cetera ())->willReturn (new PropertyNameCollection ($ propertyNames ));
46
46
$ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
47
- $ propertyMetadataFactoryProphecy ->create (AttributeResource::class, 'id ' )->willReturn (new ApiProperty ());
47
+ $ propertyMetadataFactoryProphecy ->create (AttributeResource::class, 'id ' )->willReturn (null === $ idAsIdentifier ? new ApiProperty () : new ApiProperty (identifier: $ idAsIdentifier ));
48
48
$ propertyMetadataFactoryProphecy ->create (AttributeResource::class, 'name ' )->willReturn ((new ApiProperty ())->withIdentifier (true ));
49
49
$ propertyMetadataFactoryProphecy ->create (AttributeResource::class, 'slug ' )->willReturn (new ApiProperty ());
50
50
$ propertyMetadataFactoryProphecy ->create (AttributeResource::class, 'composite1 ' )->willReturn ((new ApiProperty ())->withIdentifier (true ));
@@ -65,11 +65,23 @@ public function provideCreateLinksFromIdentifiersCases(): \Generator
65
65
'compositeIdentifier ' => false ,
66
66
[],
67
67
];
68
- yield 'no identifiers ' => [
68
+ yield 'id detected as identifier ' => [
69
69
['id ' ],
70
70
'compositeIdentifier ' => false ,
71
71
[(new Link ())->withFromClass (AttributeResource::class)->withParameterName ('id ' )->withIdentifiers (['id ' ])],
72
72
];
73
+ yield 'id forced as identifier ' => [
74
+ ['id ' ],
75
+ 'compositeIdentifier ' => false ,
76
+ [(new Link ())->withFromClass (AttributeResource::class)->withParameterName ('id ' )->withIdentifiers (['id ' ])],
77
+ true ,
78
+ ];
79
+ yield 'id forced as no identifier ' => [
80
+ ['id ' ],
81
+ 'compositeIdentifier ' => false ,
82
+ [],
83
+ false ,
84
+ ];
73
85
yield 'name identifier ' => [
74
86
['id ' , 'name ' ],
75
87
'compositeIdentifier ' => false ,
0 commit comments