예제 #1
0
 public function testInvalidCharset()
 {
     $this->markTestSkipped('Skipped because of weird behavior on some platforms');
     $db = Propel::getServiceContainer()->getAdapter(BookPeer::DATABASE_NAME);
     if ($db instanceof SqliteAdapter) {
         $this->markTestSkipped();
     }
     $a = new Author();
     $a->setFirstName("Б.");
     $a->setLastName("АКУНИН");
     $a->save();
     $authorNameWindows1251 = iconv("utf-8", "windows-1251", $a->getLastName());
     $a->setLastName($authorNameWindows1251);
     // Different databases seem to handle invalid data differently (no surprise, I guess...)
     if ($db instanceof PgsqlAdapter) {
         try {
             $a->save();
             $this->fail("Expected an exception when saving non-UTF8 data to database.");
         } catch (Exception $x) {
             print $x;
         }
     } else {
         // No exception is thrown by MySQL ... (others need to be tested still)
         $a->save();
         $a->reload();
         $this->assertEquals("", $a->getLastName(), "Expected last_name to be empty (after inserting invalid charset data)");
     }
 }
예제 #2
0
 /**
  * {@inheritDoc}
  */
 public function register(Container $container)
 {
     // Append custom settings with missing params from default settings
     $container['settings']['database'] = self::mergeWithDefaultSettings($container['settings']['database']);
     $settings = $container['settings']['database'];
     $logLevel = $settings['logger']['level'] ?? null;
     $logPath = $settings['logger']['path'] ?? null;
     $className = $settings['classname'] ?? null;
     if (!$className) {
         $className = 'Propel\\Runtime\\Connection\\ConnectionWrapper';
         if ($logLevel == Logger::DEBUG) {
             $className = 'Propel\\Runtime\\Connection\\ProfilerConnectionWrapper';
         }
     }
     $manager = new ConnectionManagerSingle();
     $manager->setConfiguration(['classname' => $className, 'dsn' => $settings['dsn'], 'user' => $settings['user'], 'password' => $settings['password'], 'settings' => $settings['settings']]);
     $manager->setName($settings['connection']);
     /** @var StandardServiceContainer $serviceContainer */
     $serviceContainer = Propel::getServiceContainer();
     $serviceContainer->checkVersion($settings['version']);
     $serviceContainer->setAdapterClass($settings['connection'], $settings['adapter']);
     $serviceContainer->setConnectionManager($settings['connection'], $manager);
     $serviceContainer->setDefaultDatasource($settings['connection']);
     if ($logPath && $logLevel) {
         $logger = new Logger('defaultLogger');
         $logger->pushHandler(new StreamHandler($logPath, $logLevel));
         $serviceContainer->setLogger('defaultLogger', $logger);
         if ($logLevel == Logger::DEBUG) {
             /** @var ConnectionWrapper $con */
             $con = Propel::getConnection();
             $con->useDebug(true);
         }
     }
 }
예제 #3
0
 /**
  * @return \Propel\Runtime\Util\Profiler
  */
 public function getProfiler()
 {
     if (null === $this->profiler) {
         $this->profiler = Propel::getServiceContainer()->getProfiler();
     }
     return $this->profiler;
 }
예제 #4
0
파일: TestCase.php 프로젝트: naldz/cyberden
    protected function setUp()
    {
        parent::setUp();
        if (!class_exists('Propel\\Bundle\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\CoolBook')) {
            $schema = <<<XML
<database name="default" package="vendor.bundles.Propel.Bundle.PropelBundle.Tests.Fixtures.DataFixtures.Loader" namespace="Propel\\Bundle\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader" defaultIdMethod="native">
    <table name="cool_book">
        <column name="id" type="integer" primaryKey="true" />
        <column name="name" type="varchar" size="255" />
        <column name="description" type="varchar" />
        <column name="author_id" type="integer" required="false" defaultValue="null" />
        <column name="complementary_infos" required="false" type="object" description="An object column" />

        <foreign-key foreignTable="cool_book_author" onDelete="CASCADE" onUpdate="CASCADE">
            <reference local="author_id" foreign="id" />
        </foreign-key>
    </table>

    <table name="cool_book_author">
        <column name="id" type="integer" primaryKey="true" />
        <column name="name" type="varchar" size="255" />
    </table>
</database>
XML;
            QuickBuilder::buildSchema($schema);
        }
        $this->con = Propel::getServiceContainer()->getConnection('default');
        $this->con->beginTransaction();
    }
 public function testComputeWithSchema()
 {
     $con = Propel::getServiceContainer()->getConnection(BookstoreTableMap::DATABASE_NAME);
     BookstoreContestEntryQuery::create()->deleteAll();
     BookstoreQuery::create()->deleteAll();
     CustomerQuery::create()->deleteAll();
     BookstoreContestQuery::create()->deleteAll();
     $store = new Bookstore();
     $store->setStoreName('FreeAgent Bookstore');
     $store->save();
     $this->assertEquals(0, $store->computeTotalContestEntries($con), 'The compute method returns 0 for objects with no related objects');
     $contest = new BookstoreContest();
     $contest->setBookstore($store);
     $contest->save();
     $customer1 = new Customer();
     $customer1->save();
     $entry1 = new BookstoreContestEntry();
     $entry1->setBookstore($store);
     $entry1->setBookstoreContest($contest);
     $entry1->setCustomer($customer1);
     $entry1->save(null, true);
     // skip reload to avoid #1151 for now
     $this->assertEquals(1, $store->computeTotalContestEntries($con), 'The compute method computes the aggregate function on related objects');
     $customer2 = new Customer();
     $customer2->save();
     $entry2 = new BookstoreContestEntry();
     $entry2->setBookstore($store);
     $entry2->setBookstoreContest($contest);
     $entry2->setCustomer($customer2);
     $entry2->save(null, true);
     // skip reload to avoid #1151 for now
     $this->assertEquals(2, $store->computeTotalContestEntries($con), 'The compute method computes the aggregate function on related objects');
     $entry1->delete();
     $this->assertEquals(1, $store->computeTotalContestEntries($con), 'The compute method computes the aggregate function on related objects');
 }
예제 #6
0
파일: Update.php 프로젝트: alex63530/thelia
 public function process()
 {
     $logger = Tlog::getInstance();
     $logger->setLevel(Tlog::DEBUG);
     $updatedVersions = array();
     $currentVersion = ConfigQuery::read('thelia_version');
     $logger->debug("start update process");
     if (true === $this->isLatestVersion($currentVersion)) {
         $logger->debug("You already have the latest version. No update available");
         throw new UpToDateException('You already have the latest version. No update available');
     }
     $index = array_search($currentVersion, self::$version);
     $con = Propel::getServiceContainer()->getWriteConnection(ProductTableMap::DATABASE_NAME);
     $con->beginTransaction();
     $logger->debug("begin transaction");
     $database = new Database($con->getWrappedConnection());
     try {
         $size = count(self::$version);
         for ($i = ++$index; $i < $size; $i++) {
             $this->updateToVersion(self::$version[$i], $database, $logger);
             $updatedVersions[] = self::$version[$i];
         }
         $con->commit();
         $logger->debug('update successfully');
     } catch (PropelException $e) {
         $con->rollBack();
         $logger->error(sprintf('error during update process with message : %s', $e->getMessage()));
         throw $e;
     }
     $logger->debug('end of update processing');
     return $updatedVersions;
 }
예제 #7
0
 public function __construct(LoggerInterface $alternativeLogger = null)
 {
     $con = Propel::getServiceContainer()->getConnection(\Thelia\Model\Map\ProductTableMap::DATABASE_NAME);
     $con->setLogger($this);
     $con->setLogMethods(array('exec', 'query', 'execute', 'beginTransaction', 'commit', 'rollBack'));
     $this->alternativeLogger = $alternativeLogger;
 }
 /**
  * Register propel runtime configuration.
  *
  * @return void
  */
 protected function registerRuntimeConfiguration()
 {
     $propel_conf = $this->app->config['propel.propel'];
     if (!isset($propel_conf['runtime']['connections'])) {
         throw new \InvalidArgumentException('Unable to guess Propel runtime config file. Please, initialize the "propel.runtime" parameter.');
     }
     /** @var $serviceContainer \Propel\Runtime\ServiceContainer\StandardServiceContainer */
     $serviceContainer = Propel::getServiceContainer();
     $serviceContainer->closeConnections();
     $serviceContainer->checkVersion('2.0.0-dev');
     $runtime_conf = $propel_conf['runtime'];
     // set connections
     foreach ($runtime_conf['connections'] as $connection_name) {
         $config = $propel_conf['database']['connections'][$connection_name];
         $serviceContainer->setAdapterClass($connection_name, $config['adapter']);
         $manager = new ConnectionManagerSingle();
         $manager->setConfiguration($config + [$propel_conf['paths']]);
         $manager->setName($connection_name);
         $serviceContainer->setConnectionManager($connection_name, $manager);
     }
     $serviceContainer->setDefaultDatasource($runtime_conf['defaultConnection']);
     // set loggers
     $has_default_logger = false;
     if (isset($runtime_conf['log'])) {
         $has_default_logger = array_key_exists('defaultLogger', $runtime_conf['log']);
         foreach ($runtime_conf['log'] as $logger_name => $logger_conf) {
             $serviceContainer->setLoggerConfiguration($logger_name, $logger_conf);
         }
     }
     if (!$has_default_logger) {
         $serviceContainer->setLogger('defaultLogger', \Log::getMonolog());
     }
     Propel::setServiceContainer($serviceContainer);
 }
예제 #9
0
 public function process(ContainerBuilder $container)
 {
     if (!$container->hasDefinition('event_dispatcher')) {
         return;
     }
     $definition = $container->getDefinition('event_dispatcher');
     foreach ($container->findTaggedServiceIds('kernel.event_listener') as $id => $events) {
         foreach ($events as $event) {
             $priority = isset($event['priority']) ? $event['priority'] : 0;
             if (!isset($event['event'])) {
                 throw new \InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "kernel.event_listener" tags.', $id));
             }
             if (!isset($event['method'])) {
                 $event['method'] = 'on' . preg_replace_callback(array('/(?<=\\b)[a-z]/i', '/[^a-z0-9]/i'), function ($matches) {
                     return strtoupper($matches[0]);
                 }, $event['event']);
                 $event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']);
             }
             $definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority));
         }
     }
     foreach ($container->findTaggedServiceIds('kernel.event_subscriber') as $id => $attributes) {
         // We must assume that the class value has been correctly filled, even if the service is created by a factory
         $class = $container->getDefinition($id)->getClass();
         $refClass = new \ReflectionClass($class);
         $interface = 'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface';
         if (!$refClass->implementsInterface($interface)) {
             throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
         }
         $definition->addMethodCall('addSubscriberService', array($id, $class));
     }
     // We have to check if Propel is initialized before registering hooks
     $managers = Propel::getServiceContainer()->getConnectionManagers();
     if (!array_key_exists('thelia', $managers)) {
         return;
     }
     foreach ($container->findTaggedServiceIds('hook.event_listener') as $id => $events) {
         $class = $container->getDefinition($id)->getClass();
         // the class must extends BaseHook
         $implementClass = HookDefinition::BASE_CLASS;
         if (!is_subclass_of($class, $implementClass)) {
             throw new \InvalidArgumentException(sprintf('Hook class "%s" must extends class "%s".', $class, $implementClass));
         }
         // retrieve the module id
         $properties = $container->getDefinition($id)->getProperties();
         $module = null;
         if (array_key_exists('module', $properties)) {
             $moduleCode = explode(".", $properties['module'])[1];
             if (null !== ($module = ModuleQuery::create()->findOneByCode($moduleCode))) {
                 $module = $module->getId();
             }
         }
         foreach ($events as $event) {
             $this->registerHook($class, $module, $id, $event);
         }
     }
     // now we can add listeners for active hooks and active module
     $this->addHooksMethodCall($definition);
 }
예제 #10
0
 public function orderByRelevance()
 {
     if (!$this->full_text) {
         return $this;
     }
     $against = Propel::getServiceContainer()->getReadConnection($this->getDbName())->quote($this->fulltext_text);
     return $this->withColumn('match (title) against (' . $against . ')', 's1')->withColumn('match(description) against (' . $against . ')', 's2')->addDescendingOrderByColumn("(s1*2)+s2");
 }
예제 #11
0
 public function testSetServiceContainerOverridesTheExistingServiceContainer()
 {
     $oldSC = Propel::getServiceContainer();
     $newSC = new StandardServiceContainer();
     Propel::setServiceContainer($newSC);
     $this->assertSame($newSC, Propel::getServiceContainer());
     Propel::setServiceContainer($oldSC);
 }
예제 #12
0
 public function __construct()
 {
     $this->db = new JaCategoriasQuery();
     $this->helper = new Helper();
     $base = $this->helper->baseApi();
     $defaultLogger = new Logger('categorias');
     $defaultLogger->pushHandler(new StreamHandler($base . '/logs/api.log', Logger::WARNING));
     Propel::getServiceContainer()->setLogger('categorias', $defaultLogger);
 }
예제 #13
0
 public static function init($manager, $namespace)
 {
     $workingDirectory = $manager->getWorkingDirectory();
     $paths = explode(DIRECTORY_SEPARATOR, $workingDirectory);
     $modulePaths = array();
     $found = false;
     foreach ($paths as $path) {
         if ($found == false) {
             $modulePaths[] = $path;
         }
         if ($path == $namespace) {
             $found = true;
         }
     }
     $moduleConfigPath = implode(DIRECTORY_SEPARATOR, $modulePaths);
     $moduleConfig = (include $moduleConfigPath . '/config/module.config.php');
     $appConfigPath = self::findAppConfig($moduleConfigPath);
     $applicationConfig = (include $appConfigPath . '/config/application.config.php');
     $zf2ModulePaths = array();
     if (isset($applicationConfig['module_listener_options']['module_paths'])) {
         $modulePaths = $applicationConfig['module_listener_options']['module_paths'];
         foreach ($modulePaths as $modulePath) {
             if ($path = static::findParentPath($modulePath)) {
                 $zf2ModulePaths[] = $path;
             }
         }
     }
     if (isset($applicationConfig['module_listener_options']['config_glob_paths'])) {
         $globConfigs = $applicationConfig['module_listener_options']['config_glob_paths'];
         foreach ($globConfigs as $globConfig) {
             $localConfig = (include $appConfigPath . '/config/autoload/local.php');
             $globalConfig = (include $appConfigPath . '/config/autoload/global.php');
         }
     }
     $zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR;
     static::initAutoloader();
     $baseConfig = array('module_listener_options' => array('module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths)));
     $config = ArrayUtils::merge($moduleConfig, $applicationConfig);
     $config = ArrayUtils::merge($config, $baseConfig);
     $config = ArrayUtils::merge($config, $localConfig);
     $config = ArrayUtils::merge($config, $globalConfig);
     $serviceManager = new ServiceManager(new ServiceManagerConfig());
     $serviceManager->setService('ApplicationConfig', $config);
     $serviceManager->get('ModuleManager')->loadModules();
     static::$serviceManager = $serviceManager;
     static::$config = $config;
     $serviceContainer = Propel::getServiceContainer();
     $connectionName = array_keys($moduleConfig['propel']['database']['connections']);
     $connectionName = array_shift($connectionName);
     $connectionName = $connectionName;
     $propelConfig = $config['propel'];
     list($dsn, $dbUser, $dbPass) = static::generateDsn($connectionName, $propelConfig['database']['connections']);
     $serviceContainer->setAdapterClass($connectionName, 'mysql');
     $manager = new ConnectionManagerSingle();
     $manager->setConfiguration(array('dsn' => $dsn, 'user' => $dbUser, 'password' => $dbPass));
     $serviceContainer->setConnectionManager($connectionName, $manager);
 }
예제 #14
0
 public function testFormatOneWithOneRowAndValueEqualsZero()
 {
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     $stmt = $con->query('SELECT 0 FROM book LIMIT 0, 1');
     $formatter = new SimpleArrayFormatter();
     $formatter->init(new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book'));
     $book = $formatter->formatOne($stmt);
     $this->assertSame('0', $book);
 }
 public function setUp()
 {
     $container = \Propel\Runtime\Propel::getServiceContainer();
     $container->setAdapterClass('finite-test', 'sqlite');
     $connectionManager = new \Propel\Runtime\Connection\ConnectionManagerSingle();
     $connectionManager->setConfiguration(['dsn' => '/tmp/test.db', 'classname' => '\\Propel\\Runtime\\Connection\\ConnectionWrapper']);
     $connectionManager->setName('finite-test');
     $container->setConnectionManager('finite-test', $connectionManager);
 }
 protected function initPropel()
 {
     $serviceContainer = Propel::getServiceContainer();
     $serviceContainer->setAdapterClass($this->config["dbname"], $this->config["engine"]);
     $manager = new ConnectionManagerSingle();
     $port = empty($this->config["port"]) ? "" : ";port=" . $this->config["port"];
     $manager->setConfiguration(array("dsn" => $this->config["engine"] . ":host=" . $this->config["host"] . ";dbname=" . $this->config["dbname"] . $port, "user" => $this->config["user"], "password" => $this->config["password"]));
     $serviceContainer->setConnectionManager($this->config["dbname"], $manager);
     $this->alreadyInit = true;
 }
예제 #17
0
 public static function setupPropel()
 {
     if (!self::$isPropelSetUp) {
         $dbConfig = self::getDbConfig();
         $manager = self::setPropelManager($dbConfig);
         $serviceContainer = Propel::getServiceContainer();
         self::setPropelServiceContainer($serviceContainer, $dbConfig, $manager);
         self::$isPropelSetUp = true;
     }
 }
 public function testRegisterWithDefaults()
 {
     $current = getcwd();
     chdir(__DIR__ . '/../../../Fixtures/FixtFull');
     $app = new Application();
     $app->register(new PropelServiceProvider());
     $app->boot();
     $this->assertEquals(Propel::getServiceContainer()->getDefaultDatasource(), 'bookstore');
     chdir($current);
 }
 public function doTestReplaceNames($c, $tableMap, $origClause, $columnPhpName = false, $modifiedClause)
 {
     $this->adapterClass = Propel::getServiceContainer()->getAdapterClass(BookstoreContestTableMap::DATABASE_NAME);
     $c->replaceNames($origClause);
     $columns = $c->replacedColumns;
     if ($columnPhpName) {
         $this->assertEquals(array($tableMap->getColumnByPhpName($columnPhpName)), $columns);
     }
     $modifiedClause = preg_replace('/^(\\(?)contest\\./', '$1contest' . $this->getPlatform()->getSchemaDelimiter(), $modifiedClause);
     $this->assertEquals($modifiedClause, $origClause);
 }
예제 #20
0
 protected function __construct()
 {
     $this->adapter = Config::get('db.adapter');
     $this->host = Config::get('db.host');
     $this->database = Config::get('db.name');
     $this->manager = new ConnectionManagerSingle();
     $this->manager->setConfiguration($this->defaultConfig());
     $this->serviceContainer = Propel::getServiceContainer();
     $this->serviceContainer->setAdapterClass($this->database, $this->adapter);
     $this->serviceContainer->setConnectionManager($this->database, $this->manager);
 }
예제 #21
0
 /**
  * initialize propel orm and import  it's configs
  */
 public static function init()
 {
     $serviceContainer = \Propel\Runtime\Propel::getServiceContainer();
     $serviceContainer->checkVersion('2.0.0-dev');
     $serviceContainer->setAdapterClass('cocofile', 'mysql');
     $manager = new \Propel\Runtime\Connection\ConnectionManagerSingle();
     $manager->setConfiguration(array('dsn' => sprintf('mysql:host=%s;dbname=%s', Config::get('database.yaml@database_host'), Config::get('database.yaml@database_name')), 'user' => Config::get('database.yaml@database_username'), 'password' => Config::get('database.yaml@database_password'), 'attributes' => array('ATTR_EMULATE_PREPARES' => false), 'settings' => array('charset' => 'utf8', 'queries' => array('utf8' => 'SET NAMES utf8 COLLATE utf8_unicode_ci, COLLATION_CONNECTION = utf8_unicode_ci, COLLATION_DATABASE = utf8_unicode_ci, COLLATION_SERVER = utf8_unicode_ci')), 'classname' => '\\Propel\\Runtime\\Connection\\ConnectionWrapper'));
     $manager->setName('cocofile');
     $serviceContainer->setConnectionManager('cocofile', $manager);
     $serviceContainer->setDefaultDatasource('cocofile');
 }
예제 #22
0
 protected function configureLogging()
 {
     $serviceContainer = Propel::getServiceContainer();
     $serviceContainer->setLogger('defaultLogger', $this->container->get('propel.logger'));
     foreach ($serviceContainer->getConnectionManagers() as $manager) {
         $connection = $manager->getReadConnection($serviceContainer->getAdapter($manager->getName()));
         $connection->setLogMethods(array_merge($connection->getLogMethods(), array('prepare')));
         $connection = $manager->getWriteConnection();
         $connection->setLogMethods(array_merge($connection->getLogMethods(), array('prepare')));
     }
 }
예제 #23
0
 public function testDoInsert()
 {
     try {
         $c = new Criteria();
         $c->setPrimaryTableName(BookPeer::TABLE_NAME);
         $c->add(BookPeer::AUTHOR_ID, 'lkhlkhj');
         BasePeer::doInsert($c, Propel::getServiceContainer()->getWriteConnection(BookPeer::DATABASE_NAME));
     } catch (RuntimeException $e) {
         $this->assertContains('[INSERT INTO `book` (`AUTHOR_ID`) VALUES (:p1)]', $e->getMessage(), 'SQL query is written in the exception message');
     }
 }
예제 #24
0
 public function testDoInsert()
 {
     try {
         $c = new Criteria();
         $c->setPrimaryTableName(BookTableMap::TABLE_NAME);
         $c->add(BookTableMap::AUTHOR_ID, 'lkhlkhj');
         $c->doInsert(Propel::getServiceContainer()->getWriteConnection(BookTableMap::DATABASE_NAME));
         $this->fail('Missing expected exception on BAD SQL');
     } catch (PropelException $e) {
         $this->assertContains('[INSERT INTO `book` (`AUTHOR_ID`) VALUES (:p1)]', $e->getMessage(), 'SQL query is written in the exception message');
     }
 }
예제 #25
0
 public static function init($config)
 {
     // Autogenerated with `propel config:convert` code
     $serviceContainer = \Propel\Runtime\Propel::getServiceContainer();
     $serviceContainer->checkVersion('2.0.0-dev');
     $serviceContainer->setAdapterClass('engine', $config['type']);
     $manager = new \Propel\Runtime\Connection\ConnectionManagerSingle();
     $manager->setConfiguration(['dsn' => $config['type'] . ':host=' . $config['host'] . ';' . 'dbname=' . $config['name'] . ';charset=' . $config['charset'], 'user' => $config['user'], 'password' => $config['password']]);
     $manager->setName('engine');
     $serviceContainer->setConnectionManager('engine', $manager);
     $serviceContainer->setDefaultDatasource('engine');
 }
예제 #26
0
 public function testCreateSelectSqlPart()
 {
     Propel::getServiceContainer()->setAdapter('oracle', new OracleAdapter());
     $db = Propel::getServiceContainer()->getAdapter();
     $c = new Criteria();
     $c->addSelectColumn(BookTableMap::COL_ID);
     $c->addAsColumn('book_ID', BookTableMap::COL_ID);
     $fromClause = [];
     $selectSql = $db->createSelectSqlPart($c, $fromClause);
     $this->assertEquals('SELECT book.id, book.id AS book_ID', $selectSql, 'createSelectSqlPart() returns a SQL SELECT clause with both select and as columns');
     $this->assertEquals(['book'], $fromClause, 'createSelectSqlPart() adds the tables from the select columns to the from clause');
 }
 public function testFormat()
 {
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     BookstoreEmployeeTableMap::clearInstancePool();
     $stmt = $con->query('SELECT id, class_key, name, job_title, supervisor_id, photo FROM bookstore_employee');
     $formatter = new ObjectFormatter();
     $formatter->init(new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\BookstoreEmployee'));
     $emps = $formatter->format($stmt);
     $expectedClass = ['b1' => 'Propel\\Tests\\Bookstore\\BookstoreEmployee', 'b2' => 'Propel\\Tests\\Bookstore\\BookstoreManager', 'b3' => 'Propel\\Tests\\Bookstore\\BookstoreCashier'];
     foreach ($emps as $emp) {
         $this->assertEquals($expectedClass[$emp->getName()], get_class($emp), 'format() creates objects of the correct class when using inheritance');
     }
 }
예제 #28
0
 public function __construct(EventDispatcherInterface $dispatcher, Db $t1db)
 {
     $this->dispatcher = $dispatcher;
     $this->t1db = $t1db;
     $this->t1db->connect();
     $hdl = $this->t1db->query("select valeur from variable where nom = 'version'");
     $version = $this->t1db->fetch_column($hdl);
     $this->thelia_version = intval(substr($version, 0, 3));
     $serviceContainer = Propel::getServiceContainer();
     $serviceContainer->setLogger('defaultLogger', Tlog::getInstance());
     $con = Propel::getConnection(ProductTableMap::DATABASE_NAME);
     $con->useDebug(true);
 }
예제 #29
0
 public function testParse()
 {
     $parser = new MysqlSchemaParser(Propel::getServiceContainer()->getConnection('reverse-bookstore'));
     $parser->setGeneratorConfig(new QuickGeneratorConfig());
     $database = new Database();
     $database->setPlatform(new DefaultPlatform());
     $this->assertEquals(1, $parser->parse($database), 'One table and one view defined should return one as we exclude views');
     $tables = $database->getTables();
     $this->assertEquals(1, count($tables));
     $table = $tables[0];
     $this->assertEquals('Book', $table->getPhpName());
     $this->assertEquals(4, count($table->getColumns()));
 }
 public function testLazyLoadedColumnsWithDefaultRequireAnAdditionalQueryOnGetter()
 {
     $con = Propel::getServiceContainer()->getConnection(\Map\LazyLoadActiveRecordTableMap::DATABASE_NAME);
     $con->useDebug(true);
     $obj = new \LazyLoadActiveRecord();
     $obj->setBaz('hello');
     $obj->save($con);
     \Map\LazyLoadActiveRecordTableMap::clearInstancePool();
     $obj2 = \LazyLoadActiveRecordQuery::create()->findPk($obj->getId(), $con);
     $count = $con->getQueryCount();
     $this->assertEquals('hello', $obj2->getBaz($con));
     $this->assertEquals($count + 1, $con->getQueryCount());
 }