Windows and Intl fixes
This commit is contained in:
parent
8bbd8d90fe
commit
ea5d656ddd
@ -491,6 +491,10 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testRenderExceptionWithDoubleWidthCharacters()
|
public function testRenderExceptionWithDoubleWidthCharacters()
|
||||||
{
|
{
|
||||||
|
if (!function_exists('mb_strwidth')) {
|
||||||
|
$this->markTestSkipped('The "mb_strwidth" function is not available');
|
||||||
|
}
|
||||||
|
|
||||||
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
|
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
|
||||||
$application->setAutoExit(false);
|
$application->setAutoExit(false);
|
||||||
$application->expects($this->any())
|
$application->expects($this->any())
|
||||||
|
@ -156,20 +156,43 @@ class Crawler extends \SplObjectStorage
|
|||||||
$dom = new \DOMDocument('1.0', $charset);
|
$dom = new \DOMDocument('1.0', $charset);
|
||||||
$dom->validateOnParse = true;
|
$dom->validateOnParse = true;
|
||||||
|
|
||||||
if (function_exists('mb_convert_encoding')) {
|
set_error_handler(function () {throw new \Exception();});
|
||||||
$hasError = false;
|
|
||||||
set_error_handler(function () use (&$hasError) {
|
|
||||||
$hasError = true;
|
|
||||||
});
|
|
||||||
$tmpContent = @mb_convert_encoding($content, 'HTML-ENTITIES', $charset);
|
|
||||||
|
|
||||||
restore_error_handler();
|
try {
|
||||||
|
// Convert charset to HTML-entities to work around bugs in DOMDocument::loadHTML()
|
||||||
|
|
||||||
if (!$hasError) {
|
if (function_exists('mb_convert_encoding')) {
|
||||||
$content = $tmpContent;
|
$content = mb_convert_encoding($content, 'HTML-ENTITIES', $charset);
|
||||||
|
} elseif (function_exists('iconv')) {
|
||||||
|
$content = preg_replace_callback(
|
||||||
|
'/[\x80-\xFF]+/',
|
||||||
|
function ($m) {
|
||||||
|
$m = unpack('C*', $m[0]);
|
||||||
|
$i = 1;
|
||||||
|
$entities = '';
|
||||||
|
|
||||||
|
while (isset($m[$i])) {
|
||||||
|
if (0xF0 <= $m[$i]) {
|
||||||
|
$c = (($m[$i++] - 0xF0) << 18) + (($m[$i++] - 0x80) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80;
|
||||||
|
} elseif (0xE0 <= $m[$i]) {
|
||||||
|
$c = (($m[$i++] - 0xE0) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80;
|
||||||
|
} else {
|
||||||
|
$c = (($m[$i++] - 0xC0) << 6) + $m[$i++] - 0x80;
|
||||||
|
}
|
||||||
|
|
||||||
|
$entities .= '&#'.$c.';';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $entities;
|
||||||
|
},
|
||||||
|
iconv($charset, 'UTF-8', $content)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
restore_error_handler();
|
||||||
|
|
||||||
if ('' !== trim($content)) {
|
if ('' !== trim($content)) {
|
||||||
@$dom->loadHTML($content);
|
@$dom->loadHTML($content);
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,7 @@ class CrawlerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Component\DomCrawler\Crawler::addHtmlContent
|
* @covers Symfony\Component\DomCrawler\Crawler::addHtmlContent
|
||||||
|
* @requires extension mbstring
|
||||||
*/
|
*/
|
||||||
public function testAddHtmlContentCharset()
|
public function testAddHtmlContentCharset()
|
||||||
{
|
{
|
||||||
@ -114,6 +115,7 @@ class CrawlerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Component\DomCrawler\Crawler::addHtmlContent
|
* @covers Symfony\Component\DomCrawler\Crawler::addHtmlContent
|
||||||
|
* @requires extension mbstring
|
||||||
*/
|
*/
|
||||||
public function testAddHtmlContentCharsetGbk()
|
public function testAddHtmlContentCharsetGbk()
|
||||||
{
|
{
|
||||||
@ -234,7 +236,7 @@ EOF
|
|||||||
$this->assertEquals('中文', $crawler->filterXPath('//span')->text(), '->addContent() guess wrong charset');
|
$this->assertEquals('中文', $crawler->filterXPath('//span')->text(), '->addContent() guess wrong charset');
|
||||||
|
|
||||||
$crawler = new Crawler();
|
$crawler = new Crawler();
|
||||||
$crawler->addContent(mb_convert_encoding('<html><head><meta charset="Shift_JIS"></head><body>日本語</body></html>', 'SJIS', 'UTF-8'));
|
$crawler->addContent(iconv('UTF-8', 'SJIS', '<html><head><meta charset="Shift_JIS"></head><body>日本語</body></html>'));
|
||||||
$this->assertEquals('日本語', $crawler->filterXPath('//body')->text(), '->addContent() can recognize "Shift_JIS" in html5 meta charset tag');
|
$this->assertEquals('日本語', $crawler->filterXPath('//body')->text(), '->addContent() can recognize "Shift_JIS" in html5 meta charset tag');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,16 +34,13 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public static function setUpBeforeClass()
|
public static function setUpBeforeClass()
|
||||||
{
|
{
|
||||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
if ('\\' === DIRECTORY_SEPARATOR && null === self::$symlinkOnWindows) {
|
||||||
self::$symlinkOnWindows = true;
|
$target = tempnam(sys_get_temp_dir(), 'sl');
|
||||||
$originDir = tempnam(sys_get_temp_dir(), 'sl');
|
$link = sys_get_temp_dir().'/sl'.microtime(true).mt_rand();
|
||||||
$targetDir = tempnam(sys_get_temp_dir(), 'sl');
|
if (self::$symlinkOnWindows = @symlink($target, $link)) {
|
||||||
if (true !== @symlink($originDir, $targetDir)) {
|
unlink($link);
|
||||||
$report = error_get_last();
|
|
||||||
if (is_array($report) && false !== strpos($report['message'], 'error code(1314)')) {
|
|
||||||
self::$symlinkOnWindows = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
unlink($target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,27 +55,10 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
{
|
{
|
||||||
$this->clean($this->workspace);
|
$this->filesystem->remove($this->workspace);
|
||||||
umask($this->umask);
|
umask($this->umask);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $file
|
|
||||||
*/
|
|
||||||
private function clean($file)
|
|
||||||
{
|
|
||||||
if (is_dir($file) && !is_link($file)) {
|
|
||||||
$dir = new \FilesystemIterator($file);
|
|
||||||
foreach ($dir as $childFile) {
|
|
||||||
$this->clean($childFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
rmdir($file);
|
|
||||||
} else {
|
|
||||||
unlink($file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCopyCreatesNewFile()
|
public function testCopyCreatesNewFile()
|
||||||
{
|
{
|
||||||
$sourceFilePath = $this->workspace.DIRECTORY_SEPARATOR.'copy_source_file';
|
$sourceFilePath = $this->workspace.DIRECTORY_SEPARATOR.'copy_source_file';
|
||||||
@ -1035,7 +1015,7 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->markTestSkipped('symlink is not supported');
|
$this->markTestSkipped('symlink is not supported');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('\\' === DIRECTORY_SEPARATOR && false === self::$symlinkOnWindows) {
|
if (false === self::$symlinkOnWindows) {
|
||||||
$this->markTestSkipped('symlink requires "Create symbolic links" privilege on Windows');
|
$this->markTestSkipped('symlink requires "Create symbolic links" privilege on Windows');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,9 +60,6 @@ class RecursiveDirectoryIteratorTest extends IteratorTestCase
|
|||||||
$i->seek(1);
|
$i->seek(1);
|
||||||
$actual[] = $i->getPathname();
|
$actual[] = $i->getPathname();
|
||||||
|
|
||||||
$i->seek(2);
|
|
||||||
$actual[] = $i->getPathname();
|
|
||||||
|
|
||||||
$this->assertEquals($contains, $actual);
|
$this->assertEquals($contains, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +70,6 @@ class RecursiveDirectoryIteratorTest extends IteratorTestCase
|
|||||||
// ftp
|
// ftp
|
||||||
$contains = array(
|
$contains = array(
|
||||||
'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'README',
|
'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'README',
|
||||||
'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'index.html',
|
|
||||||
'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'pub',
|
'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'pub',
|
||||||
);
|
);
|
||||||
$data[] = array('ftp://ftp.mozilla.org/', false, $contains);
|
$data[] = array('ftp://ftp.mozilla.org/', false, $contains);
|
||||||
|
@ -33,7 +33,11 @@ class SortableIteratorTest extends RealIteratorTestCase
|
|||||||
if (!is_callable($mode)) {
|
if (!is_callable($mode)) {
|
||||||
switch ($mode) {
|
switch ($mode) {
|
||||||
case SortableIterator::SORT_BY_ACCESSED_TIME :
|
case SortableIterator::SORT_BY_ACCESSED_TIME :
|
||||||
file_get_contents(self::toAbsolute('.git'));
|
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||||
|
touch(self::toAbsolute('.git'));
|
||||||
|
} else {
|
||||||
|
file_get_contents(self::toAbsolute('.git'));
|
||||||
|
}
|
||||||
sleep(1);
|
sleep(1);
|
||||||
file_get_contents(self::toAbsolute('.bar'));
|
file_get_contents(self::toAbsolute('.bar'));
|
||||||
break;
|
break;
|
||||||
@ -56,7 +60,11 @@ class SortableIteratorTest extends RealIteratorTestCase
|
|||||||
|
|
||||||
if ($mode === SortableIterator::SORT_BY_ACCESSED_TIME
|
if ($mode === SortableIterator::SORT_BY_ACCESSED_TIME
|
||||||
|| $mode === SortableIterator::SORT_BY_CHANGED_TIME
|
|| $mode === SortableIterator::SORT_BY_CHANGED_TIME
|
||||||
|| $mode === SortableIterator::SORT_BY_MODIFIED_TIME) {
|
|| $mode === SortableIterator::SORT_BY_MODIFIED_TIME
|
||||||
|
) {
|
||||||
|
if ('\\' === DIRECTORY_SEPARATOR && SortableIterator::SORT_BY_MODIFIED_TIME !== $mode) {
|
||||||
|
$this->markTestSkipped('Sorting by atime or ctime is not supported on Windows');
|
||||||
|
}
|
||||||
$this->assertOrderedIteratorForGroups($expected, $iterator);
|
$this->assertOrderedIteratorForGroups($expected, $iterator);
|
||||||
} else {
|
} else {
|
||||||
$this->assertOrderedIterator($expected, $iterator);
|
$this->assertOrderedIterator($expected, $iterator);
|
||||||
|
@ -86,7 +86,7 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
|||||||
$cmd = Command::create()->add('--force');
|
$cmd = Command::create()->add('--force');
|
||||||
|
|
||||||
$cmd->arg('--run');
|
$cmd->arg('--run');
|
||||||
$this->assertSame('--force \'--run\'', $cmd->join());
|
$this->assertSame('--force '.escapeshellarg('--run'), $cmd->join());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCmd()
|
public function testCmd()
|
||||||
|
@ -260,7 +260,7 @@ class DateType extends AbstractType
|
|||||||
$pattern = $formatter->getPattern();
|
$pattern = $formatter->getPattern();
|
||||||
$timezone = $formatter->getTimezoneId();
|
$timezone = $formatter->getTimezoneId();
|
||||||
|
|
||||||
if ($setTimeZone = method_exists($formatter, 'setTimeZone')) {
|
if ($setTimeZone = PHP_VERSION_ID >= 50500 || method_exists($formatter, 'setTimeZone')) {
|
||||||
$formatter->setTimeZone('UTC');
|
$formatter->setTimeZone('UTC');
|
||||||
} else {
|
} else {
|
||||||
$formatter->setTimeZoneId('UTC');
|
$formatter->setTimeZoneId('UTC');
|
||||||
|
@ -27,6 +27,10 @@ class JsonResponse extends Response
|
|||||||
protected $data;
|
protected $data;
|
||||||
protected $callback;
|
protected $callback;
|
||||||
|
|
||||||
|
// Encode <, >, ', &, and " for RFC4627-compliant JSON, which may also be embedded into HTML.
|
||||||
|
// 15 === JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT
|
||||||
|
private $encodingOptions = 15;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
@ -41,6 +45,7 @@ class JsonResponse extends Response
|
|||||||
if (null === $data) {
|
if (null === $data) {
|
||||||
$data = new \ArrayObject();
|
$data = new \ArrayObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setData($data);
|
$this->setData($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,11 +60,11 @@ class JsonResponse extends Response
|
|||||||
/**
|
/**
|
||||||
* Sets the JSONP callback.
|
* Sets the JSONP callback.
|
||||||
*
|
*
|
||||||
* @param string $callback
|
* @param string|null $callback The JSONP callback or null to use none
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException When the callback name is not valid
|
||||||
*/
|
*/
|
||||||
public function setCallback($callback = null)
|
public function setCallback($callback = null)
|
||||||
{
|
{
|
||||||
@ -80,7 +85,7 @@ class JsonResponse extends Response
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the data to be sent as json.
|
* Sets the data to be sent as JSON.
|
||||||
*
|
*
|
||||||
* @param mixed $data
|
* @param mixed $data
|
||||||
*
|
*
|
||||||
@ -90,18 +95,63 @@ class JsonResponse extends Response
|
|||||||
*/
|
*/
|
||||||
public function setData($data = array())
|
public function setData($data = array())
|
||||||
{
|
{
|
||||||
// Encode <, >, ', &, and " for RFC4627-compliant JSON, which may also be embedded into HTML.
|
if (defined('HHVM_VERSION')) {
|
||||||
$this->data = json_encode($data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
|
// HHVM does not trigger any warnings and let exceptions
|
||||||
|
// thrown from a JsonSerializable object pass through.
|
||||||
|
// If only PHP did the same...
|
||||||
|
$data = json_encode($data, $this->encodingOptions);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
if (PHP_VERSION_ID < 50400) {
|
||||||
|
// PHP 5.3 triggers annoying warnings for some
|
||||||
|
// types that can't be serialized as JSON (INF, resources, etc.)
|
||||||
|
// but doesn't provide the JsonSerializable interface.
|
||||||
|
set_error_handler('var_dump', 0);
|
||||||
|
$data = @json_encode($data, $this->encodingOptions);
|
||||||
|
} else {
|
||||||
|
// PHP 5.4 and up wrap exceptions thrown by JsonSerializable
|
||||||
|
// objects in a new exception that needs to be removed.
|
||||||
|
// Fortunately, PHP 5.5 and up do not trigger any warning anymore.
|
||||||
|
if (PHP_VERSION_ID < 50500) {
|
||||||
|
// Clear json_last_error()
|
||||||
|
json_encode(null);
|
||||||
|
$errorHandler = set_error_handler('var_dump');
|
||||||
|
restore_error_handler();
|
||||||
|
set_error_handler(function () use ($errorHandler) {
|
||||||
|
if (JSON_ERROR_NONE === json_last_error()) {
|
||||||
|
return $errorHandler && false !== call_user_func_array($errorHandler, func_get_args());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = json_encode($data, $this->encodingOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PHP_VERSION_ID < 50500) {
|
||||||
|
restore_error_handler();
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
if (PHP_VERSION_ID < 50500) {
|
||||||
|
restore_error_handler();
|
||||||
|
}
|
||||||
|
if (PHP_VERSION_ID >= 50400 && 'Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) {
|
||||||
|
throw $e->getPrevious() ?: $e;
|
||||||
|
}
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (JSON_ERROR_NONE !== json_last_error()) {
|
if (JSON_ERROR_NONE !== json_last_error()) {
|
||||||
throw new \InvalidArgumentException($this->transformJsonError());
|
throw new \InvalidArgumentException($this->transformJsonError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->data = $data;
|
||||||
|
|
||||||
return $this->update();
|
return $this->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the content and headers according to the json data and callback.
|
* Updates the content and headers according to the JSON data and callback.
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
|
@ -1740,9 +1740,9 @@ class Request
|
|||||||
return $prefix;
|
return $prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, rtrim(dirname($baseUrl), '/').'/')) {
|
if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, rtrim(dirname($baseUrl), '/'.DIRECTORY_SEPARATOR).'/')) {
|
||||||
// directory portion of $baseUrl matches
|
// directory portion of $baseUrl matches
|
||||||
return rtrim($prefix, '/');
|
return rtrim($prefix, '/'.DIRECTORY_SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
$truncatedRequestUri = $requestUri;
|
$truncatedRequestUri = $requestUri;
|
||||||
@ -1763,7 +1763,7 @@ class Request
|
|||||||
$baseUrl = substr($requestUri, 0, $pos + strlen($baseUrl));
|
$baseUrl = substr($requestUri, 0, $pos + strlen($baseUrl));
|
||||||
}
|
}
|
||||||
|
|
||||||
return rtrim($baseUrl, '/');
|
return rtrim($baseUrl, '/'.DIRECTORY_SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,7 +54,7 @@ class BinaryFileResponseTest extends ResponseTestCase
|
|||||||
*/
|
*/
|
||||||
public function testRequests($requestRange, $offset, $length, $responseRange)
|
public function testRequests($requestRange, $offset, $length, $responseRange)
|
||||||
{
|
{
|
||||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif')->setAutoEtag();
|
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200, array('Content-Type' => 'application/octet-stream'))->setAutoEtag();
|
||||||
|
|
||||||
// do a request to get the ETag
|
// do a request to get the ETag
|
||||||
$request = Request::create('/');
|
$request = Request::create('/');
|
||||||
@ -96,7 +96,7 @@ class BinaryFileResponseTest extends ResponseTestCase
|
|||||||
*/
|
*/
|
||||||
public function testFullFileRequests($requestRange)
|
public function testFullFileRequests($requestRange)
|
||||||
{
|
{
|
||||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif')->setAutoEtag();
|
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200, array('Content-Type' => 'application/octet-stream'))->setAutoEtag();
|
||||||
|
|
||||||
// prepare a request for a range of the testing file
|
// prepare a request for a range of the testing file
|
||||||
$request = Request::create('/');
|
$request = Request::create('/');
|
||||||
@ -131,7 +131,7 @@ class BinaryFileResponseTest extends ResponseTestCase
|
|||||||
*/
|
*/
|
||||||
public function testInvalidRequests($requestRange)
|
public function testInvalidRequests($requestRange)
|
||||||
{
|
{
|
||||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif')->setAutoEtag();
|
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200, array('Content-Type' => 'application/octet-stream'))->setAutoEtag();
|
||||||
|
|
||||||
// prepare a request for a range of the testing file
|
// prepare a request for a range of the testing file
|
||||||
$request = Request::create('/');
|
$request = Request::create('/');
|
||||||
@ -159,7 +159,7 @@ class BinaryFileResponseTest extends ResponseTestCase
|
|||||||
$request->headers->set('X-Sendfile-Type', 'X-Sendfile');
|
$request->headers->set('X-Sendfile-Type', 'X-Sendfile');
|
||||||
|
|
||||||
BinaryFileResponse::trustXSendfileTypeHeader();
|
BinaryFileResponse::trustXSendfileTypeHeader();
|
||||||
$response = BinaryFileResponse::create(__DIR__.'/../README.md');
|
$response = BinaryFileResponse::create(__DIR__.'/../README.md', 200, array('Content-Type' => 'application/octet-stream'));
|
||||||
$response->prepare($request);
|
$response->prepare($request);
|
||||||
|
|
||||||
$this->expectOutputString('');
|
$this->expectOutputString('');
|
||||||
@ -180,7 +180,7 @@ class BinaryFileResponseTest extends ResponseTestCase
|
|||||||
$file = new FakeFile($realpath, __DIR__.'/File/Fixtures/test');
|
$file = new FakeFile($realpath, __DIR__.'/File/Fixtures/test');
|
||||||
|
|
||||||
BinaryFileResponse::trustXSendfileTypeHeader();
|
BinaryFileResponse::trustXSendfileTypeHeader();
|
||||||
$response = new BinaryFileResponse($file);
|
$response = new BinaryFileResponse($file, 200, array('Content-Type' => 'application/octet-stream'));
|
||||||
$reflection = new \ReflectionObject($response);
|
$reflection = new \ReflectionObject($response);
|
||||||
$property = $reflection->getProperty('file');
|
$property = $reflection->getProperty('file');
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
@ -203,7 +203,7 @@ class BinaryFileResponseTest extends ResponseTestCase
|
|||||||
public function testAcceptRangeOnUnsafeMethods()
|
public function testAcceptRangeOnUnsafeMethods()
|
||||||
{
|
{
|
||||||
$request = Request::create('/', 'POST');
|
$request = Request::create('/', 'POST');
|
||||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif');
|
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200, array('Content-Type' => 'application/octet-stream'));
|
||||||
$response->prepare($request);
|
$response->prepare($request);
|
||||||
|
|
||||||
$this->assertEquals('none', $response->headers->get('Accept-Ranges'));
|
$this->assertEquals('none', $response->headers->get('Accept-Ranges'));
|
||||||
@ -212,7 +212,7 @@ class BinaryFileResponseTest extends ResponseTestCase
|
|||||||
public function testAcceptRangeNotOverriden()
|
public function testAcceptRangeNotOverriden()
|
||||||
{
|
{
|
||||||
$request = Request::create('/', 'POST');
|
$request = Request::create('/', 'POST');
|
||||||
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif');
|
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif', 200, array('Content-Type' => 'application/octet-stream'));
|
||||||
$response->headers->set('Accept-Ranges', 'foo');
|
$response->headers->set('Accept-Ranges', 'foo');
|
||||||
$response->prepare($request);
|
$response->prepare($request);
|
||||||
|
|
||||||
@ -229,6 +229,6 @@ class BinaryFileResponseTest extends ResponseTestCase
|
|||||||
|
|
||||||
protected function provideResponse()
|
protected function provideResponse()
|
||||||
{
|
{
|
||||||
return new BinaryFileResponse(__DIR__.'/../README.md');
|
return new BinaryFileResponse(__DIR__.'/../README.md', 200, array('Content-Type' => 'application/octet-stream'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,9 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('gif', $file->guessExtension());
|
$this->assertEquals('gif', $file->guessExtension());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires extension fileinfo
|
||||||
|
*/
|
||||||
public function testGuessExtensionWithReset()
|
public function testGuessExtensionWithReset()
|
||||||
{
|
{
|
||||||
$file = new File(__DIR__.'/Fixtures/other-file.example');
|
$file = new File(__DIR__.'/Fixtures/other-file.example');
|
||||||
|
@ -14,17 +14,16 @@ namespace Symfony\Component\HttpFoundation\Tests\File\MimeType;
|
|||||||
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
|
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
|
||||||
use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser;
|
use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires extension fileinfo
|
||||||
|
*/
|
||||||
class MimeTypeTest extends \PHPUnit_Framework_TestCase
|
class MimeTypeTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
protected $path;
|
protected $path;
|
||||||
|
|
||||||
public function testGuessImageWithoutExtension()
|
public function testGuessImageWithoutExtension()
|
||||||
{
|
{
|
||||||
if (extension_loaded('fileinfo')) {
|
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
|
||||||
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
|
|
||||||
} else {
|
|
||||||
$this->assertNull(MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGuessImageWithDirectory()
|
public function testGuessImageWithDirectory()
|
||||||
@ -38,29 +37,17 @@ class MimeTypeTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$guesser = MimeTypeGuesser::getInstance();
|
$guesser = MimeTypeGuesser::getInstance();
|
||||||
$guesser->register(new FileBinaryMimeTypeGuesser());
|
$guesser->register(new FileBinaryMimeTypeGuesser());
|
||||||
if (extension_loaded('fileinfo')) {
|
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
|
||||||
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
|
|
||||||
} else {
|
|
||||||
$this->assertNull(MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGuessImageWithKnownExtension()
|
public function testGuessImageWithKnownExtension()
|
||||||
{
|
{
|
||||||
if (extension_loaded('fileinfo')) {
|
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.gif'));
|
||||||
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.gif'));
|
|
||||||
} else {
|
|
||||||
$this->assertNull(MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.gif'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGuessFileWithUnknownExtension()
|
public function testGuessFileWithUnknownExtension()
|
||||||
{
|
{
|
||||||
if (extension_loaded('fileinfo')) {
|
$this->assertEquals('application/octet-stream', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension'));
|
||||||
$this->assertEquals('application/octet-stream', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension'));
|
|
||||||
} else {
|
|
||||||
$this->assertNull(MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGuessWithIncorrectPath()
|
public function testGuessWithIncorrectPath()
|
||||||
@ -75,7 +62,7 @@ class MimeTypeTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->markTestSkipped('Can not verify chmod operations on Windows');
|
$this->markTestSkipped('Can not verify chmod operations on Windows');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('root' === get_current_user()) {
|
if (!getenv('USER') || 'root' === getenv('USER')) {
|
||||||
$this->markTestSkipped('This test will fail if run under superuser');
|
$this->markTestSkipped('This test will fail if run under superuser');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +70,7 @@ class MimeTypeTest extends \PHPUnit_Framework_TestCase
|
|||||||
touch($path);
|
touch($path);
|
||||||
@chmod($path, 0333);
|
@chmod($path, 0333);
|
||||||
|
|
||||||
if (get_current_user() != 'root' && substr(sprintf('%o', fileperms($path)), -4) == '0333') {
|
if (substr(sprintf('%o', fileperms($path)), -4) == '0333') {
|
||||||
$this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException');
|
$this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException');
|
||||||
MimeTypeGuesser::getInstance()->guess($path);
|
MimeTypeGuesser::getInstance()->guess($path);
|
||||||
} else {
|
} else {
|
||||||
|
@ -209,12 +209,14 @@ class IntlDateFormatter
|
|||||||
|
|
||||||
// behave like the intl extension
|
// behave like the intl extension
|
||||||
$argumentError = null;
|
$argumentError = null;
|
||||||
if (PHP_VERSION_ID < 50304 && !is_int($timestamp)) {
|
if (!is_int($timestamp)) {
|
||||||
$argumentError = 'datefmt_format: takes either an array or an integer timestamp value ';
|
if (PHP_VERSION_ID < 50304) {
|
||||||
} elseif (PHP_VERSION_ID >= 50304 && !is_int($timestamp) && !$timestamp instanceof \DateTime) {
|
$argumentError = 'datefmt_format: takes either an array or an integer timestamp value ';
|
||||||
$argumentError = 'datefmt_format: takes either an array or an integer timestamp value or a DateTime object';
|
} elseif (!$timestamp instanceof \DateTime) {
|
||||||
if (PHP_VERSION_ID >= 50500 && !is_int($timestamp)) {
|
$argumentError = 'datefmt_format: takes either an array or an integer timestamp value or a DateTime object';
|
||||||
$argumentError = sprintf('datefmt_format: string \'%s\' is not numeric, which would be required for it to be a valid date', $timestamp);
|
if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
|
||||||
|
$argumentError = sprintf('datefmt_format: string \'%s\' is not numeric, which would be required for it to be a valid date', $timestamp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,7 +378,7 @@ class IntlDateFormatter
|
|||||||
}
|
}
|
||||||
|
|
||||||
// In PHP 5.5 default timezone depends on `date_default_timezone_get()` method
|
// In PHP 5.5 default timezone depends on `date_default_timezone_get()` method
|
||||||
if (PHP_VERSION_ID >= 50500) {
|
if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
|
||||||
return date_default_timezone_get();
|
return date_default_timezone_get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -541,7 +543,7 @@ class IntlDateFormatter
|
|||||||
{
|
{
|
||||||
if (null === $timeZoneId) {
|
if (null === $timeZoneId) {
|
||||||
// In PHP 5.5 if $timeZoneId is null it fallbacks to `date_default_timezone_get()` method
|
// In PHP 5.5 if $timeZoneId is null it fallbacks to `date_default_timezone_get()` method
|
||||||
if (PHP_VERSION_ID >= 50500) {
|
if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
|
||||||
$timeZoneId = date_default_timezone_get();
|
$timeZoneId = date_default_timezone_get();
|
||||||
} else {
|
} else {
|
||||||
// TODO: changes were made to ext/intl in PHP 5.4.4 release that need to be investigated since it will
|
// TODO: changes were made to ext/intl in PHP 5.4.4 release that need to be investigated since it will
|
||||||
@ -568,8 +570,16 @@ class IntlDateFormatter
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->dateTimeZone = new \DateTimeZone($timeZoneId);
|
$this->dateTimeZone = new \DateTimeZone($timeZoneId);
|
||||||
|
if ('GMT' !== $timeZoneId && $this->dateTimeZone->getName() !== $timeZoneId) {
|
||||||
|
$timeZoneId = $timeZone = $this->getTimeZoneId();
|
||||||
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->dateTimeZone = new \DateTimeZone('UTC');
|
if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
|
||||||
|
$timeZoneId = $timeZone = $this->getTimeZoneId();
|
||||||
|
} else {
|
||||||
|
$timeZoneId = 'UTC';
|
||||||
|
}
|
||||||
|
$this->dateTimeZone = new \DateTimeZone($timeZoneId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->timeZoneId = $timeZone;
|
$this->timeZoneId = $timeZone;
|
||||||
@ -635,7 +645,7 @@ class IntlDateFormatter
|
|||||||
if (self::NONE !== $this->timetype) {
|
if (self::NONE !== $this->timetype) {
|
||||||
$patternParts[] = $this->defaultTimeFormats[$this->timetype];
|
$patternParts[] = $this->defaultTimeFormats[$this->timetype];
|
||||||
}
|
}
|
||||||
$pattern = implode(' ', $patternParts);
|
$pattern = implode(', ', $patternParts);
|
||||||
|
|
||||||
return $pattern;
|
return $pattern;
|
||||||
}
|
}
|
||||||
|
@ -520,22 +520,30 @@ class NumberFormatter
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
preg_match('/^([^0-9\-\.]{0,})(.*)/', $value, $matches);
|
$groupSep = $this->getAttribute(self::GROUPING_USED) ? ',' : '';
|
||||||
|
|
||||||
// Any string before the numeric value causes error in the parsing
|
// Any string before the numeric value causes error in the parsing
|
||||||
if (isset($matches[1]) && !empty($matches[1])) {
|
if (preg_match("/^-?(?:\.\d++|([\d{$groupSep}]++)(?:\.\d++)?)/", $value, $matches)) {
|
||||||
|
$value = $matches[0];
|
||||||
|
$position = strlen($value);
|
||||||
|
if ($error = $groupSep && isset($matches[1]) && !preg_match('/^\d{1,3}+(?:(?:,\d{3})++|\d*+)$/', $matches[1])) {
|
||||||
|
$position -= strlen(preg_replace('/^\d{1,3}+(?:(?:,\d++)++|\d*+)/', '', $matches[1]));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$error = 1;
|
||||||
|
$position = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($error) {
|
||||||
IntlGlobals::setError(IntlGlobals::U_PARSE_ERROR, 'Number parsing failed');
|
IntlGlobals::setError(IntlGlobals::U_PARSE_ERROR, 'Number parsing failed');
|
||||||
$this->errorCode = IntlGlobals::getErrorCode();
|
$this->errorCode = IntlGlobals::getErrorCode();
|
||||||
$this->errorMessage = IntlGlobals::getErrorMessage();
|
$this->errorMessage = IntlGlobals::getErrorMessage();
|
||||||
$position = 0;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
preg_match('/^[0-9\-\.\,]*/', $value, $matches);
|
$value = str_replace(',', '', $value);
|
||||||
$value = preg_replace('/[^0-9\.\-]/', '', $matches[0]);
|
|
||||||
$value = $this->convertValueDataType($value, $type);
|
$value = $this->convertValueDataType($value, $type);
|
||||||
$position = strlen($matches[0]);
|
|
||||||
|
|
||||||
// behave like the intl extension
|
// behave like the intl extension
|
||||||
$this->resetError();
|
$this->resetError();
|
||||||
|
@ -38,11 +38,16 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
$formatter = $this->getDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT);
|
$formatter = $this->getDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT);
|
||||||
|
|
||||||
// In PHP 5.5 default timezone depends on `date_default_timezone_get()` method
|
// In PHP 5.5 default timezone depends on `date_default_timezone_get()` method
|
||||||
if (PHP_VERSION_ID >= 50500) {
|
if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
|
||||||
$this->assertEquals(date_default_timezone_get(), $formatter->getTimeZoneId());
|
$this->assertEquals(date_default_timezone_get(), $formatter->getTimeZoneId());
|
||||||
} else {
|
} else {
|
||||||
$this->assertNull($formatter->getTimeZoneId());
|
$this->assertNull($formatter->getTimeZoneId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$this->getDateTime(0, $formatter->getTimeZoneId())->format('M j, Y, g:i A'),
|
||||||
|
$formatter->format(0)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -270,7 +275,7 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function formatErrorProvider()
|
public function formatErrorProvider()
|
||||||
{
|
{
|
||||||
// With PHP 5.5 IntlDateFormatter accepts empty values ('0')
|
// With PHP 5.5 IntlDateFormatter accepts empty values ('0')
|
||||||
if (PHP_VERSION_ID >= 50500) {
|
if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
|
||||||
return array(
|
return array(
|
||||||
array('y-M-d', 'foobar', 'datefmt_format: string \'foobar\' is not numeric, which would be required for it to be a valid date: U_ILLEGAL_ARGUMENT_ERROR'),
|
array('y-M-d', 'foobar', 'datefmt_format: string \'foobar\' is not numeric, which would be required for it to be a valid date: U_ILLEGAL_ARGUMENT_ERROR'),
|
||||||
);
|
);
|
||||||
@ -327,7 +332,7 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
// As of PHP 5.5, intl ext no longer fallbacks invalid time zones to UTC
|
// As of PHP 5.5, intl ext no longer fallbacks invalid time zones to UTC
|
||||||
if (PHP_VERSION_ID < 50500) {
|
if (PHP_VERSION_ID < 50500 && !(extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
|
||||||
// When time zone not exists, uses UTC by default
|
// When time zone not exists, uses UTC by default
|
||||||
$data[] = array(0, 'Foo/Bar', '1970-01-01 00:00:00');
|
$data[] = array(0, 'Foo/Bar', '1970-01-01 00:00:00');
|
||||||
$data[] = array(0, 'UTC+04:30', '1970-01-01 00:00:00');
|
$data[] = array(0, 'UTC+04:30', '1970-01-01 00:00:00');
|
||||||
@ -341,7 +346,7 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$formatter = $this->getDefaultDateFormatter('zzzz');
|
$formatter = $this->getDefaultDateFormatter('zzzz');
|
||||||
|
|
||||||
if (PHP_VERSION_ID >= 50500) {
|
if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
|
||||||
$formatter->setTimeZone('GMT+03:00');
|
$formatter->setTimeZone('GMT+03:00');
|
||||||
} else {
|
} else {
|
||||||
$formatter->setTimeZoneId('GMT+03:00');
|
$formatter->setTimeZoneId('GMT+03:00');
|
||||||
@ -354,7 +359,7 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$formatter = $this->getDefaultDateFormatter('zzzz');
|
$formatter = $this->getDefaultDateFormatter('zzzz');
|
||||||
|
|
||||||
if (PHP_VERSION_ID >= 50500) {
|
if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
|
||||||
$formatter->setTimeZone('GMT+00:30');
|
$formatter->setTimeZone('GMT+00:30');
|
||||||
} else {
|
} else {
|
||||||
$formatter->setTimeZoneId('GMT+00:30');
|
$formatter->setTimeZoneId('GMT+00:30');
|
||||||
@ -367,7 +372,7 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$formatter = $this->getDefaultDateFormatter('zzzz');
|
$formatter = $this->getDefaultDateFormatter('zzzz');
|
||||||
|
|
||||||
if (PHP_VERSION_ID >= 50500) {
|
if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
|
||||||
$formatter->setTimeZone('Pacific/Fiji');
|
$formatter->setTimeZone('Pacific/Fiji');
|
||||||
} else {
|
} else {
|
||||||
$formatter->setTimeZoneId('Pacific/Fiji');
|
$formatter->setTimeZoneId('Pacific/Fiji');
|
||||||
@ -404,7 +409,7 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testFormatWithIntlTimeZone()
|
public function testFormatWithIntlTimeZone()
|
||||||
{
|
{
|
||||||
if (PHP_VERSION_ID < 50500) {
|
if (PHP_VERSION_ID < 50500 && !(extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
|
||||||
$this->markTestSkipped('Only in PHP 5.5+ IntlDateFormatter allows to use DateTimeZone objects.');
|
$this->markTestSkipped('Only in PHP 5.5+ IntlDateFormatter allows to use DateTimeZone objects.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,7 +424,7 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testFormatWithTimezoneFromEnvironmentVariable()
|
public function testFormatWithTimezoneFromEnvironmentVariable()
|
||||||
{
|
{
|
||||||
if (PHP_VERSION_ID >= 50500) {
|
if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
|
||||||
$this->markTestSkipped('IntlDateFormatter in PHP 5.5 no longer depends on TZ environment.');
|
$this->markTestSkipped('IntlDateFormatter in PHP 5.5 no longer depends on TZ environment.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -442,7 +447,7 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testFormatWithTimezoneFromPhp()
|
public function testFormatWithTimezoneFromPhp()
|
||||||
{
|
{
|
||||||
if (PHP_VERSION_ID < 50500) {
|
if (PHP_VERSION_ID < 50500 && !(extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
|
||||||
$this->markTestSkipped('Only in PHP 5.5 IntlDateFormatter depends on default timezone (`date_default_timezone_get()`).');
|
$this->markTestSkipped('Only in PHP 5.5 IntlDateFormatter depends on default timezone (`date_default_timezone_get()`).');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -873,7 +878,7 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$formatter = $this->getDefaultDateFormatter();
|
$formatter = $this->getDefaultDateFormatter();
|
||||||
|
|
||||||
if (PHP_VERSION_ID >= 50500) {
|
if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
|
||||||
$formatter->setTimeZone($timeZoneId);
|
$formatter->setTimeZone($timeZoneId);
|
||||||
} else {
|
} else {
|
||||||
$formatter->setTimeZoneId($timeZoneId);
|
$formatter->setTimeZoneId($timeZoneId);
|
||||||
@ -884,15 +889,17 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function setTimeZoneIdProvider()
|
public function setTimeZoneIdProvider()
|
||||||
{
|
{
|
||||||
|
$isPhp55 = PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'));
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
array('UTC', 'UTC'),
|
array('UTC', 'UTC'),
|
||||||
array('GMT', 'GMT'),
|
array('GMT', 'GMT'),
|
||||||
array('GMT-03:00', 'GMT-03:00'),
|
array('GMT-03:00', 'GMT-03:00'),
|
||||||
array('Europe/Zurich', 'Europe/Zurich'),
|
array('Europe/Zurich', 'Europe/Zurich'),
|
||||||
array('GMT-0300', 'GMT-0300'),
|
array(null, $isPhp55 ? date_default_timezone_get() : null),
|
||||||
array('Foo/Bar', 'Foo/Bar'),
|
array('Foo/Bar', $isPhp55 ? 'UTC' : 'Foo/Bar'),
|
||||||
array('GMT+00:AA', 'GMT+00:AA'),
|
array('GMT+00:AA', $isPhp55 ? 'UTC' : 'GMT+00:AA'),
|
||||||
array('GMT+00AA', 'GMT+00AA'),
|
array('GMT+00AA', $isPhp55 ? 'UTC' : 'GMT+00AA'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -905,7 +912,9 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$dateTime = new \DateTime();
|
$dateTime = new \DateTime();
|
||||||
$dateTime->setTimestamp(null === $timestamp ? time() : $timestamp);
|
$dateTime->setTimestamp(null === $timestamp ? time() : $timestamp);
|
||||||
$dateTime->setTimezone(new \DateTimeZone($timeZone));
|
if (null !== $timeZone) {
|
||||||
|
$dateTime->setTimezone(new \DateTimeZone($timeZone));
|
||||||
|
}
|
||||||
|
|
||||||
return $dateTime;
|
return $dateTime;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,11 @@ class IntlDateFormatterTest extends AbstractIntlDateFormatterTest
|
|||||||
|
|
||||||
protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null)
|
protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null)
|
||||||
{
|
{
|
||||||
return new \IntlDateFormatter($locale, $datetype, $timetype, $timezone, $calendar, $pattern);
|
if (!$formatter = new \IntlDateFormatter($locale, $datetype, $timetype, $timezone, $calendar, $pattern)) {
|
||||||
|
throw new \InvalidArgumentException(intl_get_error_message());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $formatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getIntlErrorMessage()
|
protected function getIntlErrorMessage()
|
||||||
|
@ -506,10 +506,11 @@ abstract class AbstractNumberFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
/**
|
/**
|
||||||
* @dataProvider parseProvider
|
* @dataProvider parseProvider
|
||||||
*/
|
*/
|
||||||
public function testParse($value, $expected, $message, $expectedPosition)
|
public function testParse($value, $expected, $message, $expectedPosition, $groupingUsed = true)
|
||||||
{
|
{
|
||||||
$position = 0;
|
$position = 0;
|
||||||
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
|
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
|
||||||
|
$formatter->setAttribute(NumberFormatter::GROUPING_USED, $groupingUsed);
|
||||||
$parsedValue = $formatter->parse($value, NumberFormatter::TYPE_DOUBLE, $position);
|
$parsedValue = $formatter->parse($value, NumberFormatter::TYPE_DOUBLE, $position);
|
||||||
$this->assertSame($expected, $parsedValue, $message);
|
$this->assertSame($expected, $parsedValue, $message);
|
||||||
$this->assertSame($expectedPosition, $position, $message);
|
$this->assertSame($expectedPosition, $position, $message);
|
||||||
@ -535,6 +536,11 @@ abstract class AbstractNumberFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
return array(
|
return array(
|
||||||
array('prefix1', false, '->parse() does not parse a number with a string prefix.', 0),
|
array('prefix1', false, '->parse() does not parse a number with a string prefix.', 0),
|
||||||
array('1.4suffix', (float) 1.4, '->parse() parses a number with a string suffix.', 3),
|
array('1.4suffix', (float) 1.4, '->parse() parses a number with a string suffix.', 3),
|
||||||
|
array('-.4suffix', (float) -0.4, '->parse() parses a negative dot float with suffix.', 3),
|
||||||
|
array('-123,4', false, '->parse() does not parse when invalid grouping used.', 6),
|
||||||
|
array('-1234,567', false, '->parse() does not parse when invalid grouping used.', 5),
|
||||||
|
array('-123,,456', false, '->parse() does not parse when invalid grouping used.', 4),
|
||||||
|
array('-123,,456', -123.0, '->parse() parses when grouping is disabled.', 4, false),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -543,8 +543,10 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$process = $this->getProcess(self::$phpBin.' -r "sleep(1);"');
|
$process = $this->getProcess(self::$phpBin.' -r "sleep(1);"');
|
||||||
$process->start();
|
$process->start();
|
||||||
|
|
||||||
|
$this->assertFalse($process->isSuccessful());
|
||||||
|
|
||||||
while ($process->isRunning()) {
|
while ($process->isRunning()) {
|
||||||
$this->assertFalse($process->isSuccessful());
|
|
||||||
usleep(300000);
|
usleep(300000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,23 +40,25 @@ class LengthValidator extends ConstraintValidator
|
|||||||
$charset = 'UTF-8';
|
$charset = 'UTF-8';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (function_exists('iconv_strlen')) {
|
if ('UTF-8' === $charset) {
|
||||||
$length = @iconv_strlen($stringValue, $constraint->charset);
|
if (!preg_match('//u', $stringValue)) {
|
||||||
$invalidCharset = false === $length;
|
$invalidCharset = true;
|
||||||
|
} elseif (function_exists('utf8_decode')) {
|
||||||
|
$length = strlen(utf8_decode($stringValue));
|
||||||
|
} else {
|
||||||
|
preg_replace('/./u', '', $stringValue, -1, $length);
|
||||||
|
}
|
||||||
} elseif (function_exists('mb_strlen')) {
|
} elseif (function_exists('mb_strlen')) {
|
||||||
if (mb_check_encoding($stringValue, $constraint->charset)) {
|
if (@mb_check_encoding($stringValue, $constraint->charset)) {
|
||||||
$length = mb_strlen($stringValue, $constraint->charset);
|
$length = mb_strlen($stringValue, $constraint->charset);
|
||||||
} else {
|
} else {
|
||||||
$invalidCharset = true;
|
$invalidCharset = true;
|
||||||
}
|
}
|
||||||
} elseif ('UTF-8' !== $charset) {
|
} elseif (function_exists('iconv_strlen')) {
|
||||||
$length = strlen($stringValue);
|
$length = @iconv_strlen($stringValue, $constraint->charset);
|
||||||
} elseif (!preg_match('//u', $stringValue)) {
|
$invalidCharset = false === $length;
|
||||||
$invalidCharset = true;
|
|
||||||
} elseif (function_exists('utf8_decode')) {
|
|
||||||
$length = strlen(utf8_decode($stringValue));
|
|
||||||
} else {
|
} else {
|
||||||
preg_replace('/./u', '', $stringValue, -1, $length);
|
$length = strlen($stringValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($invalidCharset) {
|
if ($invalidCharset) {
|
||||||
|
@ -14,6 +14,9 @@ namespace Symfony\Component\Validator\Tests\Constraints;
|
|||||||
use Symfony\Component\Validator\Constraints\Image;
|
use Symfony\Component\Validator\Constraints\Image;
|
||||||
use Symfony\Component\Validator\Constraints\ImageValidator;
|
use Symfony\Component\Validator\Constraints\ImageValidator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires extension fileinfo
|
||||||
|
*/
|
||||||
class ImageValidatorTest extends AbstractConstraintValidatorTest
|
class ImageValidatorTest extends AbstractConstraintValidatorTest
|
||||||
{
|
{
|
||||||
protected $context;
|
protected $context;
|
||||||
|
Reference in New Issue
Block a user