Skip to content

Commit

Permalink
Fix issue with inheritance
Browse files Browse the repository at this point in the history
The array values the collection need to keep the self elements as
leading values, by switch the parameters this is done.

fixes #3633
  • Loading branch information
jaapio committed Jan 8, 2024
1 parent ae81a7b commit 635e8d3
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/phpDocumentor/Descriptor/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public function offsetUnset($offset): void
*/
public function merge(self $collection): Collection
{
return new self(array_merge($this->items, $collection->getAll()));
return new self(array_merge($collection->getAll(), $this->items));
}

/**
Expand Down
22 changes: 13 additions & 9 deletions tests/unit/phpDocumentor/Descriptor/ClassDescriptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,20 @@ public function testRetrievingInheritedMethodsReturnsEmptyCollectionWithoutParen
/** @covers ::getInheritedMethods */
public function testRetrievingInheritedMethodsReturnsCollectionWithParent(): void
{
$mock = m::mock(ClassDescriptor::class);
$mock->shouldReceive('getMethods')->andReturn(new Collection(['methods']));
$mock->shouldReceive('getInheritedMethods')->andReturn(new Collection(['inherited']));
$grandParent = new ClassDescriptor();
$grandParent->getMethods()->set('construct', new MethodDescriptor());

$this->fixture->setParent($mock);
$result = $this->fixture->getInheritedMethods();
$parent = new ClassDescriptor();
$parent->getMethods()->set('construct', new MethodDescriptor());
$parent->getMethods()->set('otherMethod', new MethodDescriptor());
$parent->setParent($grandParent);
$this->fixture->setParent($parent);

self::assertInstanceOf(Collection::class, $result);
$expected = [];
$expected['construct'] = $parent->getMethods()->get('construct');
$expected['otherMethod'] = $parent->getMethods()->get('otherMethod');

$expected = ['methods', 'inherited'];
$result = $this->fixture->getInheritedMethods();
self::assertSame($expected, $result->getAll());
}

Expand Down Expand Up @@ -220,7 +224,7 @@ public function testGetInheritedConstantsWithClassDescriptorParent(): void

self::assertInstanceOf(Collection::class, $result);

$expected = ['constants', 'inherited'];
$expected = ['inherited', 'constants'];
self::assertSame($expected, $result->getAll());
}

Expand Down Expand Up @@ -248,7 +252,7 @@ public function testGetInheritedPropertiesWithClassDescriptorParent(): void

self::assertInstanceOf(Collection::class, $result);

$expected = ['properties', 'inherited'];
$expected = ['inherited', 'properties'];
self::assertSame($expected, $result->getAll());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/phpDocumentor/Descriptor/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function testIfExistingElementsAreDetected(): void
/** @covers ::merge */
public function testIfAfterMergeCollectionContainsAllItems(): void
{
$expected = [0 => 'a', 1 => 'b', 2 => 'c'];
$expected = [0 => 'c', 1 => 'a', 2 => 'b'];
$this->fixture[1] = 'a';
$this->fixture[2] = 'b';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public function testSettingAndGettingErrors(): void
$this->fixture->setErrors(new Collection([$descriptorError]));
$this->fixture->setTags(new Collection([new Collection([$tagDescriptor->reveal()])]));

self::assertSame([$descriptorError, $tagError], $this->fixture->getErrors()->getAll());
self::assertSame([$tagError, $descriptorError], $this->fixture->getErrors()->getAll());
}

/**
Expand Down
22 changes: 11 additions & 11 deletions tests/unit/phpDocumentor/Descriptor/FileDescriptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,18 @@ public function testGetAllErrors(): void

// final merge and check
$expectedErrors = [
...$errorGlobal,
...$errorClasses,
...$errorInterfaces,
...$errorTraits,
...$errorFunctions,
...$errorClassMethods,
...$errorClassConstants,
...$errorClassProperties,
...$errorInterfacesMethods,
...$errorInterfacesConstants,
...$errorTraitsMethods,
...$errorTraitsProperties,
...$errorTraitsMethods,
...$errorInterfacesConstants,
...$errorInterfacesMethods,
...$errorClassProperties,
...$errorClassConstants,
...$errorClassMethods,
...$errorFunctions,
...$errorTraits,
...$errorInterfaces,
...$errorClasses,
...$errorGlobal,
];

self::assertSame($expectedErrors, $this->fixture->getAllErrors()->getAll());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function testGetInheritedConstantsWithClassDescriptorParent(): void
$result = $this->fixture->getInheritedConstants();

$this->assertInstanceOf(Collection::class, $result);
$this->assertSame([$constantInParent, $constantInGrandParent], $result->getAll());
$this->assertSame([$constantInGrandParent, $constantInParent], $result->getAll());
}

/** @covers ::getInheritedMethods */
Expand Down Expand Up @@ -218,7 +218,7 @@ public function testRetrievingInheritedMethodsReturnsCollectionWithParent(): voi

$this->assertInstanceOf(Collection::class, $result);

$this->assertSame([$parentDescriptor, $grandParentDescriptor], $result->getAll());
$this->assertSame([$grandParentDescriptor, $parentDescriptor], $result->getAll());
}

private function whenFixtureHasParentInterface(): InterfaceDescriptor
Expand Down

0 comments on commit 635e8d3

Please sign in to comment.