mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MNT Tweak the Eagerload test to not worry about sort order (#10848)
* MNT Tweak the Eagerload test to not worry about sort order * MNT Use array keys for EagerLoad test DataProvider
This commit is contained in:
parent
60ca35c02d
commit
110c9135e0
@ -2254,172 +2254,150 @@ class DataListTest extends SapphireTest
|
|||||||
/**
|
/**
|
||||||
* @dataProvider provideEagerLoadRelations
|
* @dataProvider provideEagerLoadRelations
|
||||||
*/
|
*/
|
||||||
public function testEagerLoadRelations(string $iden, array $eagerLoad, int $expected): void
|
public function testEagerLoadRelations(array $eagerLoad, int $expectedCount): void
|
||||||
{
|
{
|
||||||
$this->createEagerLoadData();
|
$this->createEagerLoadData();
|
||||||
$dataList = EagerLoadObject::get()->eagerLoad(...$eagerLoad);
|
$dataList = EagerLoadObject::get()->eagerLoad(...$eagerLoad);
|
||||||
list($results, $selectCount) = $this->iterateEagerLoadData($dataList);
|
list($results, $selectCount) = $this->iterateEagerLoadData($dataList);
|
||||||
$this->assertSame($this->expectedEagerLoadData(), $results, $iden);
|
$expectedResults=$this->expectedEagerLoadData();
|
||||||
$this->assertSame($expected, $selectCount, $iden);
|
$this->assertSame(sort($expectedResults), sort($results));
|
||||||
|
$this->assertSame($expectedCount, $selectCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideEagerLoadRelations(): array
|
public function provideEagerLoadRelations(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[
|
'lazy-load' => [
|
||||||
'iden' => 'lazy-load',
|
|
||||||
'eagerLoad' => [],
|
'eagerLoad' => [],
|
||||||
'expected' => 83
|
'expected' => 83
|
||||||
],
|
],
|
||||||
[
|
'has-one-a' => [
|
||||||
'iden' => 'has-one-a',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'HasOneEagerLoadObject',
|
'HasOneEagerLoadObject',
|
||||||
],
|
],
|
||||||
'expected' => 82
|
'expected' => 82
|
||||||
],
|
],
|
||||||
[
|
'has-one-b' => [
|
||||||
'iden' => 'has-one-b',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'HasOneEagerLoadObject.HasOneSubEagerLoadObject',
|
'HasOneEagerLoadObject.HasOneSubEagerLoadObject',
|
||||||
],
|
],
|
||||||
'expected' => 81
|
'expected' => 81
|
||||||
],
|
],
|
||||||
[
|
'has-one-c' => [
|
||||||
'iden' => 'has-one-c',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'HasOneEagerLoadObject.HasOneSubEagerLoadObject.HasOneSubSubEagerLoadObject',
|
'HasOneEagerLoadObject.HasOneSubEagerLoadObject.HasOneSubSubEagerLoadObject',
|
||||||
],
|
],
|
||||||
'expected' => 80
|
'expected' => 80
|
||||||
],
|
],
|
||||||
[
|
'belongs-to-a' => [
|
||||||
'iden' => 'belongs-to-a',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'BelongsToEagerLoadObject',
|
'BelongsToEagerLoadObject',
|
||||||
],
|
],
|
||||||
'expected' => 82
|
'expected' => 82
|
||||||
],
|
],
|
||||||
[
|
'belongs-to-b' => [
|
||||||
'iden' => 'belongs-to-b',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'BelongsToEagerLoadObject.BelongsToSubEagerLoadObject',
|
'BelongsToEagerLoadObject.BelongsToSubEagerLoadObject',
|
||||||
],
|
],
|
||||||
'expected' => 81
|
'expected' => 81
|
||||||
],
|
],
|
||||||
[
|
'belongs-to-c' => [
|
||||||
'iden' => 'belongs-to-c',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'BelongsToEagerLoadObject.BelongsToSubEagerLoadObject.BelongsToSubSubEagerLoadObject',
|
'BelongsToEagerLoadObject.BelongsToSubEagerLoadObject.BelongsToSubSubEagerLoadObject',
|
||||||
],
|
],
|
||||||
'expected' => 80
|
'expected' => 80
|
||||||
],
|
],
|
||||||
[
|
'has-many-a' => [
|
||||||
'iden' => 'has-many-a',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'HasManyEagerLoadObjects',
|
'HasManyEagerLoadObjects',
|
||||||
],
|
],
|
||||||
'expected' => 82
|
'expected' => 82
|
||||||
],
|
],
|
||||||
[
|
'has-many-b' => [
|
||||||
'iden' => 'has-many-b',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'HasManyEagerLoadObjects.HasManySubEagerLoadObjects',
|
'HasManyEagerLoadObjects.HasManySubEagerLoadObjects',
|
||||||
],
|
],
|
||||||
'expected' => 79
|
'expected' => 79
|
||||||
],
|
],
|
||||||
[
|
'has-many-c' => [
|
||||||
'iden' => 'has-many-c',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'HasManyEagerLoadObjects.HasManySubEagerLoadObjects.HasManySubSubEagerLoadObjects',
|
'HasManyEagerLoadObjects.HasManySubEagerLoadObjects.HasManySubSubEagerLoadObjects',
|
||||||
],
|
],
|
||||||
'expected' => 72
|
'expected' => 72
|
||||||
],
|
],
|
||||||
[
|
'many-many-a' => [
|
||||||
'iden' => 'many-many-a',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'ManyManyEagerLoadObjects',
|
'ManyManyEagerLoadObjects',
|
||||||
],
|
],
|
||||||
'expected' => 83 // same number as lazy-load, though without an INNER JOIN
|
'expected' => 83 // same number as lazy-load, though without an INNER JOIN
|
||||||
],
|
],
|
||||||
[
|
'many-many-b' => [
|
||||||
'iden' => 'many-many-b',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'ManyManyEagerLoadObjects.ManyManySubEagerLoadObjects',
|
'ManyManyEagerLoadObjects.ManyManySubEagerLoadObjects',
|
||||||
],
|
],
|
||||||
'expected' => 81
|
'expected' => 81
|
||||||
],
|
],
|
||||||
[
|
'many-many-c' => [
|
||||||
'iden' => 'many-many-c',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'ManyManyEagerLoadObjects.ManyManySubEagerLoadObjects.ManyManySubSubEagerLoadObjects',
|
'ManyManyEagerLoadObjects.ManyManySubEagerLoadObjects.ManyManySubSubEagerLoadObjects',
|
||||||
],
|
],
|
||||||
'expected' => 75
|
'expected' => 75
|
||||||
],
|
],
|
||||||
[
|
'many-many-through-a' => [
|
||||||
'iden' => 'many-many-through-a',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'ManyManyThroughEagerLoadObjects',
|
'ManyManyThroughEagerLoadObjects',
|
||||||
],
|
],
|
||||||
'expected' => 83
|
'expected' => 83
|
||||||
],
|
],
|
||||||
[
|
'many-many-through-b' => [
|
||||||
'iden' => 'many-many-through-b',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'ManyManyThroughEagerLoadObjects.ManyManyThroughSubEagerLoadObjects',
|
'ManyManyThroughEagerLoadObjects.ManyManyThroughSubEagerLoadObjects',
|
||||||
],
|
],
|
||||||
'expected' => 81
|
'expected' => 81
|
||||||
],
|
],
|
||||||
[
|
'many-many-through-c' => [
|
||||||
'iden' => 'many-many-through-c',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'ManyManyThroughEagerLoadObjects.ManyManyThroughSubEagerLoadObjects.ManyManyThroughSubSubEagerLoadObjects',
|
'ManyManyThroughEagerLoadObjects.ManyManyThroughSubEagerLoadObjects.ManyManyThroughSubSubEagerLoadObjects',
|
||||||
],
|
],
|
||||||
'expected' => 75
|
'expected' => 75
|
||||||
],
|
],
|
||||||
[
|
'belongs-many-many-a' => [
|
||||||
'iden' => 'belongs-many-many-a',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'BelongsManyManyEagerLoadObjects',
|
'BelongsManyManyEagerLoadObjects',
|
||||||
],
|
],
|
||||||
'expected' => 83
|
'expected' => 83
|
||||||
],
|
],
|
||||||
[
|
'belongs-many-many-b' => [
|
||||||
'iden' => 'belongs-many-many-b',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'BelongsManyManyEagerLoadObjects.BelongsManyManySubEagerLoadObjects',
|
'BelongsManyManyEagerLoadObjects.BelongsManyManySubEagerLoadObjects',
|
||||||
],
|
],
|
||||||
'expected' => 81
|
'expected' => 81
|
||||||
],
|
],
|
||||||
[
|
'belongs-many-many-c' => [
|
||||||
'iden' => 'belongs-many-many-c',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'BelongsManyManyEagerLoadObjects.BelongsManyManySubEagerLoadObjects.BelongsManyManySubSubEagerLoadObjects',
|
'BelongsManyManyEagerLoadObjects.BelongsManyManySubEagerLoadObjects.BelongsManyManySubSubEagerLoadObjects',
|
||||||
],
|
],
|
||||||
'expected' => 75
|
'expected' => 75
|
||||||
],
|
],
|
||||||
[
|
'mixed-a' => [
|
||||||
'iden' => 'mixed-a',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'MixedManyManyEagerLoadObjects',
|
'MixedManyManyEagerLoadObjects',
|
||||||
],
|
],
|
||||||
'expected' => 83
|
'expected' => 83
|
||||||
],
|
],
|
||||||
[
|
'mixed-b' => [
|
||||||
'iden' => 'mixed-b',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'MixedManyManyEagerLoadObjects.MixedHasManyEagerLoadObjects',
|
'MixedManyManyEagerLoadObjects.MixedHasManyEagerLoadObjects',
|
||||||
],
|
],
|
||||||
'expected' => 80
|
'expected' => 80
|
||||||
],
|
],
|
||||||
[
|
'mixed-c' => [
|
||||||
'iden' => 'mixed-c',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'MixedManyManyEagerLoadObjects.MixedHasManyEagerLoadObjects.MixedHasOneEagerLoadObject',
|
'MixedManyManyEagerLoadObjects.MixedHasManyEagerLoadObjects.MixedHasOneEagerLoadObject',
|
||||||
],
|
],
|
||||||
'expected' => 73
|
'expected' => 73
|
||||||
],
|
],
|
||||||
[
|
'all' => [
|
||||||
'iden' => 'all',
|
|
||||||
'eagerLoad' => [
|
'eagerLoad' => [
|
||||||
'HasOneEagerLoadObject.HasOneSubEagerLoadObject.HasOneSubSubEagerLoadObject',
|
'HasOneEagerLoadObject.HasOneSubEagerLoadObject.HasOneSubSubEagerLoadObject',
|
||||||
'BelongsToEagerLoadObject.BelongsToSubEagerLoadObject.BelongsToSubSubEagerLoadObject',
|
'BelongsToEagerLoadObject.BelongsToSubEagerLoadObject.BelongsToSubSubEagerLoadObject',
|
||||||
@ -2518,6 +2496,7 @@ class DataListTest extends SapphireTest
|
|||||||
$manyManyThroughSubObj = new ManyManyThroughSubEagerLoadObject();
|
$manyManyThroughSubObj = new ManyManyThroughSubEagerLoadObject();
|
||||||
$manyManyThroughSubObj->Title = "manyManyThroughSubObj $i $j $k";
|
$manyManyThroughSubObj->Title = "manyManyThroughSubObj $i $j $k";
|
||||||
$manyManyThroughSubObj->write();
|
$manyManyThroughSubObj->write();
|
||||||
|
|
||||||
$manyManyThroughObj->ManyManyThroughSubEagerLoadObjects()->add($manyManyThroughSubObj);
|
$manyManyThroughObj->ManyManyThroughSubEagerLoadObjects()->add($manyManyThroughSubObj);
|
||||||
for ($l = 0; $l < 2; $l++) {
|
for ($l = 0; $l < 2; $l++) {
|
||||||
$manyManyThroughSubSubObj = new ManyManyThroughSubSubEagerLoadObject();
|
$manyManyThroughSubSubObj = new ManyManyThroughSubSubEagerLoadObject();
|
||||||
|
Loading…
Reference in New Issue
Block a user