Skip to content

Commit

Permalink
Merge pull request #189 from ergebnis/fix/rename
Browse files Browse the repository at this point in the history
Fix: Rename get() to create()
  • Loading branch information
ergebnis-bot committed Apr 24, 2020
2 parents 477162a + 3034897 commit a5dd5f1
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 101 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -36,6 +36,7 @@ For a full diff see [`fa9c564...master`][fa9c564...master].
* Extracted `FieldDefinition\Closure` ([#161]), by [@localheinz]
* Extracted `FieldDefinition\Sequence` ([#164]), by [@localheinz]
* Introduced named constructors for field definitions and marked primary constructor as `private` ([#188]), by [@localheinz]
* Renamed `FixtureFactory::get()` to `FixtureFactory::create()` ([#189]), by [@localheinz]

### Fixed

Expand Down Expand Up @@ -95,5 +96,6 @@ For a full diff see [`fa9c564...master`][fa9c564...master].
[#164]: https://github.com/ergebnis/factory-bot/pull/164
[#185]: https://github.com/ergebnis/factory-bot/pull/185
[#188]: https://github.com/ergebnis/factory-bot/pull/188
[#189]: https://github.com/ergebnis/factory-bot/pull/189

[@localheinz]: https://github.com/localheinz
2 changes: 1 addition & 1 deletion src/FieldDefinition/Reference.php
Expand Up @@ -72,6 +72,6 @@ public static function required(string $className): self
*/
public function resolve(FixtureFactory $fixtureFactory)
{
return $fixtureFactory->get($this->className);
return $fixtureFactory->create($this->className);
}
}
8 changes: 2 additions & 6 deletions src/FixtureFactory.php
Expand Up @@ -143,10 +143,6 @@ public function defineEntity(string $className, array $fieldDefinitions = [], ?\
}

/**
* Get an entity and its dependencies.
*
* If you've called `persistOnGet()` then the entity is also persisted.
*
* @phpstan-param class-string<T> $className
* @phpstan-return T
* @phpstan-template T
Expand All @@ -163,7 +159,7 @@ public function defineEntity(string $className, array $fieldDefinitions = [], ?\
*
* @return object
*/
public function get(string $className, array $fieldOverrides = [])
public function create(string $className, array $fieldOverrides = [])
{
if (!\array_key_exists($className, $this->entityDefinitions)) {
throw Exception\EntityDefinitionNotRegistered::for($className);
Expand Down Expand Up @@ -261,7 +257,7 @@ public function getList(string $className, array $fieldOverrides = [], int $coun
$instances = [];

for ($i = 0; $i < $count; ++$i) {
$instances[] = $this->get(
$instances[] = $this->create(
$className,
$fieldOverrides
);
Expand Down
12 changes: 6 additions & 6 deletions test/Integration/FixtureFactoryTest.php
Expand Up @@ -30,7 +30,7 @@
*/
final class FixtureFactoryTest extends AbstractTestCase
{
public function testAutomaticPersistCanBeTurnedOn(): void
public function testCreatePersistsEntityWhenPersistOnGetHasBeenTurnedOn(): void
{
$entityManager = self::entityManager();

Expand All @@ -43,15 +43,15 @@ public function testAutomaticPersistCanBeTurnedOn(): void
$fixtureFactory->persistOnGet();

/** @var Fixture\FixtureFactory\Entity\Organization $organization */
$organization = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Organization::class);
$organization = $fixtureFactory->create(Fixture\FixtureFactory\Entity\Organization::class);

$entityManager->flush();

self::assertNotNull($organization->id());
self::assertSame($organization, $entityManager->find(Fixture\FixtureFactory\Entity\Organization::class, $organization->id()));
}

public function testDoesNotPersistByDefault(): void
public function testCreateDoesNotNotPersistEntityByDefault(): void
{
$entityManager = self::entityManager();

Expand All @@ -62,7 +62,7 @@ public function testDoesNotPersistByDefault(): void
]);

/** @var Fixture\FixtureFactory\Entity\Organization $organization */
$organization = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Organization::class);
$organization = $fixtureFactory->create(Fixture\FixtureFactory\Entity\Organization::class);

$entityManager->flush();

Expand All @@ -76,7 +76,7 @@ public function testDoesNotPersistByDefault(): void
self::assertEmpty($query->getResult());
}

public function testDoesNotPersistEmbeddableWhenAutomaticPersistingIsTurnedOn(): void
public function testCreateDoesNotPersistEmbeddablesWhenPersistOnGetHasBeenTurnedOn(): void
{
$faker = self::faker();

Expand All @@ -97,7 +97,7 @@ public function testDoesNotPersistEmbeddableWhenAutomaticPersistingIsTurnedOn():

$fixtureFactory->persistOnGet();

$fixtureFactory->get(Fixture\FixtureFactory\Entity\User::class);
$fixtureFactory->create(Fixture\FixtureFactory\Entity\User::class);

$entityManager->flush();

Expand Down
2 changes: 1 addition & 1 deletion test/Unit/FieldDefinition/ClosureTest.php
Expand Up @@ -37,7 +37,7 @@ public function testResolveReturnsResultOfInvokingClosureWithFixtureFactory(): v
$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\User::class);

$closure = static function (FixtureFactory $fixtureFactory): Fixture\FixtureFactory\Entity\User {
return $fixtureFactory->get(Fixture\FixtureFactory\Entity\User::class);
return $fixtureFactory->create(Fixture\FixtureFactory\Entity\User::class);
};

$fieldDefinition = Closure::required($closure);
Expand Down
2 changes: 1 addition & 1 deletion test/Unit/FieldDefinitionTest.php
Expand Up @@ -36,7 +36,7 @@ public function testClosureReturnsClosure(): void
{
$closure = static function (FixtureFactory $fixtureFactory): Fixture\FixtureFactory\Entity\User {
/** @var Fixture\FixtureFactory\Entity\User $user */
$user = $fixtureFactory->get(Fixture\FixtureFactory\Entity\User::class);
$user = $fixtureFactory->create(Fixture\FixtureFactory\Entity\User::class);

$user->renameTo(self::faker()->userName);

Expand Down

0 comments on commit a5dd5f1

Please sign in to comment.