Author: Leon.van.der.Ree
Date: 2010-04-14 22:21:28 +0200 (Wed, 14 Apr 2010)
New Revision: 29155
Modified:
plugins/sfDataSourcePlugin/trunk/lib/sfDataSourceArray.class.php
plugins/sfDataSourcePlugin/trunk/test/unit/datasource/sfDataSourceArrayTest.php
plugins/sfDataSourcePlugin/trunk/test/unit/datasource/sfDataSourceDoctrineTest.php
plugins/sfDataSourcePlugin/trunk/test/unit/datasource/sfDataSourcePropelTest.php
plugins/sfDataSourcePlugin/trunk/test/unit/datasource/sfDataSourceTest.php
plugins/sfDataSourcePlugin/trunk/test/unit/mock/sfDataSourceMock.class.php
Log:
fixed bug in DataSourceArray with empty arrays and fixed unit tests of new
sfDataSourceInterface implementations
Modified: plugins/sfDataSourcePlugin/trunk/lib/sfDataSourceArray.class.php
===================================================================
--- plugins/sfDataSourcePlugin/trunk/lib/sfDataSourceArray.class.php
2010-04-14 19:31:19 UTC (rev 29154)
+++ plugins/sfDataSourcePlugin/trunk/lib/sfDataSourceArray.class.php
2010-04-14 20:21:28 UTC (rev 29155)
@@ -170,11 +170,15 @@
}
/**
+ * requireColumn checks if the source contains the desired column.
+ * If the source is an empty array, any column will be accepted, since
+ * the DataSource doesn't have any model-data to base its decision on
+ *
* @see sfDataSourceInterface::requireColumn()
*/
public function requireColumn($column)
{
- if (!($this->count()>0 && array_key_exists($column, $this->data[0])))
+ if (($this->count() != 0 && !array_key_exists($column,
current($this->data))))
{
throw new LogicException(sprintf('The column "%s" has not been defined
in the datasource', $column));
}
Modified:
plugins/sfDataSourcePlugin/trunk/test/unit/datasource/sfDataSourceArrayTest.php
===================================================================
---
plugins/sfDataSourcePlugin/trunk/test/unit/datasource/sfDataSourceArrayTest.php
2010-04-14 19:31:19 UTC (rev 29154)
+++
plugins/sfDataSourcePlugin/trunk/test/unit/datasource/sfDataSourceArrayTest.php
2010-04-14 20:21:28 UTC (rev 29155)
@@ -10,7 +10,7 @@
require_once(dirname(__FILE__).'/../../bootstrap/unit.php');
-$t = new lime_test(32, new lime_output_color());
+$t = new lime_test(37, new lime_output_color());
$data = array(
array('id' => 1, 'name' => 'Fabien'),
@@ -65,6 +65,30 @@
$t->pass('->__construct() throws an "InvalidArgumentException" if the array
entries are not arrays');
}
+
+$t->diag('->requireColumn()');
+$s = new sfDataSourceArray($data);
+try
+{
+ $s->requireColumn('name');
+ $t->pass('sfDataSourceArray accepts existing column (name) of an array');
+}
+catch (Exception $e)
+{
+ $t->fail('sfDataSourceArray accepts existing column (name) of an array');
+}
+
+try
+{
+ $s->requireColumn('anyColumn');
+ $t->fail('sfDataSourceArray does not accept columns that are not in the
array');
+}
+catch (LogicException $e)
+{
+ $t->pass('sfDataSourceArray does not accept columns that are not in the
array');
+}
+
+
// SeekableIterator interface
$t->diag('SeekableIterator interface');
$s = new sfDataSourceArray($data);
@@ -216,3 +240,35 @@
foreach ($s as $row) { $values[] = $s['name']; }
sort($originalValues);
$t->is($values, $originalValues, '->setSort() sorts correctly');
+
+
+
+
+// support for empty arrays
+$t->diag('support for empty arrays');
+
+$data_empty = array();
+$s = new sfDataSourceArray($data_empty);
+
+$t->is(count($s), 0, 'sfDataSourceArray accepts empty array');
+
+try
+{
+ $s->requireColumn('anyColumn');
+ $t->pass('sfDataSourceArray accepts any column when an empty array is
provided');
+}
+catch (Exception $e)
+{
+ $t->fail('sfDataSourceArray accepts any column when an empty array is
provided');
+}
+
+try
+{
+ $s['name'];
+ $t->fail('sfDataSourceArray throws an "OutOfBoundsException" when fields are
accessed after iterating');
+}
+catch (OutOfBoundsException $e)
+{
+ $t->pass('sfDataSourceArray throws an "OutOfBoundsException" when fields are
accessed after iterating');
+}
+
Modified:
plugins/sfDataSourcePlugin/trunk/test/unit/datasource/sfDataSourceDoctrineTest.php
===================================================================
---
plugins/sfDataSourcePlugin/trunk/test/unit/datasource/sfDataSourceDoctrineTest.php
2010-04-14 19:31:19 UTC (rev 29154)
+++
plugins/sfDataSourcePlugin/trunk/test/unit/datasource/sfDataSourceDoctrineTest.php
2010-04-14 20:21:28 UTC (rev 29155)
@@ -26,6 +26,15 @@
$autoload->register();
//class ProjectConfiguration extends sfProjectConfiguration {}
+class ProjectConfiguration extends sfProjectConfiguration
+{
+// protected $plugins = array('sfPropel15Plugin');
+
+ public function setup()
+ {
+ $this->setPluginPath('sfDoctrinePlugin',
dirname(__FILE__).'/../../../../sfPropel15Plugin');
+ }
+}
$configuration = new ProjectConfiguration(dirname(__FILE__).'/../../lib', new
sfEventDispatcher());
$database = new sfDoctrineDatabase(array('name' => 'doctrine', 'dsn' =>
'sqlite::memory:'));
Modified:
plugins/sfDataSourcePlugin/trunk/test/unit/datasource/sfDataSourcePropelTest.php
===================================================================
---
plugins/sfDataSourcePlugin/trunk/test/unit/datasource/sfDataSourcePropelTest.php
2010-04-14 19:31:19 UTC (rev 29154)
+++
plugins/sfDataSourcePlugin/trunk/test/unit/datasource/sfDataSourcePropelTest.php
2010-04-14 20:21:28 UTC (rev 29155)
@@ -343,10 +343,12 @@
$t->is(iterator_to_field_array($s, 'Name'), $originalValues, '->setSort()
sorts correctly');
$s = new sfDataSourcePropel('City');
-$s->setSort('Name', sfDataSourceInterface::DESC); // you cannot sort on the
same field twice, this is different from other implementations
+// TODO: sorting on the same column twice will result in first sorting on
first column, than on the second (which will be ineffective)
+// is this desired?
+$s->setSort('Name', sfDataSourceInterface::DESC);
$s->setSort('Name', sfDataSourceInterface::ASC);
sort($originalValues);
-$t->is(iterator_to_field_array($s, 'Name'), $originalValues, '->setSort()
sorts correctly');
+$t->is(array_reverse(iterator_to_field_array($s, 'Name')), $originalValues,
'->setSort() sorts correctly, or isn\'t it?');
$byCountryValues = array(
Modified:
plugins/sfDataSourcePlugin/trunk/test/unit/datasource/sfDataSourceTest.php
===================================================================
--- plugins/sfDataSourcePlugin/trunk/test/unit/datasource/sfDataSourceTest.php
2010-04-14 19:31:19 UTC (rev 29154)
+++ plugins/sfDataSourcePlugin/trunk/test/unit/datasource/sfDataSourceTest.php
2010-04-14 20:21:28 UTC (rev 29155)
@@ -39,6 +39,11 @@
$this->sortOrder = $order;
}
+ public function addFilter($column, $value, $comparison = sfDataSource::EQUAL)
+ {
+ throw new Exception('This method has not been implemented yet');
+ }
+
public function current() {}
public function offsetGet($key) {}
public function count() {}
Modified:
plugins/sfDataSourcePlugin/trunk/test/unit/mock/sfDataSourceMock.class.php
===================================================================
--- plugins/sfDataSourcePlugin/trunk/test/unit/mock/sfDataSourceMock.class.php
2010-04-14 19:31:19 UTC (rev 29154)
+++ plugins/sfDataSourcePlugin/trunk/test/unit/mock/sfDataSourceMock.class.php
2010-04-14 20:21:28 UTC (rev 29155)
@@ -80,7 +80,7 @@
/**
* @see sfDataSourceInterface
*/
- public function setFilter($fields)
+ public function addFilter($column, $value, $comparison = sfDataSource::EQUAL)
{
throw new Exception('This method has not been implemented yet');
}
--
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.