Issue #3439738 by mondrake, longwave: Change remaining Jsonapi module test dataproviders to static
(cherry picked from commit 7ab4b0e73c
)
merge-requests/7427/head
parent
f744f367b9
commit
23519dbe70
|
@ -24,66 +24,68 @@ class LinkTest extends UnitTestCase {
|
||||||
* @covers ::compare
|
* @covers ::compare
|
||||||
* @dataProvider linkComparisonProvider
|
* @dataProvider linkComparisonProvider
|
||||||
*/
|
*/
|
||||||
public function testLinkComparison(Link $a, Link $b, $expected) {
|
public function testLinkComparison(array $a, array $b, bool $expected): void {
|
||||||
$actual = Link::compare($a, $b);
|
$this->mockUrlAssembler();
|
||||||
|
|
||||||
|
$link_a = new Link(new CacheableMetadata(), Url::fromUri($a[0]), $a[1], $a[2] ?? []);
|
||||||
|
$link_b = new Link(new CacheableMetadata(), Url::fromUri($b[0]), $b[1], $b[2] ?? []);
|
||||||
|
|
||||||
|
$actual = Link::compare($link_a, $link_b);
|
||||||
$this->assertSame($expected, $actual === 0);
|
$this->assertSame($expected, $actual === 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides test data for link comparison.
|
* Provides test data for link comparison.
|
||||||
*/
|
*/
|
||||||
public function linkComparisonProvider() {
|
public static function linkComparisonProvider(): \Generator {
|
||||||
$this->mockUrlAssembler();
|
yield 'same href and same link relation type' => [
|
||||||
return [
|
['https://jsonapi.org/foo', 'self'],
|
||||||
'same href and same link relation type' => [
|
['https://jsonapi.org/foo', 'self'],
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self'),
|
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self'),
|
|
||||||
TRUE,
|
TRUE,
|
||||||
],
|
];
|
||||||
'different href and same link relation type' => [
|
yield 'different href and same link relation type' => [
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self'),
|
['https://jsonapi.org/foo', 'self'],
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/bar'), 'self'),
|
['https://jsonapi.org/bar', 'self'],
|
||||||
FALSE,
|
FALSE,
|
||||||
],
|
];
|
||||||
'same href and different link relation type' => [
|
yield 'same href and different link relation type' => [
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self'),
|
['https://jsonapi.org/foo', 'self'],
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'related'),
|
['https://jsonapi.org/foo', 'related'],
|
||||||
FALSE,
|
FALSE,
|
||||||
],
|
];
|
||||||
'same href and same link relation type and empty target attributes' => [
|
yield 'same href and same link relation type and empty target attributes' => [
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self', []),
|
['https://jsonapi.org/foo', 'self', []],
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self', []),
|
['https://jsonapi.org/foo', 'self', []],
|
||||||
TRUE,
|
TRUE,
|
||||||
],
|
];
|
||||||
'same href and same link relation type and same target attributes' => [
|
yield 'same href and same link relation type and same target attributes' => [
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self', ['anchor' => 'https://jsonapi.org']),
|
['https://jsonapi.org/foo', 'self', ['anchor' => 'https://jsonapi.org']],
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self', ['anchor' => 'https://jsonapi.org']),
|
['https://jsonapi.org/foo', 'self', ['anchor' => 'https://jsonapi.org']],
|
||||||
TRUE,
|
TRUE,
|
||||||
],
|
];
|
||||||
// These links are not considered equivalent because it would while the
|
// These links are not considered equivalent because it would while the
|
||||||
// `href` remains the same, the anchor changes the context of the link.
|
// `href` remains the same, the anchor changes the context of the link.
|
||||||
'same href and same link relation type and different target attributes' => [
|
yield 'same href and same link relation type and different target attributes' => [
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/boy'), 'self', ['title' => 'sue']),
|
['https://jsonapi.org/boy', 'self', ['title' => 'sue']],
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/boy'), 'self', ['anchor' => '/sob', 'title' => 'pa']),
|
['https://jsonapi.org/boy', 'self', ['anchor' => '/sob', 'title' => 'pa']],
|
||||||
FALSE,
|
FALSE,
|
||||||
],
|
];
|
||||||
'same href and same link relation type and same nested target attributes' => [
|
yield 'same href and same link relation type and same nested target attributes' => [
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self', ['data' => ['foo' => 'bar']]),
|
['https://jsonapi.org/foo', 'self', ['data' => ['foo' => 'bar']]],
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self', ['data' => ['foo' => 'bar']]),
|
['https://jsonapi.org/foo', 'self', ['data' => ['foo' => 'bar']]],
|
||||||
TRUE,
|
TRUE,
|
||||||
],
|
];
|
||||||
'same href and same link relation type and different nested target attributes' => [
|
yield 'same href and same link relation type and different nested target attributes' => [
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self', ['data' => ['foo' => 'bar']]),
|
['https://jsonapi.org/foo', 'self', ['data' => ['foo' => 'bar']]],
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/foo'), 'self', ['data' => ['foo' => 'baz']]),
|
['https://jsonapi.org/foo', 'self', ['data' => ['foo' => 'baz']]],
|
||||||
FALSE,
|
FALSE,
|
||||||
],
|
];
|
||||||
// These links are not considered equivalent because it would be unclear
|
// These links are not considered equivalent because it would be unclear
|
||||||
// which title corresponds to which link relation type.
|
// which title corresponds to which link relation type.
|
||||||
'same href and different link relation types and different target attributes' => [
|
yield 'same href and different link relation types and different target attributes' => [
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/boy'), 'self', ['title' => 'A boy named Sue']),
|
['https://jsonapi.org/boy', 'self', ['title' => 'A boy named Sue']],
|
||||||
new Link(new CacheableMetadata(), Url::fromUri('https://jsonapi.org/boy'), 'edit', ['title' => 'Change name to Bill or George']),
|
['https://jsonapi.org/boy', 'edit', ['title' => 'Change name to Bill or George']],
|
||||||
FALSE,
|
FALSE,
|
||||||
],
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,32 +93,29 @@ class LinkTest extends UnitTestCase {
|
||||||
* @covers ::merge
|
* @covers ::merge
|
||||||
* @dataProvider linkMergeProvider
|
* @dataProvider linkMergeProvider
|
||||||
*/
|
*/
|
||||||
public function testLinkMerge(Link $a, Link $b, $expected) {
|
public function testLinkMerge(array $a, array $b, array $expected): void {
|
||||||
if ($expected instanceof Link) {
|
$this->mockUrlAssembler();
|
||||||
$this->assertSame($expected->getCacheTags(), Link::merge($a, $b)->getCacheTags());
|
|
||||||
}
|
$link_a = new Link((new CacheableMetadata())->addCacheTags($a[0]), Url::fromUri($a[1]), $a[2]);
|
||||||
else {
|
$link_b = new Link((new CacheableMetadata())->addCacheTags($b[0]), Url::fromUri($b[1]), $b[2]);
|
||||||
$this->expectExceptionObject($expected);
|
$link_expected = new Link((new CacheableMetadata())->addCacheTags($expected[0]), Url::fromUri($expected[1]), $expected[2]);
|
||||||
Link::merge($a, $b);
|
|
||||||
}
|
$this->assertSame($link_expected->getCacheTags(), Link::merge($link_a, $link_b)->getCacheTags());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides test data for link merging.
|
* Provides test data for link merging.
|
||||||
*/
|
*/
|
||||||
public function linkMergeProvider() {
|
public static function linkMergeProvider(): \Generator {
|
||||||
$this->mockUrlAssembler();
|
yield 'same everything' => [
|
||||||
return [
|
[['foo'], 'https://jsonapi.org/foo', 'self'],
|
||||||
'same everything' => [
|
[['foo'], 'https://jsonapi.org/foo', 'self'],
|
||||||
new Link((new CacheableMetadata())->addCacheTags(['foo']), Url::fromUri('https://jsonapi.org/foo'), 'self'),
|
[['foo'], 'https://jsonapi.org/foo', 'self'],
|
||||||
new Link((new CacheableMetadata())->addCacheTags(['foo']), Url::fromUri('https://jsonapi.org/foo'), 'self'),
|
];
|
||||||
new Link((new CacheableMetadata())->addCacheTags(['foo']), Url::fromUri('https://jsonapi.org/foo'), 'self'),
|
yield 'different cache tags' => [
|
||||||
],
|
[['foo'], 'https://jsonapi.org/foo', 'self'],
|
||||||
'different cache tags' => [
|
[['bar'], 'https://jsonapi.org/foo', 'self'],
|
||||||
new Link((new CacheableMetadata())->addCacheTags(['foo']), Url::fromUri('https://jsonapi.org/foo'), 'self'),
|
[['foo', 'bar'], 'https://jsonapi.org/foo', 'self'],
|
||||||
new Link((new CacheableMetadata())->addCacheTags(['bar']), Url::fromUri('https://jsonapi.org/foo'), 'self'),
|
|
||||||
new Link((new CacheableMetadata())->addCacheTags(['foo', 'bar']), Url::fromUri('https://jsonapi.org/foo'), 'self'),
|
|
||||||
],
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue