/** * Sets up the tests */ public function setUp() { $dataPath = realpath(__DIR__ . '/..'); $this->config = parse_ini_file($dataPath . '/data/entities.doctrine.ini', true); $connection = DriverManager::getConnection(['url' => $this->config['databaseUrl']]); $this->transactor = new DoctrineTransactor($connection); $this->idAccessorRegistry = new IdAccessorRegistry(); $repositoryFactory = new RepositoryFactory($this->config, $connection, $this->transactor); $this->idAccessorRegistry->registerIdAccessors(User::class, function (User $user) { return $user->getId(); }, function (User $user, $id) { $user->setId($id); }); $strategy = new RecursiveDirectoryStrategy($this->config['definitionPath']); $locator = new Locator([$strategy]); $this->builder = new EntityBuilder($locator, $repositoryFactory); $this->repo = $repositoryFactory->forEntity(User::class); $this->entityRegistry = $repositoryFactory->getEntityRegistry(); $this->unitOfWork = new UnitOfWorkAccessDecorator($repositoryFactory->getUnitOfWork()); $this->dataMapper = $this->unitOfWork->getDataMapper(User::class); /** * The Ids are purposely unique so that we can identify them as such without having to first insert them to * assign unique Ids * They are also purposely set to 724, 1987, and 345 so that they won't potentially overlap with any default * values set to the Ids */ $this->entity1 = new User(724, "foo"); $this->entity2 = new User(1987, "bar"); $this->entity3 = new User(345, "baz"); }
public function setUp() { $this->onBeforeSetup(); $repositoryFactory = new RepositoryFactory($this->config, $this->connection, $this->transactor); $this->entityRegistry = $repositoryFactory->getEntityRegistry(); $this->builder = $repositoryFactory->getEntityBuilder(); $this->unitOfWork = $repositoryFactory->getUnitOfWork(); $this->idAccessorRegistry = $repositoryFactory->getIdAccessorRegistry(); $this->onAfterSetUp(); }
/** * @param HasOne[] $relations * @param object $entity * @param int|string $entityId */ private function resolveHasOne($relations, $entity, $entityId) { $entityRegistry = $this->repositoryFactory->getEntityRegistry(); foreach ($relations as $field => $relation) { /** @var HasOne $relation */ $varObjName = $relation->varObjectName(); $colRefName = $relation->colReferenceName(); $entityClass = $this->resolveAlias($relation->entity); $object = $entityRegistry->getEntity($entityClass, $entityId); if (empty($object)) { $repository = $this->getRepository($entityClass); try { $object = $repository->findOne()->with($colRefName, Operator::EQUAL, $entityId)->getItem(); } catch (EntityNotFoundException $e) { $object = null; } } $entity->{$varObjName} = $object; } }
public function setUp() { $repositoryFactory = new RepositoryFactory($this->config, $this->connection, $this->transactor); $this->entityRegistry = $repositoryFactory->getEntityRegistry(); $this->unitOfWork = $repositoryFactory->getUnitOfWork(); }