Permalink
Browse files

Update tests to pass minor fix for obtainCollectionVersion, #16

  • Loading branch information...
1 parent 19d14b9 commit de6ac08f2bc1713c1ad215a73ec5cd7ee66c1e13 @fruit committed Feb 5, 2012
@@ -19,6 +19,11 @@
class Doctrine_Template_Cachetaggable extends Doctrine_Template
{
/**
+ * The default version value for records which were never saved before
+ */
+ const UNSAVED_RECORD_DEFAULT_VERSION = '1';
+
+ /**
* Array of Sortable options
*
* @var string
@@ -90,7 +95,10 @@ public function setTableDefinition ()
$this->getOption('versionColumn'),
'string',
10 + sfCacheTaggingToolkit::getPrecision(),
- array('notnull' => false, 'default' => 1)
+ array(
+ 'notnull' => false,
+ 'default' => self::UNSAVED_RECORD_DEFAULT_VERSION
+ )
);
$this->addListener(
@@ -149,7 +157,7 @@ public function getCacheTags ($deep = true)
{
continue;
}
-
+
if ($reference instanceof Doctrine_Record && ! $reference->exists())
{
continue;
@@ -278,7 +286,7 @@ public function obtainCollectionVersion ()
}
- return '1';
+ return self::UNSAVED_RECORD_DEFAULT_VERSION;
}
/**
@@ -58,7 +58,7 @@
$t->ok(isset($freshTags[$posts->getTable()->getClassNameToReturn()]));
- $t->cmp_ok($collectionTagVersion, '<', $freshCollectionVersion);
+ $t->cmp_ok($collectionTagVersion, '=', $freshCollectionVersion);
$c = new Doctrine_Collection_Cachetaggable('University');
@@ -42,16 +42,28 @@
$t->diag('Testing methods content');
$t->diag('obtainObjectVersion() unsaved');
- $t->is(gettype($obj->obtainObjectVersion()), 'integer', 'Return type is integer');
- $t->is($obj->obtainObjectVersion(), 1, 'Unsaved object returns 1');
+
+ // default value changed to string '1' (was 1) to match returning value
+ // in Doctrine_Template_Cachetaggable::obtainCollectionVersion and describing
+ // table custom column "object_version" specification
+ $t->is(gettype($obj->obtainObjectVersion()), 'string', 'Return type is string');
+ $t->is(
+ $obj->obtainObjectVersion(),
+ Doctrine_Template_Cachetaggable::UNSAVED_RECORD_DEFAULT_VERSION,
+ 'Unsaved object returns 1'
+ );
$t->diag('obtainCollectionVersion() unsaved');
$t->is(gettype($obj->obtainCollectionVersion()), 'string', 'Return type is string');
$t->cmp_ok($obj->obtainCollectionVersion(), '<', sfCacheTaggingToolkit::generateVersion(), 'Collection tag version could not be greater then current microtime');
$version1 = $obj->obtainCollectionVersion();
$version2 = $obj->obtainCollectionVersion();
- $t->cmp_ok($version1, '<', $version2, 'Unsaved object with neved saved any other objects return always current microtime');
+ /**
+ * @since 4.2.2 Unsaved object memorize first generated version
+ * for next method calls
+ */
+ $t->cmp_ok($version1, '=', $version2, 'Collection version stays unchanged for future method calls');
$obj->set('is_enabled', true);

0 comments on commit de6ac08

Please sign in to comment.