プロジェクト

全般

プロフィール

Bug(バグ) #3336

Yuya Watanabeほぼ11年前に更新

h3. 概要

opDoctrineQueryTest が APC のない環境で失敗する.

h3. 概要

例えば下記のように lastQueryCacheHash を取得してきているが,両方とも空文字列を返すため値が等しくなり,テストが失敗する.
<pre>
test/unit/util/opDoctrineQueryTest.php
31 Doctrine::getTable('AdminUser')->find(1);
32 $keys['find'] = myQuery::$lastQueryCacheHash;
...
55 $t->isnt($keys['find'], $keys['find_all'], '->find() and ->findAll() generates different query cache keys');
</pre>

$lastQueryCacheHash は calculateQueryCacheHash() を呼び出す.

<pre>
test/unit/util/opDoctrineQueryTest.php
5 class myQuery extends opDoctrineQuery
6 {
7 public static $lastQueryCacheHash = '';
8
9 public function calculateQueryCacheHash()
10 {
11 self::$lastQueryCacheHash = parent::calculateQueryCacheHash();
12
13 return self::$lastQueryCacheHash;
14 }
15 }
</pre>

calculateQueryCacheHash() が呼ばれるのは find() や findAll() など, おおまかに言うと execute() を呼び出している部分.932 行目の $this->conn->getAttribute(Doctrine_Core::ATTR_QUERY_CACHE) が偽になる.
<pre>
lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Query/Abstract.php
932 if ($this->_queryCache !== false && ($this->_queryCache || $this->conn->getAttribute(Doctrine_Core::ATTR_QUERY_CACHE))) {
933 $queryCacheDriver = $this->getQueryCacheDriver();
934 $hash = $this->calculateQueryCacheHash();
935 $cached = $queryCacheDriver->fetch($hash);
</pre>

932 行目の Doctrine::ATTR_QUERY_CACHE は OpenPNE では下記部分で定義されている.見て分かる通り apc が有効でないと設定されない.
<pre>
lib/config/opProjectConfiguration.class.php
118 if (extension_loaded('apc'))
119 {
...
129 $cacheDriver = new Doctrine_Cache_Apc($options);
130 $manager->setAttribute(Doctrine::ATTR_QUERY_CACHE, $cacheDriver);
</pre>

h3. 修正案

キャッシュされた場合,そのハッシュが等しくないかどうかを確認したいという内容のテストであると思われるため, そしてキャッシュされた場合,そのハッシュが等しくないかどうかを確認したいという内容のテストであると思われるため, APC が入っていない環境でもテストは実行されるべき.そのために Doctrine::ATTR_QUERY_CACHE に new Doctrine_Cache_Array() をセットすることで環境に依存しないテストの実行ができるものと考えられる.

<pre>
diff --git a/test/unit/util/opDoctrineQueryTest.php b/test/unit/util/opDoctrineQueryTest.php
index fc02677..9de61f6 100644
--- a/test/unit/util/opDoctrineQueryTest.php
+++ b/test/unit/util/opDoctrineQueryTest.php
@@ -21,6 +21,7 @@ $configuration = ProjectConfiguration::getApplicationConfiguration($_app, $_env,
new sfDatabaseManager($configuration);

Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_QUERY_CLASS, 'myQuery');
+Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_QUERY_CACHE, new Doctrine_Cache_Array());

$t = new lime_test(null, new lime_output_color());

</pre>

戻る