Skip to content

Commit

Permalink
Fix returned empty arguments when args are passed via func_get_args (#…
Browse files Browse the repository at this point in the history
…1047)

Closes #1046
  • Loading branch information
julienbornstein committed Oct 27, 2020
1 parent 25e127f commit 822bf9d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
35 changes: 35 additions & 0 deletions fixtures/Entity/DummyWithNoArgumentConstructor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Alice package.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Nelmio\Alice\Entity;

class DummyWithNoArgumentConstructor
{
/**
* @var array
*/
private $args;

public function __construct()
{
$this->args = func_get_args();
}

/**
* @return array
*/
public function getArgs(): array
{
return $this->args;
}
}
4 changes: 4 additions & 0 deletions src/Generator/NamedArgumentsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public function resolveArguments(array $arguments, string $className, string $me
return $arguments;
}

if (0 === count($method->getParameters())) {
return $arguments;
}

$sortedArguments = [];
$buffer = [];

Expand Down
14 changes: 14 additions & 0 deletions tests/Generator/NamedArgumentsResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Nelmio\Alice\Generator;

use Nelmio\Alice\Entity\DummyWithNoArgumentConstructor;
use Nelmio\Alice\Entity\DummyWithMethods;
use Nelmio\Alice\Entity\EmptyDummy;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -302,6 +303,19 @@ public function provideResolveArgumentsCases()
'bar2' => null,
],
];

yield 'with arguments passed to a constructor that does not expect arguments' => [
DummyWithNoArgumentConstructor::class,
'__construct',
[
'foo',
'bar',
],
[
'foo',
'bar',
],
];
}

public function testThrowsExceptionWhenResolvingUnknownArguments(): void
Expand Down

0 comments on commit 822bf9d

Please sign in to comment.