protected function getDocumentManager() { $config = new Configuration(); $config->setProxyDir(sys_get_temp_dir() . '/JMSDoctrineTestProxies'); $config->setProxyNamespace('JMS\\Tests\\Proxies'); $config->setMetadataDriverImpl(new DoctrinePHPCRDriver(new AnnotationReader(), __DIR__ . '/../../Fixtures/DoctrinePHPCR')); $session = $this->getMock('PHPCR\\SessionInterface'); return DocumentManager::create($session, $config); }
private function loadPhpcrOdm() { $this['psi_content_type.storage.doctrine.phpcr_odm.property_encoder'] = function ($container) { return new PropertyEncoder('psict', 'https://github.com/psiphp/content-type'); }; $this['psi_content_type.storage.doctrine.phpcr_odm.field_mapper'] = function ($container) { return new FieldMapper($container['psi_content_type.storage.doctrine.phpcr_odm.property_encoder'], $container['psi_content_type.field_loader']); }; $this['psi_content_type.storage.doctrine.phpcr_odm.collection_updater'] = function ($container) { return new CollectionIdentifierUpdater($container['psi_content_type.metadata.factory'], $container['psi_content_type.storage.doctrine.phpcr_odm.property_encoder']); }; $this['doctrine_phpcr.document_manager'] = function ($container) { $registerNodeTypes = false; // automatically setup the schema if the db doesn't exist yet. if (!file_exists($container['config']['db_path'])) { if (!file_exists($dir = dirname($container['config']['db_path']))) { mkdir($dir); } $connection = $container['dbal.connection']; $schema = new RepositorySchema(); foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) { $connection->exec($sql); } $registerNodeTypes = true; } // register the phpcr session $factory = new RepositoryFactoryDoctrineDBAL(); $repository = $factory->getRepository(['jackalope.doctrine_dbal_connection' => $container['dbal.connection']]); $session = $repository->login(new SimpleCredentials(null, null), 'default'); if ($registerNodeTypes) { $typeRegistrator = new NodeTypeRegistrator(); $typeRegistrator->registerNodeTypes($session); $ctTypeRegistrator = new CtNodeTypeRegistrator($container['psi_content_type.storage.doctrine.phpcr_odm.property_encoder']); $ctTypeRegistrator->registerNodeTypes($session); } // annotation driver $annotationDriver = new AnnotationDriver($container['annotation_reader'], [__DIR__ . '/../../vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Document', __DIR__ . '/Example']); $xmlDriver = new XmlDriver([__DIR__ . '/mappings']); $annotationDriver = new AnnotationDriver($container['annotation_reader'], [__DIR__ . '/../../vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Document', __DIR__ . '/Example']); $chain = new MappingDriverChain(); $chain->addDriver($annotationDriver, 'Psi\\Bridge\\ContentType\\Doctrine\\PhpcrOdm\\Tests\\Functional\\Example'); $chain->addDriver($xmlDriver, 'Psi\\Component\\ContentType\\Tests\\Functional\\Example\\Model'); $chain->addDriver($annotationDriver, 'Doctrine'); $config = new Configuration(); $config->setMetadataDriverImpl($chain); $manager = DocumentManager::create($session, $config); $manager->getEventManager()->addEventSubscriber(new MetadataSubscriber($container['psi_content_type.metadata.factory'], $container['psi_content_type.field_loader'], $container['psi_content_type.storage.doctrine.phpcr_odm.field_mapper'])); $manager->getEventManager()->addEventSubscriber(new CollectionSubscriber($container['psi_content_type.metadata.factory'], $container['psi_content_type.storage.doctrine.phpcr_odm.property_encoder'])); return $manager; }; }
public function __construct(SessionInterface $session, Configuration $config = null, EventManager $evm = null) { $this->session = $session; $this->config = $config ?: new Configuration(); $this->evm = $evm ?: new EventManager(); $this->metadataFactory = new ClassMetadataFactory($this); $this->unitOfWork = new UnitOfWork($this); $this->proxyFactory = new ProxyFactory($this, $this->config->getProxyDir(), $this->config->getProxyNamespace(), $this->config->getAutoGenerateProxyClasses()); // initialize default translation strategies $this->translationStrategy = array('attribute' => new AttributeTranslationStrategy(), 'child' => new ChildTranslationStrategy()); }
public function testUuid() { $class = new \ReflectionClass('Doctrine\\ODM\\PHPCR\\UnitOfWork'); $method = $class->getMethod('generateUuid'); $method->setAccessible(true); $this->assertInternalType('string', $method->invoke($this->uow)); $config = new Configuration(); $config->setUuidGenerator(function () { return 'like-a-uuid'; }); $dm = DocumentManager::create($this->session, $config); $uow = new UnitOfWork($dm); $this->assertEquals('like-a-uuid', $method->invoke($uow)); }