Permalink
Browse files

[Generator] [NestedSet] Refactor tests to avoid fatal errors

  • Loading branch information...
willdurand committed Jan 13, 2013
1 parent e6a52e1 commit 8c086c6188a9f0b84c6368bef2c46c2d0dc4d608
@@ -92,8 +92,13 @@ public function useScope()
return 'true' === $this->getParameter('use_scope');
}
- public function getColumnConstant($columnName, $builder)
+ public function getColumnConstant($columnName)
{
- return $builder->getColumnConstant($this->getColumnForParameter($columnName));
+ return $this->getColumn($columnName)->getName();
+ }
+
+ public function getColumn($columnName)
+ {
+ return $this->getColumnForParameter($columnName);
}
}
@@ -1005,7 +1005,7 @@ public function addChild($objectClassName \$child)
protected function addInsertAsFirstChildOf(&$script)
{
$objectClassName = $this->builder->getObjectClassName();
- $queryClassName = $this->builder->getQueryClassName();
+ $queryClassName = $this->builder->getQueryClassName(true);
$useScope = $this->behavior->useScope();
$script .= "
@@ -1054,15 +1054,15 @@ protected function addInsertAsLastChildOf()
{
return $this->behavior->renderTemplate('objectInsertAsLastChildOf', array(
'objectClassName' => $this->builder->getObjectClassName(),
- 'queryClassName' => $this->builder->getQueryClassName(),
+ 'queryClassName' => $this->builder->getQueryClassName(true),
'useScope' => $this->behavior->useScope(),
));
}
protected function addInsertAsPrevSiblingOf(&$script)
{
$objectClassName = $this->builder->getObjectClassName();
- $queryClassName = $this->builder->getQueryClassName();
+ $queryClassName = $this->builder->getQueryClassName(true);
$useScope = $this->behavior->useScope();
$script .= "
@@ -1105,7 +1105,7 @@ public function insertAsPrevSiblingOf(\$sibling)
protected function addInsertAsNextSiblingOf(&$script)
{
$objectClassName = $this->builder->getObjectClassName();
- $queryClassName = $this->builder->getQueryClassName();
+ $queryClassName = $this->builder->getQueryClassName(true);
$useScope = $this->behavior->useScope();
$script .= "
@@ -1373,6 +1373,7 @@ protected function addDeleteDescendants(&$script)
{
$objectClassName = $this->builder->getObjectClassName();
$queryClassName = $this->builder->getQueryClassName();
+ $tableMapClass = $this->builder->getTableMapClass();
$useScope = $this->behavior->useScope();
$script .= "
@@ -1392,7 +1393,7 @@ public function deleteDescendants(ConnectionInterface \$con = null)
return;
}
if (null === \$con) {
- \$con = Propel::getServiceContainer()->getReadConnection($queryClassName::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getReadConnection($tableMapClass::DATABASE_NAME);
}
\$left = \$this->getLeftValue();
\$right = \$this->getRightValue();";
@@ -1452,25 +1453,25 @@ public function objectAttributes($builder)
/**
* Left column for the set
*/
-const LEFT_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('left_column', $builder) . "';
+const LEFT_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('left_column') . "';
/**
* Right column for the set
*/
-const RIGHT_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('right_column', $builder) . "';
+const RIGHT_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('right_column') . "';
/**
* Level column for the set
*/
-const LEVEL_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('level_column', $builder) . "';
+const LEVEL_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('level_column') . "';
";
if ($this->behavior->useScope()) {
$script .= "
/**
* Scope column for the set
*/
-const SCOPE_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('scope_column', $builder) . "';
+const SCOPE_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('scope_column') . "';
";
}
@@ -45,10 +45,10 @@ protected function getColumn($name)
protected function setBuilder($builder)
{
- $this->builder = $builder;
- $this->objectClassName = $builder->getObjectClassName();
- $this->queryClassName = $builder->getQueryClassName();
- $this->peerClassName = $builder->getPeerClassName();
+ $this->builder = $builder;
+ $this->objectClassName = $builder->getObjectClassName();
+ $this->queryClassName = $builder->getQueryClassName();
+ $this->peerClassName = $builder->getPeerClassName();
}
public function queryMethods($builder)
@@ -405,8 +405,9 @@ public function findTree(" . ($useScope ? "\$scope = null, " : "") . "\$con = nu
protected function addRetrieveRoots(&$script)
{
- $peerClassName = $this->peerClassName;
+ $peerClassName = $this->peerClassName;
$objectClassName = $this->objectClassName;
+ $tableMapClass = $this->builder->getTableMapClass();
$script .= "
/**
@@ -418,7 +419,7 @@ protected function addRetrieveRoots(&$script)
static public function retrieveRoots(Criteria \$criteria = null, ConnectionInterface \$con = null)
{
if (null === \$criteria) {
- \$criteria = new Criteria($peerClassName::DATABASE_NAME);
+ \$criteria = new Criteria($tableMapClass::DATABASE_NAME);
}
\$criteria->add($objectClassName::LEFT_COL, 1, Criteria::EQUAL);
@@ -429,9 +430,10 @@ static public function retrieveRoots(Criteria \$criteria = null, ConnectionInter
protected function addRetrieveRoot(&$script)
{
- $peerClassName = $this->peerClassName;
+ $peerClassName = $this->peerClassName;
$objectClassName = $this->objectClassName;
- $useScope = $this->behavior->useScope();
+ $useScope = $this->behavior->useScope();
+ $tableMapClass = $this->builder->getTableMapClass();
$script .= "
/**
@@ -447,7 +449,7 @@ protected function addRetrieveRoot(&$script)
*/
static public function retrieveRoot(" . ($useScope ? "\$scope = null, " : "") . "ConnectionInterface \$con = null)
{
- \$c = new Criteria($peerClassName::DATABASE_NAME);
+ \$c = new Criteria($tableMapClass::DATABASE_NAME);
\$c->add($objectClassName::LEFT_COL, 1, Criteria::EQUAL);";
if ($useScope) {
$script .= "
@@ -462,9 +464,10 @@ static public function retrieveRoot(" . ($useScope ? "\$scope = null, " : "") .
protected function addRetrieveTree(&$script)
{
- $peerClassName = $this->peerClassName;
+ $peerClassName = $this->peerClassName;
$objectClassName = $this->objectClassName;
- $useScope = $this->behavior->useScope();
+ $useScope = $this->behavior->useScope();
+ $tableMapClass = $this->builder->getTableMapClass();
$script .= "
/**
@@ -482,7 +485,7 @@ protected function addRetrieveTree(&$script)
static public function retrieveTree(" . ($useScope ? "\$scope = null, " : "") . "Criteria \$criteria = null, ConnectionInterface \$con = null)
{
if (null === \$criteria) {
- \$criteria = new Criteria($peerClassName::DATABASE_NAME);
+ \$criteria = new Criteria($tableMapClass::DATABASE_NAME);
}
\$criteria->addAscendingOrderByColumn($objectClassName::LEFT_COL);";
if ($useScope) {
@@ -520,9 +523,10 @@ static public function isValid($objectClassName \$node = null)
protected function addDeleteTree(&$script)
{
- $peerClassName = $this->peerClassName;
+ $peerClassName = $this->peerClassName;
$objectClassName = $this->objectClassName;
- $useScope = $this->behavior->useScope();
+ $useScope = $this->behavior->useScope();
+ $tableMapClass = $this->builder->getTableMapClass();
$script .= "
/**
@@ -541,7 +545,7 @@ static public function deleteTree(" . ($useScope ? "\$scope = null, " : "") . "C
{";
if ($useScope) {
$script .= "
- \$c = new Criteria($peerClassName::DATABASE_NAME);
+ \$c = new Criteria($tableMapClass::DATABASE_NAME);
\$c->add($objectClassName::SCOPE_COL, \$scope, Criteria::EQUAL);
return $peerClassName::doDelete(\$c, \$con);";
@@ -557,33 +561,36 @@ static public function deleteTree(" . ($useScope ? "\$scope = null, " : "") . "C
protected function addShiftRLValues(&$script)
{
- $peerClassName = $this->peerClassName;
+ $peerClassName = $this->peerClassName;
$objectClassName = $this->objectClassName;
- $useScope = $this->behavior->useScope();
+ $useScope = $this->behavior->useScope();
+ $tableMapClass = $this->builder->getTableMapClass();
+
+ $this->builder->declareClass('Propel\Runtime\Util\BasePeer');
$script .= "
/**
* Adds \$delta to all L and R values that are >= \$first and <= \$last.
* '\$delta' can also be negative.
*
- * @param int \$delta Value to be shifted by, can be negative
- * @param int \$first First node to be shifted
- * @param int \$last Last node to be shifted (optional)";
+ * @param int \$delta Value to be shifted by, can be negative
+ * @param int \$first First node to be shifted
+ * @param int \$last Last node to be shifted (optional)";
if ($useScope) {
$script .= "
- * @param int \$scope Scope to use for the shift";
+ * @param int \$scope Scope to use for the shift";
}
$script .= "
- * @param ConnectionInterface \$con Connection to use.
+ * @param ConnectionInterface \$con Connection to use.
*/
static public function shiftRLValues(\$delta, \$first, \$last = null" . ($useScope ? ", \$scope = null" : ""). ", ConnectionInterface \$con = null)
{
if (\$con === null) {
- \$con = Propel::getServiceContainer()->getWriteConnection($peerClassName::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getWriteConnection($tableMapClass::DATABASE_NAME);
}
// Shift left column values
- \$whereCriteria = new Criteria($peerClassName::DATABASE_NAME);
+ \$whereCriteria = new Criteria($tableMapClass::DATABASE_NAME);
\$criterion = \$whereCriteria->getNewCriterion($objectClassName::LEFT_COL, \$first, Criteria::GREATER_EQUAL);
if (null !== \$last) {
\$criterion->addAnd(\$whereCriteria->getNewCriterion($objectClassName::LEFT_COL, \$last, Criteria::LESS_EQUAL));
@@ -595,13 +602,13 @@ static public function shiftRLValues(\$delta, \$first, \$last = null" . ($useSco
}
$script .= "
- \$valuesCriteria = new Criteria($peerClassName::DATABASE_NAME);
+ \$valuesCriteria = new Criteria($tableMapClass::DATABASE_NAME);
\$valuesCriteria->add($objectClassName::LEFT_COL, array('raw' => $objectClassName::LEFT_COL . ' + ?', 'value' => \$delta), Criteria::CUSTOM_EQUAL);
BasePeer::doUpdate(\$whereCriteria, \$valuesCriteria, \$con);
// Shift right column values
- \$whereCriteria = new Criteria($peerClassName::DATABASE_NAME);
+ \$whereCriteria = new Criteria($tableMapClass::DATABASE_NAME);
\$criterion = \$whereCriteria->getNewCriterion($objectClassName::RIGHT_COL, \$first, Criteria::GREATER_EQUAL);
if (null !== \$last) {
\$criterion->addAnd(\$whereCriteria->getNewCriterion($objectClassName::RIGHT_COL, \$last, Criteria::LESS_EQUAL));
@@ -613,7 +620,7 @@ static public function shiftRLValues(\$delta, \$first, \$last = null" . ($useSco
}
$script .= "
- \$valuesCriteria = new Criteria($peerClassName::DATABASE_NAME);
+ \$valuesCriteria = new Criteria($tableMapClass::DATABASE_NAME);
\$valuesCriteria->add($objectClassName::RIGHT_COL, array('raw' => $objectClassName::RIGHT_COL . ' + ?', 'value' => \$delta), Criteria::CUSTOM_EQUAL);
BasePeer::doUpdate(\$whereCriteria, \$valuesCriteria, \$con);
@@ -623,9 +630,12 @@ static public function shiftRLValues(\$delta, \$first, \$last = null" . ($useSco
protected function addShiftLevel(&$script)
{
- $peerClassName = $this->peerClassName;
+ $peerClassName = $this->peerClassName;
$objectClassName = $this->objectClassName;
- $useScope = $this->behavior->useScope();
+ $useScope = $this->behavior->useScope();
+ $tableMapClass = $this->builder->getTableMapClass();
+
+ $this->builder->declareClass('Propel\Runtime\Util\BasePeer');
$script .= "
/**
@@ -645,10 +655,10 @@ protected function addShiftLevel(&$script)
static public function shiftLevel(\$delta, \$first, \$last" . ($useScope ? ", \$scope = null" : ""). ", ConnectionInterface \$con = null)
{
if (\$con === null) {
- \$con = Propel::getServiceContainer()->getWriteConnection($peerClassName::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getWriteConnection($tableMapClass::DATABASE_NAME);
}
- \$whereCriteria = new Criteria($peerClassName::DATABASE_NAME);
+ \$whereCriteria = new Criteria($tableMapClass::DATABASE_NAME);
\$whereCriteria->add($objectClassName::LEFT_COL, \$first, Criteria::GREATER_EQUAL);
\$whereCriteria->add($objectClassName::RIGHT_COL, \$last, Criteria::LESS_EQUAL);";
if ($useScope) {
@@ -657,7 +667,7 @@ static public function shiftLevel(\$delta, \$first, \$last" . ($useScope ? ", \$
}
$script .= "
- \$valuesCriteria = new Criteria($peerClassName::DATABASE_NAME);
+ \$valuesCriteria = new Criteria($tableMapClass::DATABASE_NAME);
\$valuesCriteria->add($objectClassName::LEVEL_COL, array('raw' => $objectClassName::LEVEL_COL . ' + ?', 'value' => \$delta), Criteria::CUSTOM_EQUAL);
BasePeer::doUpdate(\$whereCriteria, \$valuesCriteria, \$con);
@@ -669,6 +679,7 @@ protected function addUpdateLoadedNodes(&$script)
{
$peerClassName = $this->peerClassName;
$objectClassName = $this->objectClassName;
+ $tableMapClass = $this->builder->getTableMapClass();
$script .= "
/**
@@ -690,7 +701,7 @@ static public function updateLoadedNodes(\$prune = null, ConnectionInterface \$c
if (!empty(\$keys)) {
// We don't need to alter the object instance pool; we're just modifying these ones
// already in the pool.
- \$criteria = new Criteria($peerClassName::DATABASE_NAME);";
+ \$criteria = new Criteria($tableMapClass::DATABASE_NAME);";
if (1 === count($this->table->getPrimaryKey())) {
$pkey = $this->table->getPrimaryKey();
$col = array_shift($pkey);
@@ -758,8 +769,10 @@ static public function updateLoadedNodes(\$prune = null, ConnectionInterface \$c
protected function addMakeRoomForLeaf(&$script)
{
- $peerClassName = $this->peerClassName;
- $useScope = $this->behavior->useScope();
+ $peerClassName = $this->peerClassName;
+ $queryClassName = $this->queryClassName;
+ $useScope = $this->behavior->useScope();
+
$script .= "
/**
* Update the tree to allow insertion of a leaf at the specified position
@@ -776,10 +789,10 @@ protected function addMakeRoomForLeaf(&$script)
static public function makeRoomForLeaf(\$left" . ($useScope ? ", \$scope" : ""). ", \$prune = null, ConnectionInterface \$con = null)
{
// Update database nodes
- $peerClassName::shiftRLValues(2, \$left, null" . ($useScope ? ", \$scope" : "") . ", \$con);
+ $queryClassName::shiftRLValues(2, \$left, null" . ($useScope ? ", \$scope" : "") . ", \$con);
// Update all loaded nodes
- $peerClassName::updateLoadedNodes(\$prune, \$con);
+ $queryClassName::updateLoadedNodes(\$prune, \$con);
}
";
}
@@ -24,8 +24,8 @@ public function insertAsLastChildOf($parent)
<?php if ($useScope) : ?>
$scope = $parent->getScopeValue();
$this->setScopeValue($scope);
-<?php endif; ?>
+<?php endif; ?>
// update the children collection of the parent
$parent->addNestedSetChild($this);
@@ -0,0 +1,9 @@
+<?php
+
+namespace Propel\Tests\Generator\Behavior\NestedSet\Fixtures;
+
+class PublicTable10 extends \NestedSetTable10
+{
+ public $hasParentNode = null;
+ public $parentNode = null;
+}
@@ -0,0 +1,13 @@
+<?php
+
+namespace Propel\Tests\Generator\Behavior\NestedSet\Fixtures;
+
+class PublicTable9 extends \NestedSetTable9
+{
+ public $hasParentNode = null;
+ public $parentNode = null;
+ public $hasPrevSibling = null;
+ public $prevSibling = null;
+ public $hasNextSibling = null;
+ public $nextSibling = null;
+}
Oops, something went wrong.

0 comments on commit 8c086c6

Please sign in to comment.