forked from nelmio/alice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better handling of references to inexistent fixtures (nelmio#592)
As of now if a reference to an inexistent fixture in a constructor is made, as no object is found for it, the reference resolver will try to instantiate that fixture. However as it is a temporary fixture, it has no class leading to this obscure error: `Class does not exist in /path/to/alice/src/Generator/Instantiator/Chainable/NullConstructorInstantiator.php:36` A solution is to check if this fixture exist when no object is found to thrown an error before trying to generate it.
- Loading branch information
Showing
9 changed files
with
188 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Alice package. | ||
* | ||
* (c) Nelmio <[email protected]> | ||
* | ||
* 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\Definition\Fixture; | ||
|
||
use Nelmio\Alice\FixtureIdInterface; | ||
|
||
final class FixtureId implements FixtureIdInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $id; | ||
|
||
public function __construct(string $id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getId(): string | ||
{ | ||
return $this->id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Alice package. | ||
* | ||
* (c) Nelmio <[email protected]> | ||
* | ||
* 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; | ||
|
||
/** | ||
* A fixture is a value object representing an object to be built. | ||
*/ | ||
interface FixtureIdInterface | ||
{ | ||
/** | ||
* @return string e.g. 'dummy0'. May contain flags e.g. 'dummy (extends base_dummy)' depending of the implementation. | ||
*/ | ||
public function getId(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Alice package. | ||
* | ||
* (c) Nelmio <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nelmio\Alice\Definition\Fixture; | ||
|
||
use Nelmio\Alice\FixtureIdInterface; | ||
|
||
/** | ||
* @covers \Nelmio\Alice\Definition\Fixture\FixtureId | ||
*/ | ||
class FixtureIdTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testIsAFixtureId() | ||
{ | ||
$this->assertTrue(is_a(FixtureId::class, FixtureIdInterface::class, true)); | ||
} | ||
|
||
public function testAccessor() | ||
{ | ||
$id = new FixtureId('foo'); | ||
$this->assertEquals('foo', $id->getId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.