Skip to content

Commit 93fedc5

Browse files
committed
fix tests
1 parent 840cb48 commit 93fedc5

File tree

5 files changed

+27
-20
lines changed

5 files changed

+27
-20
lines changed

api/src/Metadata/Resource/Factory/UriTemplateFactory.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public function __construct(
3838
public function createFromShortname(string $shortName): array {
3939
$resourceClass = $this->resourceNameMapping[lcfirst($shortName)] ?? null;
4040

41+
if (!$resourceClass) {
42+
return [null, false];
43+
}
44+
4145
return $this->createFromResourceClass($resourceClass);
4246
}
4347

@@ -50,9 +54,6 @@ public function createFromShortname(string $shortName): array {
5054
* indicates whether any template parameters are present in the URI
5155
*/
5256
public function createFromResourceClass(string $resourceClass): array {
53-
if (!$resourceClass) {
54-
return [null, false];
55-
}
5657
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
5758

5859
$baseUri = $this->iriConverter->getIriFromResourceClass($resourceClass);

api/tests/Api/ContentTypes/ReadContentTypeTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ public function testGetSingleContentTypeIsAllowedForAnonymousUser() {
1818
'id' => $contentType->getId(),
1919
'name' => $contentType->name,
2020
'active' => $contentType->active,
21-
'entityClass' => 'App\\Entity\\ContentNode\\SingleText',
22-
'entityPath' => '/content_node/single_texts',
21+
'_links' => [
22+
'contentNodes' => [
23+
'href' => '/content_node/single_texts?contentType='.urlencode($this->getIriFor($contentType)),
24+
],
25+
],
2326
]);
2427
}
2528

@@ -32,8 +35,11 @@ public function testGetSingleContentTypeIsAllowedForLoggedInUser() {
3235
'id' => $contentType->getId(),
3336
'name' => $contentType->name,
3437
'active' => $contentType->active,
35-
'entityClass' => 'App\\Entity\\ContentNode\\SingleText',
36-
'entityPath' => '/content_node/single_texts',
38+
'_links' => [
39+
'contentNodes' => [
40+
'href' => '/content_node/single_texts?contentType='.urlencode($this->getIriFor($contentType)),
41+
],
42+
],
3743
]);
3844
}
3945
}

api/tests/Metadata/Resource/Factory/UriTemplateFactoryTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testCantCreateUriTemplateForNonexistentResource() {
5151
$this->createFactory();
5252

5353
// when
54-
[$uri, $templated] = $this->uriTemplateFactory->create($resource);
54+
[$uri, $templated] = $this->uriTemplateFactory->createFromShortname($resource);
5555

5656
// then
5757
self::assertThat($uri, self::equalTo(null));
@@ -68,7 +68,7 @@ public function testCreatesNonTemplatedUri() {
6868
$this->createFactory();
6969

7070
// when
71-
[$uri, $templated] = $this->uriTemplateFactory->create($resource);
71+
[$uri, $templated] = $this->uriTemplateFactory->createFromShortname($resource);
7272

7373
// then
7474
self::assertThat($uri, self::equalTo('/dummys'));
@@ -81,7 +81,7 @@ public function testCreatesTemplatedUriWithIdPathParameter() {
8181
$this->createFactory();
8282

8383
// when
84-
[$uri, $templated] = $this->uriTemplateFactory->create($resource);
84+
[$uri, $templated] = $this->uriTemplateFactory->createFromShortname($resource);
8585

8686
// then
8787
self::assertThat($uri, self::equalTo('/dummys{/id}'));
@@ -100,7 +100,7 @@ public function testCreatesTemplatedUriWithFilterQueryParameter() {
100100
$this->createFactory();
101101

102102
// when
103-
[$uri, $templated] = $this->uriTemplateFactory->create($resource);
103+
[$uri, $templated] = $this->uriTemplateFactory->createFromShortname($resource);
104104

105105
// then
106106
self::assertThat($uri, self::equalTo('/dummys{/id}{?some_filter}'));
@@ -114,7 +114,7 @@ public function testCreatesTemplatedUriWithPaginationQueryParameter() {
114114
$this->createFactory();
115115

116116
// when
117-
[$uri, $templated] = $this->uriTemplateFactory->create($resource);
117+
[$uri, $templated] = $this->uriTemplateFactory->createFromShortname($resource);
118118

119119
// then
120120
self::assertThat($uri, self::equalTo('/dummys{/id}{?page}'));
@@ -132,7 +132,7 @@ public function testCreatesTemplatedUriWithAdvancedPaginationQueryParameters() {
132132
$this->createFactory();
133133

134134
// when
135-
[$uri, $templated] = $this->uriTemplateFactory->create($resource);
135+
[$uri, $templated] = $this->uriTemplateFactory->createFromShortname($resource);
136136

137137
// then
138138
self::assertThat($uri, self::equalTo('/dummys{/id}{?page,itemsPerPage,pagination}'));

api/tests/Serializer/Normalizer/RelatedCollectionLinkNormalizerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ public function testNormalizeReplacesLinkArrayWithSingleFilteredCollectionLinkBa
184184
$this->propertyAccessor->method('getValue')->willReturn('value');
185185
$this->uriTemplateFactory
186186
->expects($this->once())
187-
->method('create')
188-
->with('scheduleEntry')
187+
->method('createFromResourceClass')
188+
->with('App\\Entity\\DummyEntity')
189189
->willReturn(['/relatedEntities{/id}{?test_param}', true])
190190
;
191191
$this->uriTemplate
@@ -497,7 +497,7 @@ public function getFilterValue(): string {
497497
return '';
498498
}
499499

500-
#[RelatedCollectionLink('scheduleEntry', ['test_param' => 'filterValue'])]
500+
#[RelatedCollectionLink('App\\Entity\\DummyEntity', ['test_param' => 'filterValue'])]
501501
public function getRelatedEntities(): array {
502502
return [];
503503
}

api/tests/Serializer/Normalizer/UriTemplateNormalizerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testCreateNotTemplatedLinkIfNoParameters() {
4141
'camp' => ['href' => '/camps'],
4242
]]);
4343
$resource = new Entrypoint(new ResourceNameCollection([Camp::class]));
44-
$this->uriTemplateFactory->expects($this->once())->method('create')->willReturn(['/camps', false]);
44+
$this->uriTemplateFactory->expects($this->once())->method('createFromShortname')->willReturn(['/camps', false]);
4545

4646
// when
4747
$normalize = $this->uriTemplateNormalizer->normalize($resource);
@@ -68,7 +68,7 @@ public function testCreateTemplatedLinkIfPathParameters() {
6868
'camp' => ['href' => '/camps'],
6969
]]);
7070
$resource = new Entrypoint(new ResourceNameCollection([Camp::class]));
71-
$this->uriTemplateFactory->expects($this->once())->method('create')->willReturn(['/camps{/id}', true]);
71+
$this->uriTemplateFactory->expects($this->once())->method('createFromShortname')->willReturn(['/camps{/id}', true]);
7272

7373
// when
7474
$normalize = $this->uriTemplateNormalizer->normalize($resource);
@@ -96,7 +96,7 @@ public function testCreateTemplatedLinkForQueryParameters() {
9696
'activity' => ['href' => '/activities'],
9797
]]);
9898
$resource = new Entrypoint(new ResourceNameCollection([Activity::class]));
99-
$this->uriTemplateFactory->expects($this->once())->method('create')->willReturn(['/activities{?camp,camp[]}', true]);
99+
$this->uriTemplateFactory->expects($this->once())->method('createFromShortname')->willReturn(['/activities{?camp,camp[]}', true]);
100100

101101
// when
102102
$normalize = $this->uriTemplateNormalizer->normalize($resource);
@@ -124,7 +124,7 @@ public function testMergePathAndQueryParameter() {
124124
'activity' => ['href' => '/activities'],
125125
]]);
126126
$resource = new Entrypoint(new ResourceNameCollection([Activity::class]));
127-
$this->uriTemplateFactory->expects($this->once())->method('create')->willReturn(['/activities{/id}{?camp,camp[]}', true]);
127+
$this->uriTemplateFactory->expects($this->once())->method('createFromShortname')->willReturn(['/activities{/id}{?camp,camp[]}', true]);
128128

129129
// when
130130
$normalize = $this->uriTemplateNormalizer->normalize($resource);

0 commit comments

Comments
 (0)