public function createDocumentManager(array $paths = null)
 {
     $reader = new \Doctrine\Common\Annotations\AnnotationReader();
     $reader->addGlobalIgnoredName('group');
     if (empty($paths)) {
         $paths = array(__DIR__ . "/../../Models");
     }
     $metaDriver = new AnnotationDriver($reader, $paths);
     $factoryclass = isset($GLOBALS['DOCTRINE_PHPCR_FACTORY']) ? $GLOBALS['DOCTRINE_PHPCR_FACTORY'] : '\\Jackalope\\RepositoryFactoryJackrabbit';
     if ($factoryclass === '\\Jackalope\\RepositoryFactoryDoctrineDBAL') {
         $params = array();
         foreach ($GLOBALS as $key => $value) {
             if (0 === strpos($key, 'jackalope.doctrine.dbal.')) {
                 $params[substr($key, strlen('jackalope.doctrine.dbal.'))] = $value;
             }
         }
         if (isset($params['username'])) {
             $params['user'] = $params['username'];
         }
         $GLOBALS['jackalope.doctrine_dbal_connection'] = \Doctrine\DBAL\DriverManager::getConnection($params);
     }
     $parameters = array_intersect_key($GLOBALS, $factoryclass::getConfigurationKeys());
     // factory will return null if it gets unknown parameters
     $repository = $factoryclass::getRepository($parameters);
     $this->assertNotNull($repository, 'There is an issue with your parameters: ' . var_export(array_keys($parameters), true));
     $workspace = isset($GLOBALS['DOCTRINE_PHPCR_WORKSPACE']) ? $GLOBALS['DOCTRINE_PHPCR_WORKSPACE'] : 'tests';
     $user = isset($GLOBALS['DOCTRINE_PHPCR_USER']) ? $GLOBALS['DOCTRINE_PHPCR_USER'] : '';
     $pass = isset($GLOBALS['DOCTRINE_PHPCR_PASS']) ? $GLOBALS['DOCTRINE_PHPCR_PASS'] : '';
     $credentials = new \PHPCR\SimpleCredentials($user, $pass);
     $session = $repository->login($credentials, $workspace);
     $this->sessions[] = $session;
     $config = new \Doctrine\ODM\PHPCR\Configuration();
     $config->setMetadataDriverImpl($metaDriver);
     return DocumentManager::create($session, $config);
 }
Пример #2
0
 /**
  * @covers Doctrine\ODM\PHPCR\DocumentManager::escapeIllegalCharacters
  */
 public function testEscapeIllegalCharacters()
 {
     $session = $this->getMock('PHPCR\\SessionInterface');
     $dm = DocumentManager::create($session);
     $string = $dm->escapeIllegalCharacters('Some{String}Wit"h[]Illegal^^^Chara\\cte?rs:!');
     $this->assertEquals($string, 'Some\\{String\\}Wit"h\\[\\]Illegal\\^\\^\\^Chara\\cte\\?rs\\:\\!');
 }
 protected function getMockDocumentManager(EventManager $evm = null)
 {
     $config = new \Doctrine\ODM\PHPCR\Configuration();
     $config->setMetadataDriverImpl($this->getMetadataDriverImplementation());
     $this->dm = DocumentManager::create($this->getSession(), $config, $evm ?: $this->getEventManager());
     return $this->dm;
 }
 protected function setUp()
 {
     $params = array('driver' => 'pdo_mysql', 'host' => 'localhost', 'user' => 'root', 'password' => 'testmachine', 'dbname' => 'v_products_tests');
     $workspace = 'default';
     $user = '******';
     $pass = '******';
     $dbConn = \Doctrine\DBAL\DriverManager::getConnection($params);
     $parameters = array('jackalope.doctrine_dbal_connection' => $dbConn);
     /**
             $schema = RepositorySchema::create();
             foreach ($schema->toSql($dbConn->getDatabasePlatform()) as $sql) {
                 $dbConn->exec($sql);
             } */
     $repositoryFactory = new \Jackalope\RepositoryFactoryDoctrineDBAL();
     $repository = $repositoryFactory->getRepository($parameters);
     $credentials = new \PHPCR\SimpleCredentials(null, null);
     $session = $repository->login($credentials, $workspace);
     $locatorXml = new SymfonyFileLocator(array(__DIR__ . '/../../../lib/Vespolina/Product/Mapping' => 'Vespolina\\Entity\\Product', __DIR__ . '/../../../vendor/vespolina/pricing/lib/Vespolina/Pricing/Mapping' => 'Vespolina\\Entity\\Pricing', __DIR__ . '/../../../vendor/vespolina/taxonomy/lib/Vespolina/Taxonomy/Mapping' => 'Vespolina\\Entity\\Taxonomy'), '.phpcr.xml');
     $xmlDriver = new XmlDriver($locatorXml);
     $config = new \Doctrine\ODM\PHPCR\Configuration();
     $config->setMetadataDriverImpl($xmlDriver);
     $config->setMetadataCacheImpl(new ArrayCache());
     $config->setAutoGenerateProxyClasses(true);
     $documentManager = \Doctrine\ODM\PHPCR\DocumentManager::create($session, $config);
     $this->productGateway = new ProductDoctrinePHPCRGateway($documentManager, 'Vespolina\\Entity\\Product\\Product');
     $this->taxonomyGateway = new TaxonomyPHPCRGateway($documentManager, 'Vespolina\\Entity\\Taxonomy\\TaxonomyNode', '/');
     $this->taxonomyRootNode = $documentManager->find(null, '/');
     parent::setUp();
 }
 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);
 }
 protected function getAnnotationDriver()
 {
     AnnotationRegistry::registerFile($this->app['path.base'] . '/vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php');
     $reader = new AnnotationReader();
     $driver = new AnnotationDriver($reader, [$this->app['path.base'] . '/app/']);
     $config = new \Doctrine\ODM\PHPCR\Configuration();
     $config->setMetadataDriverImpl($driver);
     $this->app->singleton('phpcr.manager', function () use($config) {
         return DocumentManager::create($this->app->make('phpcr.session'), $config);
     });
     return $driver;
 }
Пример #7
0
 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;
     };
 }
Пример #8
0
 public function setUp()
 {
     if (!class_exists('Jackalope\\Factory', true)) {
         $this->markTestSkipped('The Node needs to be properly mocked/stubbed. Remove dependency to Jackalope');
     }
     $this->factory = new Factory();
     $this->session = $this->getMock('Jackalope\\Session', array(), array($this->factory), '', false);
     $this->objectManager = $this->getMock('Jackalope\\ObjectManager', array(), array($this->factory), '', false);
     $this->type = 'Doctrine\\Tests\\ODM\\PHPCR\\UoWUser';
     $this->dm = DocumentManager::create($this->session);
     $this->uow = new UnitOfWork($this->dm);
     $cmf = $this->dm->getMetadataFactory();
     $metadata = $cmf->getMetadataFor($this->type);
     $metadata->mapField(array('fieldName' => 'id', 'id' => true));
     $metadata->mapField(array('fieldName' => 'username', 'type' => 'string'));
     $cmf->setMetadataFor($this->type, $metadata);
 }
Пример #9
0
 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));
 }
 public function testStringExtendedMapping()
 {
     $className = 'Doctrine\\Tests\\ODM\\PHPCR\\Mapping\\Model\\StringMappingObject';
     $this->loadMetadataForClassname($className);
     $className = 'Doctrine\\Tests\\ODM\\PHPCR\\Mapping\\Model\\StringExtendedMappingObject';
     $session = $this->getMock('PHPCR\\SessionInterface');
     $dm = \Doctrine\ODM\PHPCR\DocumentManager::create($session);
     $dm->getConfiguration()->setMetadataDriverImpl($this->loadDriver());
     $cmf = new ClassMetadataFactory($dm);
     $class = $cmf->getMetadataFor($className);
     $this->assertEquals('stringAssoc', $class->mappings['stringAssoc']['fieldName']);
     $this->assertEquals('string', $class->mappings['stringAssoc']['type']);
     $this->assertTrue($class->mappings['stringAssoc']['translated']);
     $this->assertTrue($class->mappings['stringAssoc']['multivalue']);
     $this->assertEquals('stringAssocKeys', $class->mappings['stringAssoc']['assoc']);
     $this->assertEquals('stringAssocNulls', $class->mappings['stringAssoc']['assocNulls']);
 }
Пример #11
0
 public function setUp()
 {
     $session = $this->getMock('PHPCR\\SessionInterface');
     $this->dm = \Doctrine\ODM\PHPCR\DocumentManager::create($session);
 }
Пример #12
0
 /**
  * @covers Doctrine\ODM\PHPCR\DocumentManager::createQueryBuilder
  */
 public function testCreateQueryBuilder()
 {
     $session = $this->getMock('PHPCR\\SessionInterface');
     $workspace = $this->getMock('PHPCR\\WorkspaceInterface');
     $queryManager = $this->getMock('PHPCR\\Query\\QueryManagerInterface');
     $qomf = $this->getMock('PHPCR\\Query\\QOM\\QueryObjectModelFactoryInterface');
     $baseQuery = $this->getMock('PHPCR\\Query\\QueryInterface');
     $session->expects($this->once())->method('getWorkspace')->will($this->returnValue($workspace));
     $workspace->expects($this->once())->method('getQueryManager')->will($this->returnValue($queryManager));
     $queryManager->expects($this->once())->method('getQOMFactory')->will($this->returnValue($qomf));
     $dm = DocumentManager::create($session);
     $qb = $dm->createQueryBuilder();
     $this->assertInstanceOf('Doctrine\\ODM\\PHPCR\\Query\\Builder\\QueryBuilder', $qb);
 }
 public function createDocumentManager(array $paths = null)
 {
     $reader = new AnnotationReader();
     $reader->addGlobalIgnoredName('group');
     if (empty($paths)) {
         $paths = array(__DIR__ . "/../../../Models");
     }
     $metaDriver = new PhpcrAnnotationDriver($reader, $paths);
     $factoryclass = isset($GLOBALS['DOCTRINE_PHPCR_FACTORY']) ? $GLOBALS['DOCTRINE_PHPCR_FACTORY'] : '\\Jackalope\\RepositoryFactoryJackrabbit';
     if ($factoryclass === '\\Jackalope\\RepositoryFactoryDoctrineDBAL') {
         $GLOBALS['jackalope.doctrine_dbal_connection'] = $this->connection;
     }
     /** @var $factory RepositoryFactoryInterface */
     $factory = new $factoryclass();
     $parameters = array_intersect_key($GLOBALS, $factory->getConfigurationKeys());
     // factory returns null if it gets unknown parameters
     $repository = $factory->getRepository($parameters);
     $this->assertNotNull($repository, 'There is an issue with your parameters: ' . var_export(array_keys($parameters), true));
     $workspace = isset($GLOBALS['DOCTRINE_PHPCR_WORKSPACE']) ? $GLOBALS['DOCTRINE_PHPCR_WORKSPACE'] : 'tests';
     $user = isset($GLOBALS['DOCTRINE_PHPCR_USER']) ? $GLOBALS['DOCTRINE_PHPCR_USER'] : '';
     $pass = isset($GLOBALS['DOCTRINE_PHPCR_PASS']) ? $GLOBALS['DOCTRINE_PHPCR_PASS'] : '';
     $credentials = new \PHPCR\SimpleCredentials($user, $pass);
     $session = $repository->login($credentials, $workspace);
     $this->sessions[] = $session;
     $config = new \Doctrine\ODM\PHPCR\Configuration();
     $config->setMetadataDriverImpl($metaDriver);
     $eventManager = new EventManager();
     $this->dm = DocumentManager::create($session, $config, $eventManager);
 }
Пример #14
0
/**
 * The config file is responsible to make class loading work and initialize a
 * DocumentManagerHelper that contains the doctrine document manager with a
 * Session of your phcpr implementation.
 * The array $extraCommands can be used to inject implementation specific commands.
 * Add instances of commands for eventual implementation specific commands to this array.
 */
$extraCommands = array();
$extraCommands[] = new \Jackalope\Tools\Console\Command\InitDoctrineDbalCommand();
$params = array('driver' => 'pdo_mysql', 'host' => 'localhost', 'user' => 'root', 'password' => '', 'dbname' => 'v_products_tests');
$dbConn = \Doctrine\DBAL\DriverManager::getConnection($params);
$workspace = 'default';
$user = '******';
$pass = '******';
/* only create a session if this is not about the server control command */
if (isset($argv[1]) && $argv[1] != 'jackalope:init:dbal' && $argv[1] != 'list' && $argv[1] != 'help') {
    $factory = new \Jackalope\RepositoryFactoryDoctrineDBAL();
    $repository = $factory->getRepository(array('jackalope.doctrine_dbal_connection' => $dbConn));
    $credentials = new \PHPCR\SimpleCredentials(null, null);
    $session = $repository->login($credentials, $workspace);
    /* prepare the doctrine configuration */
    $config = new \Doctrine\ODM\PHPCR\Configuration();
    $dm = \Doctrine\ODM\PHPCR\DocumentManager::create($session, $config);
    $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array('dm' => new \Doctrine\ODM\PHPCR\Tools\Console\Helper\DocumentManagerHelper(null, $dm)));
} else {
    if (isset($argv[1]) && $argv[1] == 'jackalope:init:dbal') {
        // special case: the init command needs the db connection, but a session is impossible if the db is not yet initialized
        $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array('connection' => new \Jackalope\Tools\Console\Helper\DoctrineDbalHelper($dbConn)));
    }
}