/** * delete() delegates call to connection */ public function testDelete() { $this->connection->expects($this->once())->method('delete')->willReturn(1); $this->dataMapper->delete(new Article()); }
/** * Creates a DataMapper * * @param string $entityClass The Entity's class * * @return DataMapperInterface */ private function createDataMapper($entityClass) { $dataMapperClass = isset($this->config['dataMapper']) ? $this->config['dataMapper'] : DoctrineDataMapper::class; $meta = $this->builder->getMeta($entityClass); if ($meta->storage['type'] == 'api') { $dataMapperClass = $meta->storage['handler']; } switch ($dataMapperClass) { case CsvDataMapper::class: if (!isset($this->connections[CsvDataGateway::class])) { $this->connections[CsvDataGateway::class] = new CsvDataGateway($this->config['dataPath']); } $dataMapper = new CsvDataMapper($this->connections[CsvDataGateway::class], $entityClass, $meta->storage['table'], $this->entityRegistry); break; case DoctrineDataMapper::class: if (!isset($this->connections[Connection::class])) { $this->connections[Connection::class] = DriverManager::getConnection(['url' => $this->config['databaseUrl']]); } $dataMapper = new DoctrineDataMapper($this->connections[Connection::class], $entityClass, $meta->storage['table'], $this->entityRegistry); $dataMapper->setDispatcher($this->getDispatcher()); break; default: throw new OrmException("No data mapper '{$dataMapperClass}' for '{$entityClass}'"); break; } return $dataMapper; }