Skip to content

Commit

Permalink
correct constructor check in ReflectionWithConstructor
Browse files Browse the repository at this point in the history
  • Loading branch information
bendavies authored and Ben Davies committed Dec 23, 2015
1 parent f9afb65 commit 699b71b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(Processor $processor, TypeHintChecker $typeHintCheck
*/
public function canInstantiate(Fixture $fixture)
{
$refl = new \ReflectionMethod($fixture->getClass(), '__construct');
$refl = new \ReflectionMethod($fixture->getClass(), $fixture->getConstructorMethod());

return $fixture->shouldUseConstructor() && $refl->getNumberOfRequiredParameters() <= count($fixture->getConstructorArgs());
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Nelmio/Alice/Fixtures/FixtureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,16 @@ public function testHasNameFlagWillReturnIfNameFLagExists()

public function testGetConstructorMethodWillReturnTheMethodName()
{
$fixture = new Fixture(self::USER, 'user', ['__construct' => ['create' => ['1', '2', '3']]], null);
$fixture = new Fixture(self::USER, 'user', ['__construct' => ['create' => ['1']]], null);

$this->assertEquals('create', $fixture->getConstructorMethod());
}

public function testGetConstructorArgsWillReturnTheArgumentsList()
{
$fixture = new Fixture(self::USER, 'user', ['__construct' => ['create' => ['1', '2', '3']]], null);
$fixture = new Fixture(self::USER, 'user', ['__construct' => ['create' => ['1']]], null);

$this->assertEquals(['1', '2', '3'], $fixture->getConstructorArgs());
$this->assertEquals(['1'], $fixture->getConstructorArgs());
}

public function testShouldUseConstructorWillReturnTrueIfThereIsNoConstructorInTheSpec()
Expand Down
4 changes: 2 additions & 2 deletions tests/Nelmio/Alice/support/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public function __construct($username = null, $email = null, \DateTime $birthDat
$this->birthDate = $birthDate;
}

public static function create($username = null, $email = null, \DateTime $birthDate = null)
public static function create($username = null)
{
return new static($username . '-from-create', $email, $birthDate);
return new static($username . '-from-create', null, null);
}

public static function bogusCreate($username = null, $email = null, \DateTime $birthDate = null)
Expand Down

0 comments on commit 699b71b

Please sign in to comment.