Author: maksim_ka
Date: 2010-05-19 09:18:42 +0200 (Wed, 19 May 2010)
New Revision: 29517
Removed:
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/doctrine/sfPhpunitFixtureDoctrine12.php
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/doctrine/sfPhpunitFixtureDoctrine14.php
Modified:
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/dbunit/sfPhpunitFixtureDbUnit.php
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/doctrine/sfPhpunitFixtureDoctrine.php
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/propel/sfPhpunitFixturePropel.php
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/propel/sfPhpunitPropelData.php
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/sfPhpunitFixture.php
plugins/sfPhpunitPlugin/branches/1.2-4/lib/test/sfBasePhpunitTestSuite.class.php
Log:
[sfPhpunitPlugin][sf1.2-4] Fix bugs with unsing propel objects as a fixtures.
add method cleanSnapshots.
Modified:
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/dbunit/sfPhpunitFixtureDbUnit.php
===================================================================
---
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/dbunit/sfPhpunitFixtureDbUnit.php
2010-05-19 04:33:58 UTC (rev 29516)
+++
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/dbunit/sfPhpunitFixtureDbUnit.php
2010-05-19 07:18:42 UTC (rev 29517)
@@ -39,9 +39,4 @@
{
throw new Exception('Not complited yet');
}
-
- public static function build($aggregator, array $options = array())
- {
- return new self($aggregator, $options);
- }
}
\ No newline at end of file
Modified:
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/doctrine/sfPhpunitFixtureDoctrine.php
===================================================================
---
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/doctrine/sfPhpunitFixtureDoctrine.php
2010-05-19 04:33:58 UTC (rev 29516)
+++
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/doctrine/sfPhpunitFixtureDoctrine.php
2010-05-19 07:18:42 UTC (rev 29517)
@@ -10,12 +10,15 @@
*/
abstract class sfPhpunitFixtureDoctrine extends sfPhpunitFixture
{
+ protected $_data;
+
/**
*
* @var array
*/
protected $_options = array(
- 'fixture_ext' => '.doctrine.yml');
+ 'fixture_ext' => '.doctrine.yml',
+ 'snapshot-table-prefix' => '_snapshot');
/**
* (non-PHPdoc)
@@ -90,24 +93,28 @@
->getCurrentConnection()->clear();
}
- abstract protected function _getDataLoader();
-
- public static function build($aggregator, array $options = array())
+ protected function _getDataLoader()
{
if (version_compare(SYMFONY_VERSION, '1.2.0', '>=') &&
version_compare(SYMFONY_VERSION, '1.3.0', '<'))
{
- return new sfPhpunitFixtureDoctrine12($aggregator, $options);
+ $dataClass = 'sfPhpunitFixtureDoctrine12';
} else if (version_compare(SYMFONY_VERSION, '1.3.0', '>=') &&
version_compare(SYMFONY_VERSION, '1.5.0', '<='))
{
- return new sfPhpunitFixtureDoctrine14($aggregator, $options);
+ $dataClass = 'sfPhpunitFixtureDoctrine14';
+ } else {
+ throw new LogicException('The symfony version `'.SYMFONY_VERSION.'` is
not supported for doctrine fixture');
}
-
- throw new LogicException('The symfony version `'.SYMFONY_VERSION.'` is not
supported for doctrine fixture');
+
+ if (!$this->_data) {
+ $this->_data = new $dataClass();
+ }
+
+ return $this->_data;
}
}
\ No newline at end of file
Deleted:
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/doctrine/sfPhpunitFixtureDoctrine12.php
===================================================================
---
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/doctrine/sfPhpunitFixtureDoctrine12.php
2010-05-19 04:33:58 UTC (rev 29516)
+++
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/doctrine/sfPhpunitFixtureDoctrine12.php
2010-05-19 07:18:42 UTC (rev 29517)
@@ -1,27 +0,0 @@
-<?php
-
-/**
- *
- * Class for managing syfmony 1.2 doctrine fixtures.
- *
- * @package sfPhpunitPlugin
- * @subpackage fixture
- * @author Maksim Kotlyar <[email protected]>
- */
-class sfPhpunitFixtureDoctrine12 extends sfPhpunitFixtureDoctrine
-{
- protected $_data;
-
- /**
- *
- * @return sfPhpunitDoctrineData12
- */
- protected function _getDataLoader()
- {
- if (!$this->_data) {
- $this->_data = new sfPhpunitDoctrineData12();
- }
-
- return $this->_data;
- }
-}
\ No newline at end of file
Deleted:
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/doctrine/sfPhpunitFixtureDoctrine14.php
===================================================================
---
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/doctrine/sfPhpunitFixtureDoctrine14.php
2010-05-19 04:33:58 UTC (rev 29516)
+++
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/doctrine/sfPhpunitFixtureDoctrine14.php
2010-05-19 07:18:42 UTC (rev 29517)
@@ -1,27 +0,0 @@
-<?php
-
-/**
- *
- * Class for managing doctrine fixtures.
- *
- * @package sfPhpunitPlugin
- * @subpackage fixture
- * @author Maksim Kotlyar <[email protected]>
- */
-class sfPhpunitFixtureDoctrine14 extends sfPhpunitFixtureDoctrine
-{
- protected $_data;
-
- /**
- *
- * @return sfPhpunitDoctrineData14
- */
- protected function _getDataLoader()
- {
- if (!$this->_data) {
- $this->_data = new sfPhpunitDoctrineData14();
- }
-
- return $this->_data;
- }
-}
\ No newline at end of file
Modified:
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/propel/sfPhpunitFixturePropel.php
===================================================================
---
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/propel/sfPhpunitFixturePropel.php
2010-05-19 04:33:58 UTC (rev 29516)
+++
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/propel/sfPhpunitFixturePropel.php
2010-05-19 07:18:42 UTC (rev 29517)
@@ -21,6 +21,7 @@
*/
protected $_options = array(
'fixture_ext' => '.propel.yml',
+ 'snapshot-table-prefix' => '_snapshot',
'connection' => null);
/**
@@ -52,6 +53,28 @@
return $this->_getDataLoader()->getObject($id);
}
+ public function doSnapshot($name)
+ {
+ parent::doSnapshot($name);
+
+ $this->_getDataLoader()->doSnapshot($name);
+
+ return $this;
+ }
+
+ /**
+ *
+ * @param string $name
+ */
+ public function loadSnapshot($name)
+ {
+ parent::loadSnapshot($name);
+
+ $this->_getDataLoader()->loadSnapshot($name);
+
+ return $this;
+ }
+
protected function _pdo()
{
return Propel::getConnection($this->_getOption('connection'));
@@ -67,9 +90,4 @@
return $this->_data;
}
-
- public static function build($aggregator, array $options = array())
- {
- return new self($aggregator, $options);
- }
}
\ No newline at end of file
Modified:
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/propel/sfPhpunitPropelData.php
===================================================================
---
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/propel/sfPhpunitPropelData.php
2010-05-19 04:33:58 UTC (rev 29516)
+++
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/propel/sfPhpunitPropelData.php
2010-05-19 07:18:42 UTC (rev 29517)
@@ -2,6 +2,21 @@
class sfPhpunitPropelData extends sfPropelData
{
+ protected static $_snapshots = array();
+
+ protected $deleteCurrentData = false;
+
+ protected function doLoadData($files)
+ {
+// $this->object_references = array();
+// $this->maps = array();
+
+ foreach ($files as $file)
+ {
+ $this->doLoadDataFromFile($file);
+ }
+ }
+
/**
* (non-PHPdoc)
* @see
plugins/sfPhpunitPlugin/lib/fixture/data/sfPhpunitDataInterface#getObject($id,
$class)
@@ -11,14 +26,27 @@
if (strpos($id, '_') === false) {
throw new Exception('The id should match the pattern {class}_{id} but
you provide: `'.$id.'`');
}
-
+
if (!isset($this->object_references[$id])) {
throw new Exception('The data object with given id `'.$id.'` does not
exist');
}
-
- return $this->object_references[$id];
+
+ $object = $this->object_references[$id];
+ $object->reload();
+
+ return clone $object;
}
+ public function doSnapshot($name)
+ {
+ self::$_snapshots[$name] = $this->object_references;
+ }
+
+ public function loadSnapshot($name)
+ {
+ $this->object_references = self::$_snapshots[$name];
+ }
+
public function cleanObjects()
{
$this->object_references = array();
Modified:
plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/sfPhpunitFixture.php
===================================================================
--- plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/sfPhpunitFixture.php
2010-05-19 04:33:58 UTC (rev 29516)
+++ plugins/sfPhpunitPlugin/branches/1.2-4/lib/fixture/sfPhpunitFixture.php
2010-05-19 07:18:42 UTC (rev 29517)
@@ -44,7 +44,7 @@
*
* @var array
*/
- protected $_requiredOptions = array('fixture_ext');
+ protected $_requiredOptions = array('fixture_ext', 'snapshot-table-prefix');
protected $_options = array();
@@ -92,12 +92,16 @@
{
$this->pdo()->exec("SET FOREIGN_KEY_CHECKS = 0;");
+ $snapshotPrefix = $this->_getOption('snapshot-table-prefix');
+
$query = $this->pdo()->prepare('SHOW TABLES');
$query->execute();
while($table = $query->fetchColumn()) {
+ if (strpos($table, $snapshotPrefix) !== false) continue;
+
$this->pdo()->exec("TRUNCATE TABLE `{$table}`");
}
-
+
$this->pdo()->exec("SET FOREIGN_KEY_CHECKS = 1;");
$this->_getDataLoader()->cleanObjects();
@@ -119,10 +123,12 @@
public function doSnapshot($name)
{
$query = $this->pdo()->query('SHOW TABLES');
+ $snapshotPrefix = $this->_getOption('snapshot-table-prefix');
+
while($table = $query->fetchColumn()) {
- if (strpos($table, '_snapshot_') !== false) continue;
+ if (strpos($table, $snapshotPrefix) !== false) continue;
- $snapshop_table = "_snapshot_{$name}_{$table}";
+ $snapshop_table = "{$snapshotPrefix}_{$name}_{$table}";
$this->pdo()->exec("DROP TABLE IF EXISTS `{$snapshop_table}`");
$this->pdo()->exec("CREATE TABLE `{$snapshop_table}` SELECT * FROM
`{$table}`");
}
@@ -132,6 +138,20 @@
return $this;
}
+ public function cleanSnapshots()
+ {
+ $query = $this->pdo()->query('SHOW TABLES');
+ $snapshotPrefix = $this->_getOption('snapshot-table-prefix');
+
+ while($table = $query->fetchColumn()) {
+ if (strpos($table, $snapshotPrefix) === false) continue;
+
+ $this->pdo()->exec("DROP TABLE IF EXISTS `{$table}`");
+ }
+
+ return $this;
+ }
+
/**
*
* @param string $name
@@ -321,9 +341,7 @@
foreach ($map as $class => $agg_type) {
if ($aggregator instanceof $agg_type) {
- return call_user_func_array(
- array($class, 'build'),
- array($aggregator, $options));
+ return new $class($aggregator, $options);
}
}
Modified:
plugins/sfPhpunitPlugin/branches/1.2-4/lib/test/sfBasePhpunitTestSuite.class.php
===================================================================
---
plugins/sfPhpunitPlugin/branches/1.2-4/lib/test/sfBasePhpunitTestSuite.class.php
2010-05-19 04:33:58 UTC (rev 29516)
+++
plugins/sfPhpunitPlugin/branches/1.2-4/lib/test/sfBasePhpunitTestSuite.class.php
2010-05-19 07:18:42 UTC (rev 29517)
@@ -121,12 +121,12 @@
public function getCommonFixtureDir()
{
- return sfConfig::get('sf_phpunit_dir').'/phpunit/fixtures/common';
+ return sfConfig::get('sf_phpunit_dir').'/fixtures/common';
}
public function getSymfonyFixtureDir()
{
- return sfConfig::get('sf_phpunit_dir').'/fixtures';
+ return sfConfig::get('sf_data_dir').'/fixtures';
}
/**
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.