Merge branch '2.3' into 2.4

* 2.3:
  Make Doctrine's dependency injection test less fragile.
  [Finder] [Iterator] Make the tests less fragile
  [Form][DateTime] Propagate invalid_message & invalid_message parameters to date & time sub widgets
This commit is contained in:
Fabien Potencier 2014-09-27 10:35:25 +02:00
commit e768f37685
5 changed files with 87 additions and 36 deletions

View File

@ -132,7 +132,11 @@ class RegisterEventListenersAndSubscribersPassTest extends \PHPUnit_Framework_Te
; ;
$this->process($container); $this->process($container);
$this->assertEquals(array('c', 'd', 'e', 'b', 'a'), $this->getServiceOrder($container, 'addEventSubscriber')); $serviceOrder = $this->getServiceOrder($container, 'addEventSubscriber');
$unordered = array_splice($serviceOrder, 0, 3);
sort($unordered);
$this->assertEquals(array('c', 'd', 'e'), $unordered);
$this->assertEquals(array('b', 'a'), $serviceOrder);
} }
public function testProcessNoTaggedServices() public function testProcessNoTaggedServices()

View File

@ -34,6 +34,31 @@ abstract class IteratorTestCase extends \PHPUnit_Framework_TestCase
$this->assertEquals($expected, array_values($values)); $this->assertEquals($expected, array_values($values));
} }
/**
* Same as assertOrderedIterator, but checks the order of groups of
* array elements.
*
* @param array $expected - an array of arrays. For any two subarrays
* $a and $b such that $a goes before $b in $expected, the method
* asserts that any element of $a goes before any element of $b
* in the sequence generated by $iterator
* @param \Traversable $iterator
*/
protected function assertOrderedIteratorForGroups($expected, \Traversable $iterator)
{
$values = array_values(array_map(function (\SplFileInfo $fileinfo) { return $fileinfo->getPathname(); }, iterator_to_array($iterator)));
foreach ($expected as $subarray) {
$temp = array();
while (count($values) && count($temp) < count($subarray)) {
array_push($temp, array_shift($values));
}
sort($temp);
sort($subarray);
$this->assertEquals($subarray, $temp);
}
}
/** /**
* Same as IteratorTestCase::assertIterator with foreach usage * Same as IteratorTestCase::assertIterator with foreach usage
* *

View File

@ -80,7 +80,11 @@ abstract class RealIteratorTestCase extends IteratorTestCase
if (is_array($files)) { if (is_array($files)) {
$f = array(); $f = array();
foreach ($files as $file) { foreach ($files as $file) {
$f[] = self::$tmpDir.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $file); if (is_array($file)) {
$f[] = self::toAbsolute($file);
} else {
$f[] = self::$tmpDir.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $file);
}
} }
return $f; return $f;

View File

@ -54,7 +54,13 @@ class SortableIteratorTest extends RealIteratorTestCase
$iterator = new SortableIterator($inner, $mode); $iterator = new SortableIterator($inner, $mode);
$this->assertOrderedIterator($expected, $iterator); if ($mode === SortableIterator::SORT_BY_ACCESSED_TIME
|| $mode === SortableIterator::SORT_BY_CHANGED_TIME
|| $mode === SortableIterator::SORT_BY_MODIFIED_TIME) {
$this->assertOrderedIteratorForGroups($expected, $iterator);
} else {
$this->assertOrderedIterator($expected, $iterator);
}
} }
public function getAcceptData() public function getAcceptData()
@ -102,45 +108,53 @@ class SortableIteratorTest extends RealIteratorTestCase
); );
$sortByAccessedTime = array( $sortByAccessedTime = array(
'foo/bar.tmp', // For these two files the access time was set to 2005-10-15
'test.php', array('foo/bar.tmp', 'test.php'),
'toto', // These files were created more or less at the same time
'foo bar', array(
'foo', '.git',
'test.py', '.foo',
'.foo', '.foo/.bar',
'.foo/.bar', '.foo/bar',
'.foo/bar', 'test.py',
'.git', 'foo',
'.bar', 'toto',
'foo bar',
),
// This file was accessed after sleeping for 1 sec
array('.bar'),
); );
$sortByChangedTime = array( $sortByChangedTime = array(
'foo', array(
'foo/bar.tmp', '.git',
'toto', '.foo',
'.git', '.foo/.bar',
'.bar', '.foo/bar',
'.foo', '.bar',
'foo bar', 'foo',
'.foo/.bar', 'foo/bar.tmp',
'.foo/bar', 'toto',
'test.php', 'foo bar',
'test.py', ),
array('test.php'),
array('test.py'),
); );
$sortByModifiedTime = array( $sortByModifiedTime = array(
'foo/bar.tmp', array(
'foo', '.git',
'toto', '.foo',
'.git', '.foo/.bar',
'.bar', '.foo/bar',
'.foo', '.bar',
'foo bar', 'foo',
'.foo/.bar', 'foo/bar.tmp',
'.foo/bar', 'toto',
'test.php', 'foo bar',
'test.py', ),
array('test.php'),
array('test.py'),
); );
return array( return array(

View File

@ -117,6 +117,8 @@ class DateTimeType extends AbstractType
'empty_value', 'empty_value',
'required', 'required',
'translation_domain', 'translation_domain',
'invalid_message',
'invalid_message_parameters',
))); )));
$timeOptions = array_intersect_key($options, array_flip(array( $timeOptions = array_intersect_key($options, array_flip(array(
@ -128,6 +130,8 @@ class DateTimeType extends AbstractType
'empty_value', 'empty_value',
'required', 'required',
'translation_domain', 'translation_domain',
'invalid_message',
'invalid_message_parameters',
))); )));
if (null !== $options['date_widget']) { if (null !== $options['date_widget']) {