Skip to content

Commit

Permalink
Fix: Rename FieldDef to FieldDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Mar 28, 2020
1 parent d7257e2 commit 0f711d1
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ For a full diff see [`fa9c564...master`][fa9c564...master].
* Marked `EntityDef` as internal ([#49]), by [@localheinz]
* Started throwing an `InvalidFieldNames` exception instead of a generic `Exception` when fields are referenced that are not present in the corresponding entity ([#87]), by [@localheinz]
* Renamed `EntityDef` to `EntityDefinition` ([#91]), by [@localheinz]
* Renamed `FieldDef` to `FieldDefinition` ([#92]), by [@localheinz]

### Fixed

Expand All @@ -45,5 +46,6 @@ For a full diff see [`fa9c564...master`][fa9c564...master].
[#79]: https://github.com/ergebnis/factory-bot/pull/79
[#87]: https://github.com/ergebnis/factory-bot/pull/87
[#91]: https://github.com/ergebnis/factory-bot/pull/91
[#92]: https://github.com/ergebnis/factory-bot/pull/92

[@localheinz]: https://github.com/localheinz
4 changes: 2 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ parameters:
-
message: "#^Anonymous function should have native return typehint \"string\"\\.$#"
count: 2
path: src/FieldDef.php
path: src/FieldDefinition.php

-
message: "#^Parameter \\#2 \\$replace of function str_replace expects array\\|string, int given\\.$#"
count: 1
path: src/FieldDef.php
path: src/FieldDefinition.php

-
message: "#^Method Ergebnis\\\\FactoryBot\\\\FixtureFactory\\:\\:get\\(\\) has no return typehint specified\\.$#"
Expand Down
2 changes: 1 addition & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<code>\method_exists($fieldDefinition, '__invoke')</code>
</TypeDoesNotContainType>
</file>
<file src="src/FieldDef.php">
<file src="src/FieldDefinition.php">
<MissingClosureReturnType occurrences="3">
<code>static function () use (&amp;$n, $funcOrString) {</code>
<code>static function (FixtureFactory $factory) use ($name) {</code>
Expand Down
2 changes: 1 addition & 1 deletion src/FieldDef.php → src/FieldDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* Contains static methods to define fields as sequences, references etc.
*/
final class FieldDef
final class FieldDefinition
{
/**
* Defines a field to be a string based on an incrementing integer.
Expand Down
2 changes: 1 addition & 1 deletion test/AutoReview/SrcCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testSrcClassesHaveUnitTests(): void
'Ergebnis\\FactoryBot\\Test\\Unit',
[
FactoryBot\EntityDefinition::class,
FactoryBot\FieldDef::class,
FactoryBot\FieldDefinition::class,
]
);
}
Expand Down
6 changes: 3 additions & 3 deletions test/Integration/FixtureFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Ergebnis\FactoryBot\Test\Integration;

use Ergebnis\FactoryBot\FieldDef;
use Ergebnis\FactoryBot\FieldDefinition;
use Ergebnis\FactoryBot\FixtureFactory;
use Ergebnis\FactoryBot\Test\Fixture;
use Ergebnis\Test\Util\Helper;
Expand Down Expand Up @@ -82,13 +82,13 @@ public function testDoesNotPersistEmbeddableWhenAutomaticPersistingIsTurnedOn():
$fixtureFactory = new FixtureFactory($entityManager);

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Avatar::class, [
'url' => FieldDef::sequence(static function () use ($faker): string {
'url' => FieldDefinition::sequence(static function () use ($faker): string {
return $faker->imageUrl();
}),
]);

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\User::class, [
'avatar' => FieldDef::reference(Fixture\FixtureFactory\Entity\Avatar::class),
'avatar' => FieldDefinition::reference(Fixture\FixtureFactory\Entity\Avatar::class),
'login' => $faker->userName,
]);

Expand Down
38 changes: 19 additions & 19 deletions test/Unit/FixtureFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use Doctrine\ORM;
use Ergebnis\FactoryBot\Exception;
use Ergebnis\FactoryBot\FieldDef;
use Ergebnis\FactoryBot\FieldDefinition;
use Ergebnis\FactoryBot\FixtureFactory;
use Ergebnis\FactoryBot\Test\Fixture;
use Ergebnis\Test\Util\Helper;
Expand All @@ -24,7 +24,7 @@
* @internal
*
* @covers \Ergebnis\FactoryBot\EntityDefinition
* @covers \Ergebnis\FactoryBot\FieldDef
* @covers \Ergebnis\FactoryBot\FieldDefinition
* @covers \Ergebnis\FactoryBot\FixtureFactory
*
* @uses \Ergebnis\FactoryBot\Exception\EntityDefinitionUnavailable
Expand Down Expand Up @@ -154,7 +154,7 @@ public function testDefineEntityAllowsDefiningAndReferencingEmbeddables(): void
]);

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\User::class, [
'avatar' => FieldDef::reference(Fixture\FixtureFactory\Entity\Avatar::class),
'avatar' => FieldDefinition::reference(Fixture\FixtureFactory\Entity\Avatar::class),
]);

$user = $fixtureFactory->get(Fixture\FixtureFactory\Entity\User::class);
Expand Down Expand Up @@ -329,7 +329,7 @@ public function testArrayElementsAreMappedToCollectionAsscociationFields(): void
$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Organization::class);

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Repository::class, [
'organization' => FieldDef::reference(Fixture\FixtureFactory\Entity\Organization::class),
'organization' => FieldDefinition::reference(Fixture\FixtureFactory\Entity\Organization::class),
]);

/** @var Fixture\FixtureFactory\Entity\Repository $repositoryOne */
Expand Down Expand Up @@ -388,7 +388,7 @@ public function testBidirectionalOntToManyReferencesAreAssignedBothWays(): void
$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Organization::class);

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Repository::class, [
'organization' => FieldDef::reference(Fixture\FixtureFactory\Entity\Organization::class),
'organization' => FieldDefinition::reference(Fixture\FixtureFactory\Entity\Organization::class),
]);

/** @var Fixture\FixtureFactory\Entity\Repository $repository */
Expand All @@ -404,7 +404,7 @@ public function testUnidirectionalReferencesWorkAsUsual(): void
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Project::class, [
'repository' => FieldDef::reference(Fixture\FixtureFactory\Entity\Repository::class),
'repository' => FieldDefinition::reference(Fixture\FixtureFactory\Entity\Repository::class),
]);

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Repository::class);
Expand All @@ -420,7 +420,7 @@ public function testReferencedObjectsShouldBeCreatedAutomatically(): void
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Organization::class, [
'repositories' => FieldDef::references(Fixture\FixtureFactory\Entity\Repository::class),
'repositories' => FieldDefinition::references(Fixture\FixtureFactory\Entity\Repository::class),
]);

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Repository::class, [
Expand All @@ -443,7 +443,7 @@ public function testReferencedObjectsShouldBeOverrideable(): void
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Organization::class, [
'repositories' => FieldDef::references(Fixture\FixtureFactory\Entity\Repository::class),
'repositories' => FieldDefinition::references(Fixture\FixtureFactory\Entity\Repository::class),
]);

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Repository::class, [
Expand All @@ -466,7 +466,7 @@ public function testReferencedObjectsShouldBeNullable(): void
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Repository::class, [
'template' => FieldDef::references(Fixture\FixtureFactory\Entity\Repository::class),
'template' => FieldDefinition::references(Fixture\FixtureFactory\Entity\Repository::class),
]);

/** @var Fixture\FixtureFactory\Entity\Repository $repository */
Expand Down Expand Up @@ -585,7 +585,7 @@ public function testReferencedObjectsCanBeSingletons(): void
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Organization::class, [
'repositories' => FieldDef::references(Fixture\FixtureFactory\Entity\Repository::class),
'repositories' => FieldDefinition::references(Fixture\FixtureFactory\Entity\Repository::class),
]);

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Repository::class, [
Expand All @@ -611,7 +611,7 @@ public function testWhenTheOneSideIsASingletonItMayGetSeveralChildObjects(): voi
$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Organization::class);

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Repository::class, [
'organization' => FieldDef::reference(Fixture\FixtureFactory\Entity\Organization::class),
'organization' => FieldDefinition::reference(Fixture\FixtureFactory\Entity\Organization::class),
]);

/** @var Fixture\FixtureFactory\Entity\Organization $organization */
Expand Down Expand Up @@ -709,7 +709,7 @@ public function testReferencedObjectShouldBeCreatedAutomatically(): void

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Repository::class, [
'name' => self::faker()->word,
'organization' => FieldDef::reference(Fixture\FixtureFactory\Entity\Organization::class),
'organization' => FieldDefinition::reference(Fixture\FixtureFactory\Entity\Organization::class),
]);

/** @var Fixture\FixtureFactory\Entity\Repository $repositoryOne */
Expand All @@ -733,11 +733,11 @@ public function testReferencesGetInstantiatedTransitively(): void
$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Organization::class);

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Repository::class, [
'organization' => FieldDef::reference(Fixture\FixtureFactory\Entity\Organization::class),
'organization' => FieldDefinition::reference(Fixture\FixtureFactory\Entity\Organization::class),
]);

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Project::class, [
'repository' => FieldDef::reference(Fixture\FixtureFactory\Entity\Repository::class),
'repository' => FieldDefinition::reference(Fixture\FixtureFactory\Entity\Repository::class),
]);

$project = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Project::class);
Expand All @@ -761,11 +761,11 @@ public function testTransitiveReferencesWorkWithSingletons(): void
$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Organization::class);

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Repository::class, [
'organization' => FieldDef::reference(Fixture\FixtureFactory\Entity\Organization::class),
'organization' => FieldDefinition::reference(Fixture\FixtureFactory\Entity\Organization::class),
]);

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Project::class, [
'repository' => FieldDef::reference(Fixture\FixtureFactory\Entity\Repository::class),
'repository' => FieldDefinition::reference(Fixture\FixtureFactory\Entity\Repository::class),
]);

$fixtureFactory->getAsSingleton(Fixture\FixtureFactory\Entity\Organization::class);
Expand All @@ -792,7 +792,7 @@ public function testSequenceGeneratorCallsAFunctionWithAnIncrementingArgument():
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Organization::class, [
'name' => FieldDef::sequence(static function (int $i): string {
'name' => FieldDefinition::sequence(static function (int $i): string {
return \sprintf(
'alpha-%d',
$i
Expand Down Expand Up @@ -823,7 +823,7 @@ public function testSequenceGeneratorCanTakeAPlaceholderString(): void
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Organization::class, [
'name' => FieldDef::sequence('beta-%d'),
'name' => FieldDefinition::sequence('beta-%d'),
]);

/** @var Fixture\FixtureFactory\Entity\Organization $organizationOne */
Expand All @@ -849,7 +849,7 @@ public function testSequenceGeneratorCanTakeAStringToAppendTo(): void
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Organization::class, [
'name' => FieldDef::sequence('gamma-'),
'name' => FieldDefinition::sequence('gamma-'),
]);

/** @var Fixture\FixtureFactory\Entity\Organization $organizationOne */
Expand Down

0 comments on commit 0f711d1

Please sign in to comment.