Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replicate behavior of implicit entity-to-id casting #41

Open
Firehed opened this issue Jan 7, 2024 · 0 comments
Open

Replicate behavior of implicit entity-to-id casting #41

Firehed opened this issue Jan 7, 2024 · 0 comments

Comments

@Firehed
Copy link
Owner

Firehed commented Jan 7, 2024

If an entity has a property referencing the id of another entity (but isn't defined as a relation; e.g. a Column rather than ManyToOne), and you pass that entity to a find*By* method, Doctrine appears to detect the entity and automatically use its primary key in the actual query. Mocktrine does not have this same behavior, resulting in either misleading test results or forcing specific repository interactions.

Instead, Mocktrine should aim to detect that the query parameter is an entity and use its id to perform lookups.

// Most details elided
#[Entity]
class User
{
  #[Column]
  #[Id]
  public string $id;
}
#[Entity]
class Membership
{
  #[Column]
  public string $userId;
}

// These should produce the same results in Mocktrine, and do in Doctrine
$repo = $this->em->getRepository(Membership::class);
$byId = $repo->findOneBy(['userId' => $user->id]);
$byEntity = $repo->findOneBy(['userId' => $user]);
assert($byId === $byEntity); // fails only under mocktrine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant