/** * 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"); }
/** * Execute the command * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * * @return integer 0 if everything went fine, 1 on error */ protected function execute(InputInterface $input, OutputInterface $output) { $this->setupEnvironment($input, $output); $this->repositoryFactory = $this->container->get('Repository'); $entity = $this->normaliseEntityName($input->getArgument('entity')); $repository = $this->repositoryFactory->forEntity($entity); $finder = $repository->findAll(); try { $this->applyFilter($input->getOption('filter'), $finder); $this->doIt($input, $output, $finder, $entity); $this->dumpSql($input, $output); } catch (InvalidFilterException $e) { $this->writeln($output, $e->getMessage()); $this->dumpSql($input, $output); return 1; } catch (NoRecordsException $e) { $this->writeln($output, $e->getMessage()); $this->dumpSql($input, $output); return 0; } return 0; }
/** * Gets a repository for an entity class * * @param string $entityClass The entity class * * @return RepositoryInterface */ public function getRepository($entityClass) { return $this->repositoryFactory->forEntity($this->resolveAlias($entityClass)); }