Skip to content

Commit 18a7a0a

Browse files
committed
hotfix(link-resolver): Change second parameter of resolveLinkCollection
1 parent 5b83d7c commit 18a7a0a

File tree

5 files changed

+186
-3
lines changed

5 files changed

+186
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased](https://github.com/contentful/contentful-core.php/compare/2.1.0...HEAD)
77

8+
### Fixed
9+
10+
* Method `LinkResolverInterface::resolveLinkCollection()`'s second parameter was fixed, changing from `string $locale = null` to `array $parameters = []`.
11+
812
## [2.1.0](https://github.com/contentful/contentful-core.php/tree/2.1.0) (2018-11-07)
913

1014
### Added

src/Api/LinkResolverInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public function resolveLink(Link $link, array $parameters = []): ResourceInterfa
2929
* to reduce the amount of necessary API calls, or simply forward this
3030
* to the "resolveLink" method.
3131
*
32-
* @param Link[] $links
33-
* @param string|null $locale
32+
* @param Link[] $links
33+
* @param string[] $parameters
3434
*
3535
* @return ResourceInterface[]
3636
*/
37-
public function resolveLinkCollection(array $links, string $locale = \null): array;
37+
public function resolveLinkCollection(array $links, array $parameters = []): array;
3838
}

tests/Implementation/Entry.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the contentful/contentful-core package.
5+
*
6+
* @copyright 2015-2018 Contentful GmbH
7+
* @license MIT
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace Contentful\Tests\Core\Implementation;
13+
14+
use Contentful\Core\Api\Link;
15+
use Contentful\Core\Resource\EntryInterface;
16+
17+
class Entry implements EntryInterface
18+
{
19+
/**
20+
* @var string
21+
*/
22+
private $id;
23+
24+
/**
25+
* @var string
26+
*/
27+
private $type;
28+
29+
/**
30+
* @var array
31+
*/
32+
private $parameters;
33+
34+
public function __construct(string $id, string $type, array $parameters = [])
35+
{
36+
$this->id = $id;
37+
$this->type = $type;
38+
$this->parameters = $parameters;
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
public function getId(): string
45+
{
46+
return $this->id;
47+
}
48+
49+
/**
50+
* {@inheritdoc}
51+
*/
52+
public function getType(): string
53+
{
54+
return $this->type;
55+
}
56+
57+
/**
58+
* {@inheritdoc}
59+
*/
60+
public function getSystemProperties()
61+
{
62+
throw new \Exception('Not supported');
63+
}
64+
65+
/**
66+
* {@inheritdoc}
67+
*/
68+
public function jsonSerialize()
69+
{
70+
return [
71+
'id' => $this->id,
72+
'type' => $this->type,
73+
'parameters' => $this->parameters,
74+
];
75+
}
76+
77+
/**
78+
* {@inheritdoc}
79+
*/
80+
public function asLink(): Link
81+
{
82+
return new Link($this->id, $this->type);
83+
}
84+
85+
/**
86+
* @return array
87+
*/
88+
public function getParameters(): array
89+
{
90+
return $this->parameters;
91+
}
92+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the contentful/contentful-core package.
5+
*
6+
* @copyright 2015-2018 Contentful GmbH
7+
* @license MIT
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace Contentful\Tests\Core\Implementation;
13+
14+
use Contentful\Core\Api\Link;
15+
use Contentful\Core\Api\LinkResolverInterface;
16+
use Contentful\Core\Resource\ResourceInterface;
17+
18+
class LinkResolver implements LinkResolverInterface
19+
{
20+
/**
21+
* {@inheritdoc}
22+
*/
23+
public function resolveLink(Link $link, array $parameters = []): ResourceInterface
24+
{
25+
return new Entry($link->getId(), $link->getLinkType(), $parameters);
26+
}
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function resolveLinkCollection(array $links, array $parameters = []): array
32+
{
33+
return \array_map(function (Link $link) use ($parameters): ResourceInterface {
34+
return $this->resolveLink($link, $parameters);
35+
}, $links);
36+
}
37+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the contentful/contentful-core package.
5+
*
6+
* @copyright 2015-2018 Contentful GmbH
7+
* @license MIT
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace Contentful\Tests\Core\Unit\Api;
13+
14+
use Contentful\Core\Api\Link;
15+
use Contentful\Tests\Core\Implementation\Entry;
16+
use Contentful\Tests\Core\Implementation\LinkResolver;
17+
use Contentful\Tests\TestCase;
18+
19+
class LinkResolverInterfaceTest extends TestCase
20+
{
21+
public function testLinkResolver()
22+
{
23+
$linkResolver = new LinkResolver();
24+
25+
/** @var Entry $entry */
26+
$entry = $linkResolver->resolveLink(
27+
new Link('someEntryId', 'Entry'),
28+
['someParameter' => 'someValue']
29+
);
30+
31+
$this->assertSame('someEntryId', $entry->getId());
32+
$this->assertSame('Entry', $entry->getType());
33+
$this->assertSame(['someParameter' => 'someValue'], $entry->getParameters());
34+
35+
/** @var Entry[] $entries */
36+
$entries = $linkResolver->resolveLinkCollection(
37+
[new Link('someEntryId', 'Entry')],
38+
['someParameter' => 'someValue']
39+
);
40+
41+
$this->assertContainsOnlyInstancesOf(Entry::class, $entries);
42+
$this->assertCount(1, $entries);
43+
44+
$entry = $entries[0];
45+
46+
$this->assertSame('someEntryId', $entry->getId());
47+
$this->assertSame('Entry', $entry->getType());
48+
$this->assertSame(['someParameter' => 'someValue'], $entry->getParameters());
49+
}
50+
}

0 commit comments

Comments
 (0)