fixed CS
This commit is contained in:
parent
51a359c079
commit
18b9e45f4a
@ -16,7 +16,7 @@ namespace Symfony\Bridge\PhpUnit;
|
|||||||
*/
|
*/
|
||||||
class ClassExistsMock
|
class ClassExistsMock
|
||||||
{
|
{
|
||||||
private static $classes = array();
|
private static $classes = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the classes to be checked upon existence.
|
* Configures the classes to be checked upon existence.
|
||||||
@ -47,7 +47,7 @@ class ClassExistsMock
|
|||||||
{
|
{
|
||||||
$self = \get_called_class();
|
$self = \get_called_class();
|
||||||
|
|
||||||
$mockedNs = array(substr($class, 0, strrpos($class, '\\')));
|
$mockedNs = [substr($class, 0, strrpos($class, '\\'))];
|
||||||
if (0 < strpos($class, '\\Tests\\')) {
|
if (0 < strpos($class, '\\Tests\\')) {
|
||||||
$ns = str_replace('\\Tests\\', '\\', $class);
|
$ns = str_replace('\\Tests\\', '\\', $class);
|
||||||
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
|
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
|
||||||
@ -55,7 +55,7 @@ class ClassExistsMock
|
|||||||
$mockedNs[] = substr($class, 6, strrpos($class, '\\') - 6);
|
$mockedNs[] = substr($class, 6, strrpos($class, '\\') - 6);
|
||||||
}
|
}
|
||||||
foreach ($mockedNs as $ns) {
|
foreach ($mockedNs as $ns) {
|
||||||
foreach (array('class', 'interface', 'trait') as $type) {
|
foreach (['class', 'interface', 'trait'] as $type) {
|
||||||
if (\function_exists($ns.'\\'.$type.'_exists')) {
|
if (\function_exists($ns.'\\'.$type.'_exists')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -23,14 +23,14 @@ class ClassExistsMockTest extends TestCase
|
|||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
ClassExistsMock::withMockedClasses(array(
|
ClassExistsMock::withMockedClasses([
|
||||||
ExistingClass::class => false,
|
ExistingClass::class => false,
|
||||||
'NonExistingClass' => true,
|
'NonExistingClass' => true,
|
||||||
ExistingInterface::class => false,
|
ExistingInterface::class => false,
|
||||||
'NonExistingInterface' => true,
|
'NonExistingInterface' => true,
|
||||||
ExistingTrait::class => false,
|
ExistingTrait::class => false,
|
||||||
'NonExistingTrait' => true,
|
'NonExistingTrait' => true,
|
||||||
));
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testClassExists()
|
public function testClassExists()
|
||||||
|
@ -60,7 +60,7 @@ class Configuration implements ConfigurationInterface
|
|||||||
->enumNode('theme')
|
->enumNode('theme')
|
||||||
->info('Changes the color of the dump() output when rendered directly on the templating. "dark" (default) or "light"')
|
->info('Changes the color of the dump() output when rendered directly on the templating. "dark" (default) or "light"')
|
||||||
->example('dark')
|
->example('dark')
|
||||||
->values(array('dark', 'light'))
|
->values(['dark', 'light'])
|
||||||
->defaultValue('dark')
|
->defaultValue('dark')
|
||||||
->end()
|
->end()
|
||||||
->end()
|
->end()
|
||||||
|
@ -45,7 +45,7 @@ class DebugExtension extends Extension
|
|||||||
|
|
||||||
if (method_exists(HtmlDumper::class, 'setTheme') && 'dark' !== $config['theme']) {
|
if (method_exists(HtmlDumper::class, 'setTheme') && 'dark' !== $config['theme']) {
|
||||||
$container->getDefinition('var_dumper.html_dumper')
|
$container->getDefinition('var_dumper.html_dumper')
|
||||||
->addMethodCall('setTheme', array($config['theme']));
|
->addMethodCall('setTheme', [$config['theme']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $config['dump_destination']) {
|
if (null === $config['dump_destination']) {
|
||||||
@ -79,9 +79,9 @@ class DebugExtension extends Extension
|
|||||||
|
|
||||||
if (method_exists(CliDumper::class, 'setDisplayOptions')) {
|
if (method_exists(CliDumper::class, 'setDisplayOptions')) {
|
||||||
$container->getDefinition('var_dumper.cli_dumper')
|
$container->getDefinition('var_dumper.cli_dumper')
|
||||||
->addMethodCall('setDisplayOptions', array(array(
|
->addMethodCall('setDisplayOptions', [[
|
||||||
'fileLinkFormat' => new Reference('debug.file_link_formatter', ContainerBuilder::IGNORE_ON_INVALID_REFERENCE),
|
'fileLinkFormat' => new Reference('debug.file_link_formatter', ContainerBuilder::IGNORE_ON_INVALID_REFERENCE),
|
||||||
)))
|
]])
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ abstract class Client
|
|||||||
{
|
{
|
||||||
protected $history;
|
protected $history;
|
||||||
protected $cookieJar;
|
protected $cookieJar;
|
||||||
protected $server = array();
|
protected $server = [];
|
||||||
protected $internalRequest;
|
protected $internalRequest;
|
||||||
protected $request;
|
protected $request;
|
||||||
protected $internalResponse;
|
protected $internalResponse;
|
||||||
@ -44,7 +44,7 @@ abstract class Client
|
|||||||
|
|
||||||
private $maxRedirects = -1;
|
private $maxRedirects = -1;
|
||||||
private $redirectCount = 0;
|
private $redirectCount = 0;
|
||||||
private $redirects = array();
|
private $redirects = [];
|
||||||
private $isMainRequest = true;
|
private $isMainRequest = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,7 +52,7 @@ abstract class Client
|
|||||||
* @param History $history A History instance to store the browser history
|
* @param History $history A History instance to store the browser history
|
||||||
* @param CookieJar $cookieJar A CookieJar instance to store the cookies
|
* @param CookieJar $cookieJar A CookieJar instance to store the cookies
|
||||||
*/
|
*/
|
||||||
public function __construct(array $server = array(), History $history = null, CookieJar $cookieJar = null)
|
public function __construct(array $server = [], History $history = null, CookieJar $cookieJar = null)
|
||||||
{
|
{
|
||||||
$this->setServerParameters($server);
|
$this->setServerParameters($server);
|
||||||
$this->history = $history ?: new History();
|
$this->history = $history ?: new History();
|
||||||
@ -131,9 +131,9 @@ abstract class Client
|
|||||||
*/
|
*/
|
||||||
public function setServerParameters(array $server)
|
public function setServerParameters(array $server)
|
||||||
{
|
{
|
||||||
$this->server = array_merge(array(
|
$this->server = array_merge([
|
||||||
'HTTP_USER_AGENT' => 'Symfony BrowserKit',
|
'HTTP_USER_AGENT' => 'Symfony BrowserKit',
|
||||||
), $server);
|
], $server);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -160,7 +160,7 @@ abstract class Client
|
|||||||
return isset($this->server[$key]) ? $this->server[$key] : $default;
|
return isset($this->server[$key]) ? $this->server[$key] : $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function xmlHttpRequest(string $method, string $uri, array $parameters = array(), array $files = array(), array $server = array(), string $content = null, bool $changeHistory = true): Crawler
|
public function xmlHttpRequest(string $method, string $uri, array $parameters = [], array $files = [], array $server = [], string $content = null, bool $changeHistory = true): Crawler
|
||||||
{
|
{
|
||||||
$this->setServerParameter('HTTP_X_REQUESTED_WITH', 'XMLHttpRequest');
|
$this->setServerParameter('HTTP_X_REQUESTED_WITH', 'XMLHttpRequest');
|
||||||
|
|
||||||
@ -313,14 +313,14 @@ abstract class Client
|
|||||||
*
|
*
|
||||||
* @return Crawler
|
* @return Crawler
|
||||||
*/
|
*/
|
||||||
public function submit(Form $form, array $values = array()/*, array $serverParameters = array()*/)
|
public function submit(Form $form, array $values = []/*, array $serverParameters = array()*/)
|
||||||
{
|
{
|
||||||
if (\func_num_args() < 3 && __CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
|
if (\func_num_args() < 3 && __CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
|
||||||
@trigger_error(sprintf('The "%s()" method will have a new "array $serverParameters = array()" argument in version 5.0, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
|
@trigger_error(sprintf('The "%s()" method will have a new "array $serverParameters = array()" argument in version 5.0, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
$form->setValues($values);
|
$form->setValues($values);
|
||||||
$serverParameters = 2 < \func_num_args() ? func_get_arg(2) : array();
|
$serverParameters = 2 < \func_num_args() ? func_get_arg(2) : [];
|
||||||
|
|
||||||
return $this->request($form->getMethod(), $form->getUri(), $form->getPhpValues(), $form->getPhpFiles(), $serverParameters);
|
return $this->request($form->getMethod(), $form->getUri(), $form->getPhpValues(), $form->getPhpFiles(), $serverParameters);
|
||||||
}
|
}
|
||||||
@ -334,7 +334,7 @@ abstract class Client
|
|||||||
* @param string $method The HTTP method used to submit the form
|
* @param string $method The HTTP method used to submit the form
|
||||||
* @param array $serverParameters These values override the ones stored in $_SERVER (HTTP headers must include a HTTP_ prefix as PHP does)
|
* @param array $serverParameters These values override the ones stored in $_SERVER (HTTP headers must include a HTTP_ prefix as PHP does)
|
||||||
*/
|
*/
|
||||||
public function submitForm(string $button, array $fieldValues = array(), string $method = 'POST', array $serverParameters = array()): Crawler
|
public function submitForm(string $button, array $fieldValues = [], string $method = 'POST', array $serverParameters = []): Crawler
|
||||||
{
|
{
|
||||||
if (null === $this->crawler) {
|
if (null === $this->crawler) {
|
||||||
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
|
throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
|
||||||
@ -343,7 +343,7 @@ abstract class Client
|
|||||||
$buttonNode = $this->crawler->selectButton($button);
|
$buttonNode = $this->crawler->selectButton($button);
|
||||||
$form = $buttonNode->form($fieldValues, $method);
|
$form = $buttonNode->form($fieldValues, $method);
|
||||||
|
|
||||||
return $this->submit($form, array(), $serverParameters);
|
return $this->submit($form, [], $serverParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -359,7 +359,7 @@ abstract class Client
|
|||||||
*
|
*
|
||||||
* @return Crawler
|
* @return Crawler
|
||||||
*/
|
*/
|
||||||
public function request(string $method, string $uri, array $parameters = array(), array $files = array(), array $server = array(), string $content = null, bool $changeHistory = true)
|
public function request(string $method, string $uri, array $parameters = [], array $files = [], array $server = [], string $content = null, bool $changeHistory = true)
|
||||||
{
|
{
|
||||||
if ($this->isMainRequest) {
|
if ($this->isMainRequest) {
|
||||||
$this->redirectCount = 0;
|
$this->redirectCount = 0;
|
||||||
@ -455,7 +455,7 @@ abstract class Client
|
|||||||
if (file_exists($deprecationsFile)) {
|
if (file_exists($deprecationsFile)) {
|
||||||
$deprecations = file_get_contents($deprecationsFile);
|
$deprecations = file_get_contents($deprecationsFile);
|
||||||
unlink($deprecationsFile);
|
unlink($deprecationsFile);
|
||||||
foreach ($deprecations ? unserialize($deprecations) : array() as $deprecation) {
|
foreach ($deprecations ? unserialize($deprecations) : [] as $deprecation) {
|
||||||
if ($deprecation[0]) {
|
if ($deprecation[0]) {
|
||||||
@trigger_error($deprecation[1], E_USER_DEPRECATED);
|
@trigger_error($deprecation[1], E_USER_DEPRECATED);
|
||||||
} else {
|
} else {
|
||||||
@ -599,9 +599,9 @@ abstract class Client
|
|||||||
|
|
||||||
$request = $this->internalRequest;
|
$request = $this->internalRequest;
|
||||||
|
|
||||||
if (\in_array($this->internalResponse->getStatusCode(), array(301, 302, 303))) {
|
if (\in_array($this->internalResponse->getStatusCode(), [301, 302, 303])) {
|
||||||
$method = 'GET';
|
$method = 'GET';
|
||||||
$files = array();
|
$files = [];
|
||||||
$content = null;
|
$content = null;
|
||||||
} else {
|
} else {
|
||||||
$method = $request->getMethod();
|
$method = $request->getMethod();
|
||||||
@ -611,7 +611,7 @@ abstract class Client
|
|||||||
|
|
||||||
if ('GET' === strtoupper($method)) {
|
if ('GET' === strtoupper($method)) {
|
||||||
// Don't forward parameters for GET request as it should reach the redirection URI
|
// Don't forward parameters for GET request as it should reach the redirection URI
|
||||||
$parameters = array();
|
$parameters = [];
|
||||||
} else {
|
} else {
|
||||||
$parameters = $request->getParameters();
|
$parameters = $request->getParameters();
|
||||||
}
|
}
|
||||||
@ -634,7 +634,7 @@ abstract class Client
|
|||||||
private function getMetaRefreshUrl(): ?string
|
private function getMetaRefreshUrl(): ?string
|
||||||
{
|
{
|
||||||
$metaRefresh = $this->getCrawler()->filter('head meta[http-equiv="refresh"]');
|
$metaRefresh = $this->getCrawler()->filter('head meta[http-equiv="refresh"]');
|
||||||
foreach ($metaRefresh->extract(array('content')) as $content) {
|
foreach ($metaRefresh->extract(['content']) as $content) {
|
||||||
if (preg_match('/^\s*0\s*;\s*URL\s*=\s*(?|\'([^\']++)|"([^"]++)|([^\'"].*))/i', $content, $m)) {
|
if (preg_match('/^\s*0\s*;\s*URL\s*=\s*(?|\'([^\']++)|"([^"]++)|([^\'"].*))/i', $content, $m)) {
|
||||||
return str_replace("\t\r\n", '', rtrim($m[1]));
|
return str_replace("\t\r\n", '', rtrim($m[1]));
|
||||||
}
|
}
|
||||||
|
@ -20,40 +20,40 @@ use Symfony\Component\Console\Exception\InvalidArgumentException;
|
|||||||
*/
|
*/
|
||||||
class OutputFormatterStyle implements OutputFormatterStyleInterface
|
class OutputFormatterStyle implements OutputFormatterStyleInterface
|
||||||
{
|
{
|
||||||
private static $availableForegroundColors = array(
|
private static $availableForegroundColors = [
|
||||||
'black' => array('set' => 30, 'unset' => 39),
|
'black' => ['set' => 30, 'unset' => 39],
|
||||||
'red' => array('set' => 31, 'unset' => 39),
|
'red' => ['set' => 31, 'unset' => 39],
|
||||||
'green' => array('set' => 32, 'unset' => 39),
|
'green' => ['set' => 32, 'unset' => 39],
|
||||||
'yellow' => array('set' => 33, 'unset' => 39),
|
'yellow' => ['set' => 33, 'unset' => 39],
|
||||||
'blue' => array('set' => 34, 'unset' => 39),
|
'blue' => ['set' => 34, 'unset' => 39],
|
||||||
'magenta' => array('set' => 35, 'unset' => 39),
|
'magenta' => ['set' => 35, 'unset' => 39],
|
||||||
'cyan' => array('set' => 36, 'unset' => 39),
|
'cyan' => ['set' => 36, 'unset' => 39],
|
||||||
'white' => array('set' => 37, 'unset' => 39),
|
'white' => ['set' => 37, 'unset' => 39],
|
||||||
'default' => array('set' => 39, 'unset' => 39),
|
'default' => ['set' => 39, 'unset' => 39],
|
||||||
);
|
];
|
||||||
private static $availableBackgroundColors = array(
|
private static $availableBackgroundColors = [
|
||||||
'black' => array('set' => 40, 'unset' => 49),
|
'black' => ['set' => 40, 'unset' => 49],
|
||||||
'red' => array('set' => 41, 'unset' => 49),
|
'red' => ['set' => 41, 'unset' => 49],
|
||||||
'green' => array('set' => 42, 'unset' => 49),
|
'green' => ['set' => 42, 'unset' => 49],
|
||||||
'yellow' => array('set' => 43, 'unset' => 49),
|
'yellow' => ['set' => 43, 'unset' => 49],
|
||||||
'blue' => array('set' => 44, 'unset' => 49),
|
'blue' => ['set' => 44, 'unset' => 49],
|
||||||
'magenta' => array('set' => 45, 'unset' => 49),
|
'magenta' => ['set' => 45, 'unset' => 49],
|
||||||
'cyan' => array('set' => 46, 'unset' => 49),
|
'cyan' => ['set' => 46, 'unset' => 49],
|
||||||
'white' => array('set' => 47, 'unset' => 49),
|
'white' => ['set' => 47, 'unset' => 49],
|
||||||
'default' => array('set' => 49, 'unset' => 49),
|
'default' => ['set' => 49, 'unset' => 49],
|
||||||
);
|
];
|
||||||
private static $availableOptions = array(
|
private static $availableOptions = [
|
||||||
'bold' => array('set' => 1, 'unset' => 22),
|
'bold' => ['set' => 1, 'unset' => 22],
|
||||||
'underscore' => array('set' => 4, 'unset' => 24),
|
'underscore' => ['set' => 4, 'unset' => 24],
|
||||||
'blink' => array('set' => 5, 'unset' => 25),
|
'blink' => ['set' => 5, 'unset' => 25],
|
||||||
'reverse' => array('set' => 7, 'unset' => 27),
|
'reverse' => ['set' => 7, 'unset' => 27],
|
||||||
'conceal' => array('set' => 8, 'unset' => 28),
|
'conceal' => ['set' => 8, 'unset' => 28],
|
||||||
);
|
];
|
||||||
|
|
||||||
private $foreground;
|
private $foreground;
|
||||||
private $background;
|
private $background;
|
||||||
private $href;
|
private $href;
|
||||||
private $options = array();
|
private $options = [];
|
||||||
private $handlesHrefGracefully;
|
private $handlesHrefGracefully;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,7 +63,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
|||||||
* @param string|null $background The style background color name
|
* @param string|null $background The style background color name
|
||||||
* @param array $options The style options
|
* @param array $options The style options
|
||||||
*/
|
*/
|
||||||
public function __construct(string $foreground = null, string $background = null, array $options = array())
|
public function __construct(string $foreground = null, string $background = null, array $options = [])
|
||||||
{
|
{
|
||||||
if (null !== $foreground) {
|
if (null !== $foreground) {
|
||||||
$this->setForeground($foreground);
|
$this->setForeground($foreground);
|
||||||
@ -167,7 +167,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
|||||||
*/
|
*/
|
||||||
public function setOptions(array $options)
|
public function setOptions(array $options)
|
||||||
{
|
{
|
||||||
$this->options = array();
|
$this->options = [];
|
||||||
|
|
||||||
foreach ($options as $option) {
|
foreach ($options as $option) {
|
||||||
$this->setOption($option);
|
$this->setOption($option);
|
||||||
@ -183,8 +183,8 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
|||||||
*/
|
*/
|
||||||
public function apply($text)
|
public function apply($text)
|
||||||
{
|
{
|
||||||
$setCodes = array();
|
$setCodes = [];
|
||||||
$unsetCodes = array();
|
$unsetCodes = [];
|
||||||
|
|
||||||
if (null === $this->handlesHrefGracefully) {
|
if (null === $this->handlesHrefGracefully) {
|
||||||
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR');
|
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR');
|
||||||
|
@ -256,15 +256,15 @@ class OutputFormatterTest extends TestCase
|
|||||||
|
|
||||||
public function provideDecoratedAndNonDecoratedOutput()
|
public function provideDecoratedAndNonDecoratedOutput()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array('<error>some error</error>', 'some error', "\033[37;41msome error\033[39;49m"),
|
['<error>some error</error>', 'some error', "\033[37;41msome error\033[39;49m"],
|
||||||
array('<info>some info</info>', 'some info', "\033[32msome info\033[39m"),
|
['<info>some info</info>', 'some info', "\033[32msome info\033[39m"],
|
||||||
array('<comment>some comment</comment>', 'some comment', "\033[33msome comment\033[39m"),
|
['<comment>some comment</comment>', 'some comment', "\033[33msome comment\033[39m"],
|
||||||
array('<question>some question</question>', 'some question', "\033[30;46msome question\033[39;49m"),
|
['<question>some question</question>', 'some question', "\033[30;46msome question\033[39;49m"],
|
||||||
array('<fg=red>some text with inline style</>', 'some text with inline style', "\033[31msome text with inline style\033[39m"),
|
['<fg=red>some text with inline style</>', 'some text with inline style', "\033[31msome text with inline style\033[39m"],
|
||||||
array('<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', "\033]8;;idea://open/?file=/path/SomeFile.php&line=12\033\\some URL\033]8;;\033\\"),
|
['<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', "\033]8;;idea://open/?file=/path/SomeFile.php&line=12\033\\some URL\033]8;;\033\\"],
|
||||||
array('<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', 'some URL', 'JetBrains-JediTerm'),
|
['<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', 'some URL', 'JetBrains-JediTerm'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testContentWithLineBreaks()
|
public function testContentWithLineBreaks()
|
||||||
|
@ -29,17 +29,17 @@ class DebugClassLoader
|
|||||||
{
|
{
|
||||||
private $classLoader;
|
private $classLoader;
|
||||||
private $isFinder;
|
private $isFinder;
|
||||||
private $loaded = array();
|
private $loaded = [];
|
||||||
private static $caseCheck;
|
private static $caseCheck;
|
||||||
private static $checkedClasses = array();
|
private static $checkedClasses = [];
|
||||||
private static $final = array();
|
private static $final = [];
|
||||||
private static $finalMethods = array();
|
private static $finalMethods = [];
|
||||||
private static $deprecated = array();
|
private static $deprecated = [];
|
||||||
private static $internal = array();
|
private static $internal = [];
|
||||||
private static $internalMethods = array();
|
private static $internalMethods = [];
|
||||||
private static $annotatedParameters = array();
|
private static $annotatedParameters = [];
|
||||||
private static $darwinCache = array('/' => array('/', array()));
|
private static $darwinCache = ['/' => ['/', []]];
|
||||||
private static $method = array();
|
private static $method = [];
|
||||||
|
|
||||||
public function __construct(callable $classLoader)
|
public function __construct(callable $classLoader)
|
||||||
{
|
{
|
||||||
@ -99,7 +99,7 @@ class DebugClassLoader
|
|||||||
|
|
||||||
foreach ($functions as $function) {
|
foreach ($functions as $function) {
|
||||||
if (!\is_array($function) || !$function[0] instanceof self) {
|
if (!\is_array($function) || !$function[0] instanceof self) {
|
||||||
$function = array(new static($function), 'loadClass');
|
$function = [new static($function), 'loadClass'];
|
||||||
}
|
}
|
||||||
|
|
||||||
spl_autoload_register($function);
|
spl_autoload_register($function);
|
||||||
@ -220,7 +220,7 @@ class DebugClassLoader
|
|||||||
|
|
||||||
public function checkAnnotations(\ReflectionClass $refl, $class)
|
public function checkAnnotations(\ReflectionClass $refl, $class)
|
||||||
{
|
{
|
||||||
$deprecations = array();
|
$deprecations = [];
|
||||||
|
|
||||||
// Don't trigger deprecations for classes in the same vendor
|
// Don't trigger deprecations for classes in the same vendor
|
||||||
if (2 > $len = 1 + (\strpos($class, '\\') ?: \strpos($class, '_'))) {
|
if (2 > $len = 1 + (\strpos($class, '\\') ?: \strpos($class, '_'))) {
|
||||||
@ -232,7 +232,7 @@ class DebugClassLoader
|
|||||||
|
|
||||||
// Detect annotations on the class
|
// Detect annotations on the class
|
||||||
if (false !== $doc = $refl->getDocComment()) {
|
if (false !== $doc = $refl->getDocComment()) {
|
||||||
foreach (array('final', 'deprecated', 'internal') as $annotation) {
|
foreach (['final', 'deprecated', 'internal'] as $annotation) {
|
||||||
if (false !== \strpos($doc, $annotation) && preg_match('#\n \* @'.$annotation.'(?:( .+?)\.?)?\r?\n \*(?: @|/$)#s', $doc, $notice)) {
|
if (false !== \strpos($doc, $annotation) && preg_match('#\n \* @'.$annotation.'(?:( .+?)\.?)?\r?\n \*(?: @|/$)#s', $doc, $notice)) {
|
||||||
self::${$annotation}[$class] = isset($notice[1]) ? preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]) : '';
|
self::${$annotation}[$class] = isset($notice[1]) ? preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]) : '';
|
||||||
}
|
}
|
||||||
@ -252,7 +252,7 @@ class DebugClassLoader
|
|||||||
$description .= '.';
|
$description .= '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self::$method[$class][] = array($class, $name, $static, $description);
|
self::$method[$class][] = [$class, $name, $static, $description];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -314,11 +314,11 @@ class DebugClassLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inherit @final, @internal and @param annotations for methods
|
// Inherit @final, @internal and @param annotations for methods
|
||||||
self::$finalMethods[$class] = array();
|
self::$finalMethods[$class] = [];
|
||||||
self::$internalMethods[$class] = array();
|
self::$internalMethods[$class] = [];
|
||||||
self::$annotatedParameters[$class] = array();
|
self::$annotatedParameters[$class] = [];
|
||||||
foreach ($parentAndOwnInterfaces as $use) {
|
foreach ($parentAndOwnInterfaces as $use) {
|
||||||
foreach (array('finalMethods', 'internalMethods', 'annotatedParameters') as $property) {
|
foreach (['finalMethods', 'internalMethods', 'annotatedParameters'] as $property) {
|
||||||
if (isset(self::${$property}[$use])) {
|
if (isset(self::${$property}[$use])) {
|
||||||
self::${$property}[$class] = self::${$property}[$class] ? self::${$property}[$use] + self::${$property}[$class] : self::${$property}[$use];
|
self::${$property}[$class] = self::${$property}[$class] ? self::${$property}[$use] + self::${$property}[$class] : self::${$property}[$use];
|
||||||
}
|
}
|
||||||
@ -346,7 +346,7 @@ class DebugClassLoader
|
|||||||
$doc = $method->getDocComment();
|
$doc = $method->getDocComment();
|
||||||
|
|
||||||
if (isset(self::$annotatedParameters[$class][$method->name])) {
|
if (isset(self::$annotatedParameters[$class][$method->name])) {
|
||||||
$definedParameters = array();
|
$definedParameters = [];
|
||||||
foreach ($method->getParameters() as $parameter) {
|
foreach ($method->getParameters() as $parameter) {
|
||||||
$definedParameters[$parameter->name] = true;
|
$definedParameters[$parameter->name] = true;
|
||||||
}
|
}
|
||||||
@ -364,10 +364,10 @@ class DebugClassLoader
|
|||||||
|
|
||||||
$finalOrInternal = false;
|
$finalOrInternal = false;
|
||||||
|
|
||||||
foreach (array('final', 'internal') as $annotation) {
|
foreach (['final', 'internal'] as $annotation) {
|
||||||
if (false !== \strpos($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$)#s', $doc, $notice)) {
|
if (false !== \strpos($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$)#s', $doc, $notice)) {
|
||||||
$message = isset($notice[1]) ? preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]) : '';
|
$message = isset($notice[1]) ? preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]) : '';
|
||||||
self::${$annotation.'Methods'}[$class][$method->name] = array($class, $message);
|
self::${$annotation.'Methods'}[$class][$method->name] = [$class, $message];
|
||||||
$finalOrInternal = true;
|
$finalOrInternal = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -379,7 +379,7 @@ class DebugClassLoader
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!isset(self::$annotatedParameters[$class][$method->name])) {
|
if (!isset(self::$annotatedParameters[$class][$method->name])) {
|
||||||
$definedParameters = array();
|
$definedParameters = [];
|
||||||
foreach ($method->getParameters() as $parameter) {
|
foreach ($method->getParameters() as $parameter) {
|
||||||
$definedParameters[$parameter->name] = true;
|
$definedParameters[$parameter->name] = true;
|
||||||
}
|
}
|
||||||
@ -425,7 +425,7 @@ class DebugClassLoader
|
|||||||
if (0 === substr_compare($real, $tail, -$tailLen, $tailLen, true)
|
if (0 === substr_compare($real, $tail, -$tailLen, $tailLen, true)
|
||||||
&& 0 !== substr_compare($real, $tail, -$tailLen, $tailLen, false)
|
&& 0 !== substr_compare($real, $tail, -$tailLen, $tailLen, false)
|
||||||
) {
|
) {
|
||||||
return array(substr($tail, -$tailLen + 1), substr($real, -$tailLen + 1), substr($real, 0, -$tailLen + 1));
|
return [substr($tail, -$tailLen + 1), substr($real, -$tailLen + 1), substr($real, 0, -$tailLen + 1)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,7 +455,7 @@ class DebugClassLoader
|
|||||||
$k = $kDir;
|
$k = $kDir;
|
||||||
$i = \strlen($dir) - 1;
|
$i = \strlen($dir) - 1;
|
||||||
while (!isset(self::$darwinCache[$k])) {
|
while (!isset(self::$darwinCache[$k])) {
|
||||||
self::$darwinCache[$k] = array($dir, array());
|
self::$darwinCache[$k] = [$dir, []];
|
||||||
self::$darwinCache[$dir] = &self::$darwinCache[$k];
|
self::$darwinCache[$dir] = &self::$darwinCache[$k];
|
||||||
|
|
||||||
while ('/' !== $dir[--$i]) {
|
while ('/' !== $dir[--$i]) {
|
||||||
|
@ -62,7 +62,7 @@ class PhpDumper extends Dumper
|
|||||||
private $variableCount;
|
private $variableCount;
|
||||||
private $inlinedDefinitions;
|
private $inlinedDefinitions;
|
||||||
private $serviceCalls;
|
private $serviceCalls;
|
||||||
private $reservedVariables = array('instance', 'class', 'this');
|
private $reservedVariables = ['instance', 'class', 'this'];
|
||||||
private $expressionLanguage;
|
private $expressionLanguage;
|
||||||
private $targetDirRegex;
|
private $targetDirRegex;
|
||||||
private $targetDirMaxMatches;
|
private $targetDirMaxMatches;
|
||||||
@ -73,14 +73,14 @@ class PhpDumper extends Dumper
|
|||||||
private $asFiles;
|
private $asFiles;
|
||||||
private $hotPathTag;
|
private $hotPathTag;
|
||||||
private $inlineRequires;
|
private $inlineRequires;
|
||||||
private $inlinedRequires = array();
|
private $inlinedRequires = [];
|
||||||
private $circularReferences = array();
|
private $circularReferences = [];
|
||||||
private $singleUsePrivateIds = array();
|
private $singleUsePrivateIds = [];
|
||||||
private $addThrow = false;
|
private $addThrow = false;
|
||||||
private $addGetService = false;
|
private $addGetService = false;
|
||||||
private $locatedIds = array();
|
private $locatedIds = [];
|
||||||
private $serviceLocatorTag;
|
private $serviceLocatorTag;
|
||||||
private $exportedVariables = array();
|
private $exportedVariables = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ProxyDumper
|
* @var ProxyDumper
|
||||||
@ -121,13 +121,13 @@ class PhpDumper extends Dumper
|
|||||||
*
|
*
|
||||||
* @throws EnvParameterException When an env var exists but has not been dumped
|
* @throws EnvParameterException When an env var exists but has not been dumped
|
||||||
*/
|
*/
|
||||||
public function dump(array $options = array())
|
public function dump(array $options = [])
|
||||||
{
|
{
|
||||||
$this->locatedIds = array();
|
$this->locatedIds = [];
|
||||||
$this->targetDirRegex = null;
|
$this->targetDirRegex = null;
|
||||||
$this->inlinedRequires = array();
|
$this->inlinedRequires = [];
|
||||||
$this->exportedVariables = array();
|
$this->exportedVariables = [];
|
||||||
$options = array_merge(array(
|
$options = array_merge([
|
||||||
'class' => 'ProjectServiceContainer',
|
'class' => 'ProjectServiceContainer',
|
||||||
'base_class' => 'Container',
|
'base_class' => 'Container',
|
||||||
'namespace' => '',
|
'namespace' => '',
|
||||||
@ -137,7 +137,7 @@ class PhpDumper extends Dumper
|
|||||||
'inline_class_loader_parameter' => 'container.dumper.inline_class_loader',
|
'inline_class_loader_parameter' => 'container.dumper.inline_class_loader',
|
||||||
'service_locator_tag' => 'container.service_locator',
|
'service_locator_tag' => 'container.service_locator',
|
||||||
'build_time' => time(),
|
'build_time' => time(),
|
||||||
), $options);
|
], $options);
|
||||||
|
|
||||||
$this->addThrow = $this->addGetService = false;
|
$this->addThrow = $this->addGetService = false;
|
||||||
$this->namespace = $options['namespace'];
|
$this->namespace = $options['namespace'];
|
||||||
@ -171,9 +171,9 @@ class PhpDumper extends Dumper
|
|||||||
}
|
}
|
||||||
|
|
||||||
(new AnalyzeServiceReferencesPass(false, !$this->getProxyDumper() instanceof NullDumper))->process($this->container);
|
(new AnalyzeServiceReferencesPass(false, !$this->getProxyDumper() instanceof NullDumper))->process($this->container);
|
||||||
$checkedNodes = array();
|
$checkedNodes = [];
|
||||||
$this->circularReferences = array();
|
$this->circularReferences = [];
|
||||||
$this->singleUsePrivateIds = array();
|
$this->singleUsePrivateIds = [];
|
||||||
foreach ($this->container->getCompiler()->getServiceReferenceGraph()->getNodes() as $id => $node) {
|
foreach ($this->container->getCompiler()->getServiceReferenceGraph()->getNodes() as $id => $node) {
|
||||||
if (!$node->getValue() instanceof Definition) {
|
if (!$node->getValue() instanceof Definition) {
|
||||||
continue;
|
continue;
|
||||||
@ -186,7 +186,7 @@ class PhpDumper extends Dumper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->container->getCompiler()->getServiceReferenceGraph()->clear();
|
$this->container->getCompiler()->getServiceReferenceGraph()->clear();
|
||||||
$checkedNodes = array();
|
$checkedNodes = [];
|
||||||
|
|
||||||
$this->docStar = $options['debug'] ? '*' : '';
|
$this->docStar = $options['debug'] ? '*' : '';
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
|||||||
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
|
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
|
||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
$files = array();
|
$files = [];
|
||||||
|
|
||||||
$ids = $this->container->getRemovedIds();
|
$ids = $this->container->getRemovedIds();
|
||||||
foreach ($this->container->getDefinitions() as $id => $definition) {
|
foreach ($this->container->getDefinitions() as $id => $definition) {
|
||||||
@ -265,7 +265,7 @@ EOF;
|
|||||||
}
|
}
|
||||||
$files[$options['class'].'.php'] = $code.$this->endClass();
|
$files[$options['class'].'.php'] = $code.$this->endClass();
|
||||||
$hash = ucfirst(strtr(ContainerBuilder::hash($files), '._', 'xx'));
|
$hash = ucfirst(strtr(ContainerBuilder::hash($files), '._', 'xx'));
|
||||||
$code = array();
|
$code = [];
|
||||||
|
|
||||||
foreach ($files as $file => $c) {
|
foreach ($files as $file => $c) {
|
||||||
$code["Container{$hash}/{$file}"] = $c;
|
$code["Container{$hash}/{$file}"] = $c;
|
||||||
@ -308,12 +308,12 @@ EOF;
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->targetDirRegex = null;
|
$this->targetDirRegex = null;
|
||||||
$this->inlinedRequires = array();
|
$this->inlinedRequires = [];
|
||||||
$this->circularReferences = array();
|
$this->circularReferences = [];
|
||||||
$this->locatedIds = array();
|
$this->locatedIds = [];
|
||||||
$this->exportedVariables = array();
|
$this->exportedVariables = [];
|
||||||
|
|
||||||
$unusedEnvs = array();
|
$unusedEnvs = [];
|
||||||
foreach ($this->container->getEnvCounters() as $env => $use) {
|
foreach ($this->container->getEnvCounters() as $env => $use) {
|
||||||
if (!$use) {
|
if (!$use) {
|
||||||
$unusedEnvs[] = $env;
|
$unusedEnvs[] = $env;
|
||||||
@ -338,7 +338,7 @@ EOF;
|
|||||||
return $this->proxyDumper;
|
return $this->proxyDumper;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function analyzeCircularReferences($sourceId, array $edges, &$checkedNodes, &$currentPath = array())
|
private function analyzeCircularReferences($sourceId, array $edges, &$checkedNodes, &$currentPath = [])
|
||||||
{
|
{
|
||||||
$checkedNodes[$sourceId] = true;
|
$checkedNodes[$sourceId] = true;
|
||||||
$currentPath[$sourceId] = $sourceId;
|
$currentPath[$sourceId] = $sourceId;
|
||||||
@ -367,7 +367,7 @@ EOF;
|
|||||||
unset($currentPath[$sourceId]);
|
unset($currentPath[$sourceId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function connectCircularReferences($sourceId, &$currentPath, &$subPath = array())
|
private function connectCircularReferences($sourceId, &$currentPath, &$subPath = [])
|
||||||
{
|
{
|
||||||
$subPath[$sourceId] = $sourceId;
|
$subPath[$sourceId] = $sourceId;
|
||||||
$currentPath[$sourceId] = $sourceId;
|
$currentPath[$sourceId] = $sourceId;
|
||||||
@ -423,7 +423,7 @@ EOF;
|
|||||||
|
|
||||||
private function generateProxyClasses()
|
private function generateProxyClasses()
|
||||||
{
|
{
|
||||||
$alreadyGenerated = array();
|
$alreadyGenerated = [];
|
||||||
$definitions = $this->container->getDefinitions();
|
$definitions = $this->container->getDefinitions();
|
||||||
$strip = '' === $this->docStar && method_exists('Symfony\Component\HttpKernel\Kernel', 'stripComments');
|
$strip = '' === $this->docStar && method_exists('Symfony\Component\HttpKernel\Kernel', 'stripComments');
|
||||||
$proxyDumper = $this->getProxyDumper();
|
$proxyDumper = $this->getProxyDumper();
|
||||||
@ -454,7 +454,7 @@ EOF;
|
|||||||
$code = '';
|
$code = '';
|
||||||
|
|
||||||
if ($this->inlineRequires && !$this->isHotPath($definition)) {
|
if ($this->inlineRequires && !$this->isHotPath($definition)) {
|
||||||
$lineage = array();
|
$lineage = [];
|
||||||
foreach ($this->inlinedDefinitions as $def) {
|
foreach ($this->inlinedDefinitions as $def) {
|
||||||
if (!$def->isDeprecated() && \is_string($class = \is_array($factory = $def->getFactory()) && \is_string($factory[0]) ? $factory[0] : $def->getClass())) {
|
if (!$def->isDeprecated() && \is_string($class = \is_array($factory = $def->getFactory()) && \is_string($factory[0]) ? $factory[0] : $def->getClass())) {
|
||||||
$this->collectLineage($class, $lineage);
|
$this->collectLineage($class, $lineage);
|
||||||
@ -566,7 +566,7 @@ EOF;
|
|||||||
{
|
{
|
||||||
$calls = '';
|
$calls = '';
|
||||||
foreach ($definition->getMethodCalls() as $call) {
|
foreach ($definition->getMethodCalls() as $call) {
|
||||||
$arguments = array();
|
$arguments = [];
|
||||||
foreach ($call[1] as $value) {
|
foreach ($call[1] as $value) {
|
||||||
$arguments[] = $this->dumpValue($value);
|
$arguments[] = $this->dumpValue($value);
|
||||||
}
|
}
|
||||||
@ -619,11 +619,11 @@ EOF;
|
|||||||
private function addService(string $id, Definition $definition): array
|
private function addService(string $id, Definition $definition): array
|
||||||
{
|
{
|
||||||
$this->definitionVariables = new \SplObjectStorage();
|
$this->definitionVariables = new \SplObjectStorage();
|
||||||
$this->referenceVariables = array();
|
$this->referenceVariables = [];
|
||||||
$this->variableCount = 0;
|
$this->variableCount = 0;
|
||||||
$this->referenceVariables[$id] = new Variable('instance');
|
$this->referenceVariables[$id] = new Variable('instance');
|
||||||
|
|
||||||
$return = array();
|
$return = [];
|
||||||
|
|
||||||
if ($class = $definition->getClass()) {
|
if ($class = $definition->getClass()) {
|
||||||
$class = $class instanceof Parameter ? '%'.$class.'%' : $this->container->resolveEnvPlaceholders($class);
|
$class = $class instanceof Parameter ? '%'.$class.'%' : $this->container->resolveEnvPlaceholders($class);
|
||||||
@ -680,8 +680,8 @@ EOF;
|
|||||||
EOF;
|
EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->serviceCalls = array();
|
$this->serviceCalls = [];
|
||||||
$this->inlinedDefinitions = $this->getDefinitionsFromArguments(array($definition), null, $this->serviceCalls);
|
$this->inlinedDefinitions = $this->getDefinitionsFromArguments([$definition], null, $this->serviceCalls);
|
||||||
|
|
||||||
$code .= $this->addServiceInclude($id, $definition);
|
$code .= $this->addServiceInclude($id, $definition);
|
||||||
|
|
||||||
@ -705,7 +705,7 @@ EOF;
|
|||||||
$this->definitionVariables = $this->inlinedDefinitions = null;
|
$this->definitionVariables = $this->inlinedDefinitions = null;
|
||||||
$this->referenceVariables = $this->serviceCalls = null;
|
$this->referenceVariables = $this->serviceCalls = null;
|
||||||
|
|
||||||
return array($file, $code);
|
return [$file, $code];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addInlineVariables(string $id, Definition $definition, array $arguments, bool $forConstructor): string
|
private function addInlineVariables(string $id, Definition $definition, array $arguments, bool $forConstructor): string
|
||||||
@ -782,11 +782,11 @@ EOTXT
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$arguments = array($inlineDef->getArguments(), $inlineDef->getFactory());
|
$arguments = [$inlineDef->getArguments(), $inlineDef->getFactory()];
|
||||||
|
|
||||||
$code = $this->addInlineVariables($id, $definition, $arguments, $forConstructor);
|
$code = $this->addInlineVariables($id, $definition, $arguments, $forConstructor);
|
||||||
|
|
||||||
if ($arguments = array_filter(array($inlineDef->getProperties(), $inlineDef->getMethodCalls(), $inlineDef->getConfigurator()))) {
|
if ($arguments = array_filter([$inlineDef->getProperties(), $inlineDef->getMethodCalls(), $inlineDef->getConfigurator()])) {
|
||||||
$isSimpleInstance = false;
|
$isSimpleInstance = false;
|
||||||
} elseif ($definition !== $inlineDef && 2 > $this->inlinedDefinitions[$inlineDef]) {
|
} elseif ($definition !== $inlineDef && 2 > $this->inlinedDefinitions[$inlineDef]) {
|
||||||
return $code;
|
return $code;
|
||||||
@ -855,9 +855,9 @@ EOTXT
|
|||||||
if (!$definition->isShared()) {
|
if (!$definition->isShared()) {
|
||||||
$i = strpos($code, "\n\ninclude_once ");
|
$i = strpos($code, "\n\ninclude_once ");
|
||||||
if (false !== $i && false !== $i = strpos($code, "\n\n", 2 + $i)) {
|
if (false !== $i && false !== $i = strpos($code, "\n\n", 2 + $i)) {
|
||||||
$code = array(substr($code, 0, 2 + $i), substr($code, 2 + $i));
|
$code = [substr($code, 0, 2 + $i), substr($code, 2 + $i)];
|
||||||
} else {
|
} else {
|
||||||
$code = array("\n", $code);
|
$code = ["\n", $code];
|
||||||
}
|
}
|
||||||
$code[1] = implode("\n", array_map(function ($line) { return $line ? ' '.$line : $line; }, explode("\n", $code[1])));
|
$code[1] = implode("\n", array_map(function ($line) { return $line ? ' '.$line : $line; }, explode("\n", $code[1])));
|
||||||
$factory = sprintf('$this->factories%s[\'%s\']', $definition->isPublic() ? '' : "['service_container']", $id);
|
$factory = sprintf('$this->factories%s[\'%s\']', $definition->isPublic() ? '' : "['service_container']", $id);
|
||||||
@ -875,7 +875,7 @@ EOTXT
|
|||||||
$tail = $return ? ";\n" : '';
|
$tail = $return ? ";\n" : '';
|
||||||
|
|
||||||
if (BaseServiceLocator::class === $definition->getClass() && $definition->hasTag($this->serviceLocatorTag)) {
|
if (BaseServiceLocator::class === $definition->getClass() && $definition->hasTag($this->serviceLocatorTag)) {
|
||||||
$arguments = array();
|
$arguments = [];
|
||||||
foreach ($definition->getArgument(0) as $k => $argument) {
|
foreach ($definition->getArgument(0) as $k => $argument) {
|
||||||
$arguments[$k] = $argument->getValues()[0];
|
$arguments[$k] = $argument->getValues()[0];
|
||||||
}
|
}
|
||||||
@ -883,7 +883,7 @@ EOTXT
|
|||||||
return $return.$this->dumpValue(new ServiceLocatorArgument($arguments)).$tail;
|
return $return.$this->dumpValue(new ServiceLocatorArgument($arguments)).$tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
$arguments = array();
|
$arguments = [];
|
||||||
foreach ($definition->getArguments() as $value) {
|
foreach ($definition->getArguments() as $value) {
|
||||||
$arguments[] = $this->dumpValue($value);
|
$arguments[] = $this->dumpValue($value);
|
||||||
}
|
}
|
||||||
@ -1157,11 +1157,11 @@ EOF;
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$lineage = array();
|
$lineage = [];
|
||||||
|
|
||||||
foreach ($this->container->findTaggedServiceIds($this->hotPathTag) as $id => $tags) {
|
foreach ($this->container->findTaggedServiceIds($this->hotPathTag) as $id => $tags) {
|
||||||
$definition = $this->container->getDefinition($id);
|
$definition = $this->container->getDefinition($id);
|
||||||
$inlinedDefinitions = $this->getDefinitionsFromArguments(array($definition));
|
$inlinedDefinitions = $this->getDefinitionsFromArguments([$definition]);
|
||||||
|
|
||||||
foreach ($inlinedDefinitions as $def) {
|
foreach ($inlinedDefinitions as $def) {
|
||||||
if (\is_string($class = \is_array($factory = $def->getFactory()) && \is_string($factory[0]) ? $factory[0] : $def->getClass())) {
|
if (\is_string($class = \is_array($factory = $def->getFactory()) && \is_string($factory[0]) ? $factory[0] : $def->getClass())) {
|
||||||
@ -1188,14 +1188,14 @@ EOF;
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$php = array();
|
$php = [];
|
||||||
$dynamicPhp = array();
|
$dynamicPhp = [];
|
||||||
|
|
||||||
foreach ($this->container->getParameterBag()->all() as $key => $value) {
|
foreach ($this->container->getParameterBag()->all() as $key => $value) {
|
||||||
if ($key !== $resolvedKey = $this->container->resolveEnvPlaceholders($key)) {
|
if ($key !== $resolvedKey = $this->container->resolveEnvPlaceholders($key)) {
|
||||||
throw new InvalidArgumentException(sprintf('Parameter name cannot use env parameters: %s.', $resolvedKey));
|
throw new InvalidArgumentException(sprintf('Parameter name cannot use env parameters: %s.', $resolvedKey));
|
||||||
}
|
}
|
||||||
$export = $this->exportParameters(array($value));
|
$export = $this->exportParameters([$value]);
|
||||||
$export = explode('0 => ', substr(rtrim($export, " )\n"), 7, -1), 2);
|
$export = explode('0 => ', substr(rtrim($export, " )\n"), 7, -1), 2);
|
||||||
|
|
||||||
if (preg_match("/\\\$this->(?:getEnv\('(?:\w++:)*+\w++'\)|targetDirs\[\d++\])/", $export[1])) {
|
if (preg_match("/\\\$this->(?:getEnv\('(?:\w++:)*+\w++'\)|targetDirs\[\d++\])/", $export[1])) {
|
||||||
@ -1317,7 +1317,7 @@ EOF;
|
|||||||
*/
|
*/
|
||||||
private function exportParameters(array $parameters, string $path = '', int $indent = 12): string
|
private function exportParameters(array $parameters, string $path = '', int $indent = 12): string
|
||||||
{
|
{
|
||||||
$php = array();
|
$php = [];
|
||||||
foreach ($parameters as $key => $value) {
|
foreach ($parameters as $key => $value) {
|
||||||
if (\is_array($value)) {
|
if (\is_array($value)) {
|
||||||
$value = $this->exportParameters($value, $path.'/'.$key, $indent + 4);
|
$value = $this->exportParameters($value, $path.'/'.$key, $indent + 4);
|
||||||
@ -1375,7 +1375,7 @@ EOF;
|
|||||||
|
|
||||||
private function getServiceConditionals($value): string
|
private function getServiceConditionals($value): string
|
||||||
{
|
{
|
||||||
$conditions = array();
|
$conditions = [];
|
||||||
foreach (ContainerBuilder::getInitializedConditionals($value) as $service) {
|
foreach (ContainerBuilder::getInitializedConditionals($value) as $service) {
|
||||||
if (!$this->container->hasDefinition($service)) {
|
if (!$this->container->hasDefinition($service)) {
|
||||||
return 'false';
|
return 'false';
|
||||||
@ -1397,7 +1397,7 @@ EOF;
|
|||||||
return implode(' && ', $conditions);
|
return implode(' && ', $conditions);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDefinitionsFromArguments(array $arguments, \SplObjectStorage $definitions = null, array &$calls = array()): \SplObjectStorage
|
private function getDefinitionsFromArguments(array $arguments, \SplObjectStorage $definitions = null, array &$calls = []): \SplObjectStorage
|
||||||
{
|
{
|
||||||
if (null === $definitions) {
|
if (null === $definitions) {
|
||||||
$definitions = new \SplObjectStorage();
|
$definitions = new \SplObjectStorage();
|
||||||
@ -1410,7 +1410,7 @@ EOF;
|
|||||||
$id = (string) $argument;
|
$id = (string) $argument;
|
||||||
|
|
||||||
if (!isset($calls[$id])) {
|
if (!isset($calls[$id])) {
|
||||||
$calls[$id] = array(0, $argument->getInvalidBehavior());
|
$calls[$id] = [0, $argument->getInvalidBehavior()];
|
||||||
} else {
|
} else {
|
||||||
$calls[$id][1] = min($calls[$id][1], $argument->getInvalidBehavior());
|
$calls[$id][1] = min($calls[$id][1], $argument->getInvalidBehavior());
|
||||||
}
|
}
|
||||||
@ -1422,7 +1422,7 @@ EOF;
|
|||||||
$definitions[$argument] = 1 + $definitions[$argument];
|
$definitions[$argument] = 1 + $definitions[$argument];
|
||||||
} else {
|
} else {
|
||||||
$definitions[$argument] = 1;
|
$definitions[$argument] = 1;
|
||||||
$arguments = array($argument->getArguments(), $argument->getFactory(), $argument->getProperties(), $argument->getMethodCalls(), $argument->getConfigurator());
|
$arguments = [$argument->getArguments(), $argument->getFactory(), $argument->getProperties(), $argument->getMethodCalls(), $argument->getConfigurator()];
|
||||||
$this->getDefinitionsFromArguments($arguments, $definitions, $calls);
|
$this->getDefinitionsFromArguments($arguments, $definitions, $calls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1439,14 +1439,14 @@ EOF;
|
|||||||
if ($value && $interpolate && false !== $param = array_search($value, $this->container->getParameterBag()->all(), true)) {
|
if ($value && $interpolate && false !== $param = array_search($value, $this->container->getParameterBag()->all(), true)) {
|
||||||
return $this->dumpValue("%$param%");
|
return $this->dumpValue("%$param%");
|
||||||
}
|
}
|
||||||
$code = array();
|
$code = [];
|
||||||
foreach ($value as $k => $v) {
|
foreach ($value as $k => $v) {
|
||||||
$code[] = sprintf('%s => %s', $this->dumpValue($k, $interpolate), $this->dumpValue($v, $interpolate));
|
$code[] = sprintf('%s => %s', $this->dumpValue($k, $interpolate), $this->dumpValue($v, $interpolate));
|
||||||
}
|
}
|
||||||
|
|
||||||
return sprintf('array(%s)', implode(', ', $code));
|
return sprintf('array(%s)', implode(', ', $code));
|
||||||
} elseif ($value instanceof ArgumentInterface) {
|
} elseif ($value instanceof ArgumentInterface) {
|
||||||
$scope = array($this->definitionVariables, $this->referenceVariables);
|
$scope = [$this->definitionVariables, $this->referenceVariables];
|
||||||
$this->definitionVariables = $this->referenceVariables = null;
|
$this->definitionVariables = $this->referenceVariables = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -1465,14 +1465,14 @@ EOF;
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($value instanceof IteratorArgument) {
|
if ($value instanceof IteratorArgument) {
|
||||||
$operands = array(0);
|
$operands = [0];
|
||||||
$code = array();
|
$code = [];
|
||||||
$code[] = 'new RewindableGenerator(function () {';
|
$code[] = 'new RewindableGenerator(function () {';
|
||||||
|
|
||||||
if (!$values = $value->getValues()) {
|
if (!$values = $value->getValues()) {
|
||||||
$code[] = ' return new \EmptyIterator();';
|
$code[] = ' return new \EmptyIterator();';
|
||||||
} else {
|
} else {
|
||||||
$countCode = array();
|
$countCode = [];
|
||||||
$countCode[] = 'function () {';
|
$countCode[] = 'function () {';
|
||||||
|
|
||||||
foreach ($values as $k => $v) {
|
foreach ($values as $k => $v) {
|
||||||
@ -1548,7 +1548,7 @@ EOF;
|
|||||||
|
|
||||||
return $this->getServiceCall($id, $value);
|
return $this->getServiceCall($id, $value);
|
||||||
} elseif ($value instanceof Expression) {
|
} elseif ($value instanceof Expression) {
|
||||||
return $this->getExpressionLanguage()->compile((string) $value, array('this' => 'container'));
|
return $this->getExpressionLanguage()->compile((string) $value, ['this' => 'container']);
|
||||||
} elseif ($value instanceof Parameter) {
|
} elseif ($value instanceof Parameter) {
|
||||||
return $this->dumpParameter($value);
|
return $this->dumpParameter($value);
|
||||||
} elseif (true === $interpolate && \is_string($value)) {
|
} elseif (true === $interpolate && \is_string($value)) {
|
||||||
@ -1670,8 +1670,8 @@ EOF;
|
|||||||
*/
|
*/
|
||||||
private function initializeMethodNamesMap(string $class)
|
private function initializeMethodNamesMap(string $class)
|
||||||
{
|
{
|
||||||
$this->serviceIdToMethodNameMap = array();
|
$this->serviceIdToMethodNameMap = [];
|
||||||
$this->usedMethodNames = array();
|
$this->usedMethodNames = [];
|
||||||
|
|
||||||
if ($reflectionClass = $this->container->getReflectionClass($class)) {
|
if ($reflectionClass = $this->container->getReflectionClass($class)) {
|
||||||
foreach ($reflectionClass->getMethods() as $method) {
|
foreach ($reflectionClass->getMethods() as $method) {
|
||||||
@ -1776,7 +1776,7 @@ EOF;
|
|||||||
if ($node->getValue()->isPublic()) {
|
if ($node->getValue()->isPublic()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$ids = array();
|
$ids = [];
|
||||||
foreach ($node->getInEdges() as $edge) {
|
foreach ($node->getInEdges() as $edge) {
|
||||||
if (!$value = $edge->getSourceNode()->getValue()) {
|
if (!$value = $edge->getSourceNode()->getValue()) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -31,7 +31,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
|
|||||||
*/
|
*/
|
||||||
public static function getProvidedTypes()
|
public static function getProvidedTypes()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
'base64' => 'string',
|
'base64' => 'string',
|
||||||
'bool' => 'bool',
|
'bool' => 'bool',
|
||||||
'const' => 'bool|int|float|string|array',
|
'const' => 'bool|int|float|string|array',
|
||||||
@ -45,7 +45,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
|
|||||||
'default' => 'bool|int|float|string|array',
|
'default' => 'bool|int|float|string|array',
|
||||||
'string' => 'string',
|
'string' => 'string',
|
||||||
'trim' => 'string',
|
'trim' => 'string',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -902,7 +902,7 @@ class AutowirePassTest extends TestCase
|
|||||||
|
|
||||||
(new AutowirePass())->process($container);
|
(new AutowirePass())->process($container);
|
||||||
|
|
||||||
$this->assertSame(array('Cannot autowire service "some_locator": it has type "Symfony\Component\DependencyInjection\Tests\Compiler\MissingClass" but this class was not found.'), $container->getDefinition('.errored.some_locator.'.MissingClass::class)->getErrors());
|
$this->assertSame(['Cannot autowire service "some_locator": it has type "Symfony\Component\DependencyInjection\Tests\Compiler\MissingClass" but this class was not found.'], $container->getDefinition('.errored.some_locator.'.MissingClass::class)->getErrors());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNamedArgumentAliasResolveCollisions()
|
public function testNamedArgumentAliasResolveCollisions()
|
||||||
|
@ -28,22 +28,22 @@ class RegisterEnvVarProcessorsPassTest extends TestCase
|
|||||||
$this->assertTrue($container->has('container.env_var_processors_locator'));
|
$this->assertTrue($container->has('container.env_var_processors_locator'));
|
||||||
$this->assertInstanceOf(SimpleProcessor::class, $container->get('container.env_var_processors_locator')->get('foo'));
|
$this->assertInstanceOf(SimpleProcessor::class, $container->get('container.env_var_processors_locator')->get('foo'));
|
||||||
|
|
||||||
$expected = array(
|
$expected = [
|
||||||
'foo' => array('string'),
|
'foo' => ['string'],
|
||||||
'base64' => array('string'),
|
'base64' => ['string'],
|
||||||
'bool' => array('bool'),
|
'bool' => ['bool'],
|
||||||
'const' => array('bool', 'int', 'float', 'string', 'array'),
|
'const' => ['bool', 'int', 'float', 'string', 'array'],
|
||||||
'csv' => array('array'),
|
'csv' => ['array'],
|
||||||
'file' => array('string'),
|
'file' => ['string'],
|
||||||
'float' => array('float'),
|
'float' => ['float'],
|
||||||
'int' => array('int'),
|
'int' => ['int'],
|
||||||
'json' => array('array'),
|
'json' => ['array'],
|
||||||
'key' => array('bool', 'int', 'float', 'string', 'array'),
|
'key' => ['bool', 'int', 'float', 'string', 'array'],
|
||||||
'resolve' => array('string'),
|
'resolve' => ['string'],
|
||||||
'default' => array('bool', 'int', 'float', 'string', 'array'),
|
'default' => ['bool', 'int', 'float', 'string', 'array'],
|
||||||
'string' => array('string'),
|
'string' => ['string'],
|
||||||
'trim' => array('string'),
|
'trim' => ['string'],
|
||||||
);
|
];
|
||||||
|
|
||||||
$this->assertSame($expected, $container->getParameterBag()->getProvidedTypes());
|
$this->assertSame($expected, $container->getParameterBag()->getProvidedTypes());
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ class SimpleProcessor implements EnvVarProcessorInterface
|
|||||||
|
|
||||||
public static function getProvidedTypes()
|
public static function getProvidedTypes()
|
||||||
{
|
{
|
||||||
return array('foo' => 'string');
|
return ['foo' => 'string'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +87,6 @@ class BadProcessor extends SimpleProcessor
|
|||||||
{
|
{
|
||||||
public static function getProvidedTypes()
|
public static function getProvidedTypes()
|
||||||
{
|
{
|
||||||
return array('foo' => 'string|foo');
|
return ['foo' => 'string|foo'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -221,9 +221,9 @@ class ValidateEnvPlaceholdersPassTest extends TestCase
|
|||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
$container->registerExtension($ext = new EnvExtension());
|
$container->registerExtension($ext = new EnvExtension());
|
||||||
$container->prependExtensionConfig('env_extension', $expected = array(
|
$container->prependExtensionConfig('env_extension', $expected = [
|
||||||
'scalar_node_not_empty_validated' => '%env(SOME)%',
|
'scalar_node_not_empty_validated' => '%env(SOME)%',
|
||||||
));
|
]);
|
||||||
|
|
||||||
$this->doProcess($container);
|
$this->doProcess($container);
|
||||||
|
|
||||||
@ -234,9 +234,9 @@ class ValidateEnvPlaceholdersPassTest extends TestCase
|
|||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
$container->registerExtension($ext = new EnvExtension());
|
$container->registerExtension($ext = new EnvExtension());
|
||||||
$container->prependExtensionConfig('env_extension', $expected = array(
|
$container->prependExtensionConfig('env_extension', $expected = [
|
||||||
'scalar_node_not_empty_validated' => 'foo %env(SOME)% bar',
|
'scalar_node_not_empty_validated' => 'foo %env(SOME)% bar',
|
||||||
));
|
]);
|
||||||
|
|
||||||
$this->doProcess($container);
|
$this->doProcess($container);
|
||||||
|
|
||||||
|
@ -453,7 +453,7 @@ class PhpDumperTest extends TestCase
|
|||||||
$dumper = new PhpDumper($container);
|
$dumper = new PhpDumper($container);
|
||||||
$dumper->dump();
|
$dumper->dump();
|
||||||
|
|
||||||
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_default_env.php', $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_DefaultParameters')));
|
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_default_env.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_DefaultParameters']));
|
||||||
|
|
||||||
require self::$fixturesPath.'/php/services_default_env.php';
|
require self::$fixturesPath.'/php/services_default_env.php';
|
||||||
$container = new \Symfony_DI_PhpDumper_Test_DefaultParameters();
|
$container = new \Symfony_DI_PhpDumper_Test_DefaultParameters();
|
||||||
|
@ -52,7 +52,7 @@ class CrawlerTest extends TestCase
|
|||||||
$crawler->add($this->createNodeList());
|
$crawler->add($this->createNodeList());
|
||||||
$this->assertEquals('foo', $crawler->filterXPath('//div')->attr('class'), '->add() adds nodes from a \DOMNodeList');
|
$this->assertEquals('foo', $crawler->filterXPath('//div')->attr('class'), '->add() adds nodes from a \DOMNodeList');
|
||||||
|
|
||||||
$list = array();
|
$list = [];
|
||||||
foreach ($this->createNodeList() as $node) {
|
foreach ($this->createNodeList() as $node) {
|
||||||
$list[] = $node;
|
$list[] = $node;
|
||||||
}
|
}
|
||||||
@ -269,7 +269,7 @@ EOF
|
|||||||
|
|
||||||
public function testAddNodes()
|
public function testAddNodes()
|
||||||
{
|
{
|
||||||
$list = array();
|
$list = [];
|
||||||
foreach ($this->createNodeList() as $node) {
|
foreach ($this->createNodeList() as $node) {
|
||||||
$list[] = $node;
|
$list[] = $node;
|
||||||
}
|
}
|
||||||
@ -314,7 +314,7 @@ EOF
|
|||||||
return $i.'-'.$node->text();
|
return $i.'-'.$node->text();
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertEquals(array('0-One', '1-Two', '2-Three'), $data, '->each() executes an anonymous function on each node of the list');
|
$this->assertEquals(['0-One', '1-Two', '2-Three'], $data, '->each() executes an anonymous function on each node of the list');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIteration()
|
public function testIteration()
|
||||||
@ -415,13 +415,13 @@ EOF
|
|||||||
{
|
{
|
||||||
$crawler = $this->createTestCrawler()->filterXPath('//ul[1]/li');
|
$crawler = $this->createTestCrawler()->filterXPath('//ul[1]/li');
|
||||||
|
|
||||||
$this->assertEquals(array('One', 'Two', 'Three'), $crawler->extract('_text'), '->extract() returns an array of extracted data from the node list');
|
$this->assertEquals(['One', 'Two', 'Three'], $crawler->extract('_text'), '->extract() returns an array of extracted data from the node list');
|
||||||
$this->assertEquals(array(array('One', 'first'), array('Two', ''), array('Three', '')), $crawler->extract(array('_text', 'class')), '->extract() returns an array of extracted data from the node list');
|
$this->assertEquals([['One', 'first'], ['Two', ''], ['Three', '']], $crawler->extract(['_text', 'class']), '->extract() returns an array of extracted data from the node list');
|
||||||
$this->assertEquals(array(array(), array(), array()), $crawler->extract(array()), '->extract() returns empty arrays if the attribute list is empty');
|
$this->assertEquals([[], [], []], $crawler->extract([]), '->extract() returns empty arrays if the attribute list is empty');
|
||||||
|
|
||||||
$this->assertEquals(array(), $this->createTestCrawler()->filterXPath('//ol')->extract('_text'), '->extract() returns an empty array if the node list is empty');
|
$this->assertEquals([], $this->createTestCrawler()->filterXPath('//ol')->extract('_text'), '->extract() returns an empty array if the node list is empty');
|
||||||
|
|
||||||
$this->assertEquals(array(array('One', 'li'), array('Two', 'li'), array('Three', 'li')), $crawler->extract(array('_text', '_name')), '->extract() returns an array of extracted data from the node list');
|
$this->assertEquals([['One', 'li'], ['Two', 'li'], ['Three', 'li']], $crawler->extract(['_text', '_name']), '->extract() returns an array of extracted data from the node list');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFilterXpathComplexQueries()
|
public function testFilterXpathComplexQueries()
|
||||||
@ -855,7 +855,7 @@ HTML;
|
|||||||
$links = $crawler->links();
|
$links = $crawler->links();
|
||||||
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Link', $links[0], '->links() returns an array of Link instances');
|
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Link', $links[0], '->links() returns an array of Link instances');
|
||||||
|
|
||||||
$this->assertEquals(array(), $this->createTestCrawler()->filterXPath('//ol')->links(), '->links() returns an empty array if the node selection is empty');
|
$this->assertEquals([], $this->createTestCrawler()->filterXPath('//ol')->links(), '->links() returns an empty array if the node selection is empty');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testImages()
|
public function testImages()
|
||||||
@ -867,7 +867,7 @@ HTML;
|
|||||||
$images = $crawler->images();
|
$images = $crawler->images();
|
||||||
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Image', $images[0], '->images() returns an array of Image instances');
|
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Image', $images[0], '->images() returns an array of Image instances');
|
||||||
|
|
||||||
$this->assertEquals(array(), $this->createTestCrawler()->filterXPath('//ol')->links(), '->links() returns an empty array if the node selection is empty');
|
$this->assertEquals([], $this->createTestCrawler()->filterXPath('//ol')->links(), '->links() returns an empty array if the node selection is empty');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testForm()
|
public function testForm()
|
||||||
@ -880,9 +880,9 @@ HTML;
|
|||||||
|
|
||||||
$this->assertEquals($crawler->form()->getFormNode()->getAttribute('id'), $crawler2->form()->getFormNode()->getAttribute('id'), '->form() works on elements with form attribute');
|
$this->assertEquals($crawler->form()->getFormNode()->getAttribute('id'), $crawler2->form()->getFormNode()->getAttribute('id'), '->form() works on elements with form attribute');
|
||||||
|
|
||||||
$this->assertEquals(array('FooName' => 'FooBar', 'TextName' => 'TextValue', 'FooTextName' => 'FooTextValue'), $crawler->form(array('FooName' => 'FooBar'))->getValues(), '->form() takes an array of values to submit as its first argument');
|
$this->assertEquals(['FooName' => 'FooBar', 'TextName' => 'TextValue', 'FooTextName' => 'FooTextValue'], $crawler->form(['FooName' => 'FooBar'])->getValues(), '->form() takes an array of values to submit as its first argument');
|
||||||
$this->assertEquals(array('FooName' => 'FooValue', 'TextName' => 'TextValue', 'FooTextName' => 'FooTextValue'), $crawler->form()->getValues(), '->getValues() returns correct form values');
|
$this->assertEquals(['FooName' => 'FooValue', 'TextName' => 'TextValue', 'FooTextName' => 'FooTextValue'], $crawler->form()->getValues(), '->getValues() returns correct form values');
|
||||||
$this->assertEquals(array('FooBarName' => 'FooBarValue', 'TextName' => 'TextValue', 'FooTextName' => 'FooTextValue'), $crawler2->form()->getValues(), '->getValues() returns correct form values');
|
$this->assertEquals(['FooBarName' => 'FooBarValue', 'TextName' => 'TextValue', 'FooTextName' => 'FooTextValue'], $crawler2->form()->getValues(), '->getValues() returns correct form values');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->createTestCrawler()->filterXPath('//ol')->form();
|
$this->createTestCrawler()->filterXPath('//ol')->form();
|
||||||
@ -1072,13 +1072,13 @@ HTML;
|
|||||||
|
|
||||||
public function getBaseTagData()
|
public function getBaseTagData()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array('http://base.com', 'link', 'http://base.com/link'),
|
['http://base.com', 'link', 'http://base.com/link'],
|
||||||
array('//base.com', 'link', 'https://base.com/link', 'https://domain.com', '<base> tag can use a schema-less URL'),
|
['//base.com', 'link', 'https://base.com/link', 'https://domain.com', '<base> tag can use a schema-less URL'],
|
||||||
array('path/', 'link', 'https://domain.com/path/link', 'https://domain.com', '<base> tag can set a path'),
|
['path/', 'link', 'https://domain.com/path/link', 'https://domain.com', '<base> tag can set a path'],
|
||||||
array('http://base.com', '#', 'http://base.com#', 'http://domain.com/path/link', '<base> tag does work with links to an anchor'),
|
['http://base.com', '#', 'http://base.com#', 'http://domain.com/path/link', '<base> tag does work with links to an anchor'],
|
||||||
array('http://base.com', '', 'http://base.com', 'http://domain.com/path/link', '<base> tag does work with empty links'),
|
['http://base.com', '', 'http://base.com', 'http://domain.com/path/link', '<base> tag does work with empty links'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1092,14 +1092,14 @@ HTML;
|
|||||||
|
|
||||||
public function getBaseTagWithFormData()
|
public function getBaseTagWithFormData()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array('https://base.com/', 'link/', 'https://base.com/link/', 'https://base.com/link/', '<base> tag does work with a path and relative form action'),
|
['https://base.com/', 'link/', 'https://base.com/link/', 'https://base.com/link/', '<base> tag does work with a path and relative form action'],
|
||||||
array('/basepath', '/registration', 'http://domain.com/registration', 'http://domain.com/registration', '<base> tag does work with a path and form action'),
|
['/basepath', '/registration', 'http://domain.com/registration', 'http://domain.com/registration', '<base> tag does work with a path and form action'],
|
||||||
array('/basepath', '', 'http://domain.com/registration', 'http://domain.com/registration', '<base> tag does work with a path and empty form action'),
|
['/basepath', '', 'http://domain.com/registration', 'http://domain.com/registration', '<base> tag does work with a path and empty form action'],
|
||||||
array('http://base.com/', '/registration', 'http://base.com/registration', 'http://domain.com/registration', '<base> tag does work with a URL and form action'),
|
['http://base.com/', '/registration', 'http://base.com/registration', 'http://domain.com/registration', '<base> tag does work with a URL and form action'],
|
||||||
array('http://base.com', '', 'http://domain.com/path/form', 'http://domain.com/path/form', '<base> tag does work with a URL and an empty form action'),
|
['http://base.com', '', 'http://domain.com/path/form', 'http://domain.com/path/form', '<base> tag does work with a URL and an empty form action'],
|
||||||
array('http://base.com/path', '/registration', 'http://base.com/registration', 'http://domain.com/path/form', '<base> tag does work with a URL and form action'),
|
['http://base.com/path', '/registration', 'http://base.com/registration', 'http://domain.com/path/form', '<base> tag does work with a URL and form action'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCountOfNestedElements()
|
public function testCountOfNestedElements()
|
||||||
@ -1115,7 +1115,7 @@ HTML;
|
|||||||
|
|
||||||
$result = $crawler->filterXPath('//form/input')->evaluate('substring-before(@name, "Name")');
|
$result = $crawler->filterXPath('//form/input')->evaluate('substring-before(@name, "Name")');
|
||||||
|
|
||||||
$this->assertSame(array('Text', 'Foo', 'Bar'), $result);
|
$this->assertSame(['Text', 'Foo', 'Bar'], $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEvaluateReturnsTypedResultOfNamespacedXPathExpressionOnADocumentSubset()
|
public function testEvaluateReturnsTypedResultOfNamespacedXPathExpressionOnADocumentSubset()
|
||||||
@ -1124,7 +1124,7 @@ HTML;
|
|||||||
|
|
||||||
$result = $crawler->filterXPath('//yt:accessControl/@action')->evaluate('string(.)');
|
$result = $crawler->filterXPath('//yt:accessControl/@action')->evaluate('string(.)');
|
||||||
|
|
||||||
$this->assertSame(array('comment', 'videoRespond'), $result);
|
$this->assertSame(['comment', 'videoRespond'], $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEvaluateReturnsTypedResultOfNamespacedXPathExpression()
|
public function testEvaluateReturnsTypedResultOfNamespacedXPathExpression()
|
||||||
@ -1134,7 +1134,7 @@ HTML;
|
|||||||
|
|
||||||
$result = $crawler->evaluate('string(//youtube:accessControl/@action)');
|
$result = $crawler->evaluate('string(//youtube:accessControl/@action)');
|
||||||
|
|
||||||
$this->assertSame(array('comment'), $result);
|
$this->assertSame(['comment'], $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEvaluateReturnsACrawlerIfXPathExpressionEvaluatesToANode()
|
public function testEvaluateReturnsACrawlerIfXPathExpressionEvaluatesToANode()
|
||||||
|
@ -34,24 +34,24 @@ class DotenvTest extends TestCase
|
|||||||
|
|
||||||
public function getEnvDataWithFormatErrors()
|
public function getEnvDataWithFormatErrors()
|
||||||
{
|
{
|
||||||
$tests = array(
|
$tests = [
|
||||||
array('FOO=BAR BAZ', "A value containing spaces must be surrounded by quotes in \".env\" at line 1.\n...FOO=BAR BAZ...\n ^ line 1 offset 11"),
|
['FOO=BAR BAZ', "A value containing spaces must be surrounded by quotes in \".env\" at line 1.\n...FOO=BAR BAZ...\n ^ line 1 offset 11"],
|
||||||
array('FOO BAR=BAR', "Whitespace are not supported after the variable name in \".env\" at line 1.\n...FOO BAR=BAR...\n ^ line 1 offset 3"),
|
['FOO BAR=BAR', "Whitespace are not supported after the variable name in \".env\" at line 1.\n...FOO BAR=BAR...\n ^ line 1 offset 3"],
|
||||||
array('FOO', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO...\n ^ line 1 offset 3"),
|
['FOO', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO...\n ^ line 1 offset 3"],
|
||||||
array('FOO="foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO=\"foo...\n ^ line 1 offset 8"),
|
['FOO="foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO=\"foo...\n ^ line 1 offset 8"],
|
||||||
array('FOO=\'foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo...\n ^ line 1 offset 8"),
|
['FOO=\'foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo...\n ^ line 1 offset 8"],
|
||||||
array('FOO=\'foo'."\n", "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo\\n...\n ^ line 1 offset 8"),
|
['FOO=\'foo'."\n", "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo\\n...\n ^ line 1 offset 8"],
|
||||||
array('export FOO', "Unable to unset an environment variable in \".env\" at line 1.\n...export FOO...\n ^ line 1 offset 10"),
|
['export FOO', "Unable to unset an environment variable in \".env\" at line 1.\n...export FOO...\n ^ line 1 offset 10"],
|
||||||
array('FOO=${FOO', "Unclosed braces on variable expansion in \".env\" at line 1.\n...FOO=\${FOO...\n ^ line 1 offset 9"),
|
['FOO=${FOO', "Unclosed braces on variable expansion in \".env\" at line 1.\n...FOO=\${FOO...\n ^ line 1 offset 9"],
|
||||||
array('FOO= BAR', "Whitespace are not supported before the value in \".env\" at line 1.\n...FOO= BAR...\n ^ line 1 offset 4"),
|
['FOO= BAR', "Whitespace are not supported before the value in \".env\" at line 1.\n...FOO= BAR...\n ^ line 1 offset 4"],
|
||||||
array('Стасян', "Invalid character in variable name in \".env\" at line 1.\n...Стасян...\n ^ line 1 offset 0"),
|
['Стасян', "Invalid character in variable name in \".env\" at line 1.\n...Стасян...\n ^ line 1 offset 0"],
|
||||||
array('FOO!', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO!...\n ^ line 1 offset 3"),
|
['FOO!', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO!...\n ^ line 1 offset 3"],
|
||||||
array('FOO=$(echo foo', "Missing closing parenthesis. in \".env\" at line 1.\n...FOO=$(echo foo...\n ^ line 1 offset 14"),
|
['FOO=$(echo foo', "Missing closing parenthesis. in \".env\" at line 1.\n...FOO=$(echo foo...\n ^ line 1 offset 14"],
|
||||||
array('FOO=$(echo foo'."\n", "Missing closing parenthesis. in \".env\" at line 1.\n...FOO=$(echo foo\\n...\n ^ line 1 offset 14"),
|
['FOO=$(echo foo'."\n", "Missing closing parenthesis. in \".env\" at line 1.\n...FOO=$(echo foo\\n...\n ^ line 1 offset 14"],
|
||||||
);
|
];
|
||||||
|
|
||||||
if ('\\' !== \DIRECTORY_SEPARATOR) {
|
if ('\\' !== \DIRECTORY_SEPARATOR) {
|
||||||
$tests[] = array('FOO=$((1dd2))', "Issue expanding a command (%s\n) in \".env\" at line 1.\n...FOO=$((1dd2))...\n ^ line 1 offset 13");
|
$tests[] = ['FOO=$((1dd2))', "Issue expanding a command (%s\n) in \".env\" at line 1.\n...FOO=$((1dd2))...\n ^ line 1 offset 13"];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tests;
|
return $tests;
|
||||||
@ -72,105 +72,105 @@ class DotenvTest extends TestCase
|
|||||||
$_ENV['REMOTE'] = 'remote';
|
$_ENV['REMOTE'] = 'remote';
|
||||||
$_SERVER['SERVERVAR'] = 'servervar';
|
$_SERVER['SERVERVAR'] = 'servervar';
|
||||||
|
|
||||||
$tests = array(
|
$tests = [
|
||||||
// backslashes
|
// backslashes
|
||||||
array('FOO=foo\\\\bar', array('FOO' => 'foo\\bar')),
|
['FOO=foo\\\\bar', ['FOO' => 'foo\\bar']],
|
||||||
array("FOO='foo\\\\bar'", array('FOO' => 'foo\\\\bar')),
|
["FOO='foo\\\\bar'", ['FOO' => 'foo\\\\bar']],
|
||||||
array('FOO="foo\\\\bar"', array('FOO' => 'foo\\bar')),
|
['FOO="foo\\\\bar"', ['FOO' => 'foo\\bar']],
|
||||||
|
|
||||||
// escaped backslash in front of variable
|
// escaped backslash in front of variable
|
||||||
array("BAR=bar\nFOO=foo\\\\\$BAR", array('BAR' => 'bar', 'FOO' => 'foo\\bar')),
|
["BAR=bar\nFOO=foo\\\\\$BAR", ['BAR' => 'bar', 'FOO' => 'foo\\bar']],
|
||||||
array("BAR=bar\nFOO='foo\\\\\$BAR'", array('BAR' => 'bar', 'FOO' => 'foo\\\\$BAR')),
|
["BAR=bar\nFOO='foo\\\\\$BAR'", ['BAR' => 'bar', 'FOO' => 'foo\\\\$BAR']],
|
||||||
array("BAR=bar\nFOO=\"foo\\\\\$BAR\"", array('BAR' => 'bar', 'FOO' => 'foo\\bar')),
|
["BAR=bar\nFOO=\"foo\\\\\$BAR\"", ['BAR' => 'bar', 'FOO' => 'foo\\bar']],
|
||||||
|
|
||||||
array('FOO=foo\\\\\\$BAR', array('FOO' => 'foo\\$BAR')),
|
['FOO=foo\\\\\\$BAR', ['FOO' => 'foo\\$BAR']],
|
||||||
array('FOO=\'foo\\\\\\$BAR\'', array('FOO' => 'foo\\\\\\$BAR')),
|
['FOO=\'foo\\\\\\$BAR\'', ['FOO' => 'foo\\\\\\$BAR']],
|
||||||
array('FOO="foo\\\\\\$BAR"', array('FOO' => 'foo\\$BAR')),
|
['FOO="foo\\\\\\$BAR"', ['FOO' => 'foo\\$BAR']],
|
||||||
|
|
||||||
// spaces
|
// spaces
|
||||||
array('FOO=bar', array('FOO' => 'bar')),
|
['FOO=bar', ['FOO' => 'bar']],
|
||||||
array(' FOO=bar ', array('FOO' => 'bar')),
|
[' FOO=bar ', ['FOO' => 'bar']],
|
||||||
array('FOO=', array('FOO' => '')),
|
['FOO=', ['FOO' => '']],
|
||||||
array("FOO=\n\n\nBAR=bar", array('FOO' => '', 'BAR' => 'bar')),
|
["FOO=\n\n\nBAR=bar", ['FOO' => '', 'BAR' => 'bar']],
|
||||||
array('FOO= ', array('FOO' => '')),
|
['FOO= ', ['FOO' => '']],
|
||||||
array("FOO=\nBAR=bar", array('FOO' => '', 'BAR' => 'bar')),
|
["FOO=\nBAR=bar", ['FOO' => '', 'BAR' => 'bar']],
|
||||||
|
|
||||||
// newlines
|
// newlines
|
||||||
array("\n\nFOO=bar\r\n\n", array('FOO' => 'bar')),
|
["\n\nFOO=bar\r\n\n", ['FOO' => 'bar']],
|
||||||
array("FOO=bar\r\nBAR=foo", array('FOO' => 'bar', 'BAR' => 'foo')),
|
["FOO=bar\r\nBAR=foo", ['FOO' => 'bar', 'BAR' => 'foo']],
|
||||||
array("FOO=bar\rBAR=foo", array('FOO' => 'bar', 'BAR' => 'foo')),
|
["FOO=bar\rBAR=foo", ['FOO' => 'bar', 'BAR' => 'foo']],
|
||||||
array("FOO=bar\nBAR=foo", array('FOO' => 'bar', 'BAR' => 'foo')),
|
["FOO=bar\nBAR=foo", ['FOO' => 'bar', 'BAR' => 'foo']],
|
||||||
|
|
||||||
// quotes
|
// quotes
|
||||||
array("FOO=\"bar\"\n", array('FOO' => 'bar')),
|
["FOO=\"bar\"\n", ['FOO' => 'bar']],
|
||||||
array("FOO=\"bar'foo\"\n", array('FOO' => 'bar\'foo')),
|
["FOO=\"bar'foo\"\n", ['FOO' => 'bar\'foo']],
|
||||||
array("FOO='bar'\n", array('FOO' => 'bar')),
|
["FOO='bar'\n", ['FOO' => 'bar']],
|
||||||
array("FOO='bar\"foo'\n", array('FOO' => 'bar"foo')),
|
["FOO='bar\"foo'\n", ['FOO' => 'bar"foo']],
|
||||||
array("FOO=\"bar\\\"foo\"\n", array('FOO' => 'bar"foo')),
|
["FOO=\"bar\\\"foo\"\n", ['FOO' => 'bar"foo']],
|
||||||
array('FOO="bar\nfoo"', array('FOO' => "bar\nfoo")),
|
['FOO="bar\nfoo"', ['FOO' => "bar\nfoo"]],
|
||||||
array('FOO="bar\rfoo"', array('FOO' => "bar\rfoo")),
|
['FOO="bar\rfoo"', ['FOO' => "bar\rfoo"]],
|
||||||
array('FOO=\'bar\nfoo\'', array('FOO' => 'bar\nfoo')),
|
['FOO=\'bar\nfoo\'', ['FOO' => 'bar\nfoo']],
|
||||||
array('FOO=\'bar\rfoo\'', array('FOO' => 'bar\rfoo')),
|
['FOO=\'bar\rfoo\'', ['FOO' => 'bar\rfoo']],
|
||||||
array('FOO=" FOO "', array('FOO' => ' FOO ')),
|
['FOO=" FOO "', ['FOO' => ' FOO ']],
|
||||||
array('FOO=" "', array('FOO' => ' ')),
|
['FOO=" "', ['FOO' => ' ']],
|
||||||
array('PATH="c:\\\\"', array('PATH' => 'c:\\')),
|
['PATH="c:\\\\"', ['PATH' => 'c:\\']],
|
||||||
array("FOO=\"bar\nfoo\"", array('FOO' => "bar\nfoo")),
|
["FOO=\"bar\nfoo\"", ['FOO' => "bar\nfoo"]],
|
||||||
array('FOO=BAR\\"', array('FOO' => 'BAR"')),
|
['FOO=BAR\\"', ['FOO' => 'BAR"']],
|
||||||
array("FOO=BAR\\'BAZ", array('FOO' => "BAR'BAZ")),
|
["FOO=BAR\\'BAZ", ['FOO' => "BAR'BAZ"]],
|
||||||
array('FOO=\\"BAR', array('FOO' => '"BAR')),
|
['FOO=\\"BAR', ['FOO' => '"BAR']],
|
||||||
|
|
||||||
// concatenated values
|
// concatenated values
|
||||||
array("FOO='bar''foo'\n", array('FOO' => 'barfoo')),
|
["FOO='bar''foo'\n", ['FOO' => 'barfoo']],
|
||||||
array("FOO='bar '' baz'", array('FOO' => 'bar baz')),
|
["FOO='bar '' baz'", ['FOO' => 'bar baz']],
|
||||||
array("FOO=bar\nBAR='baz'\"\$FOO\"", array('FOO' => 'bar', 'BAR' => 'bazbar')),
|
["FOO=bar\nBAR='baz'\"\$FOO\"", ['FOO' => 'bar', 'BAR' => 'bazbar']],
|
||||||
array("FOO='bar '\\'' baz'", array('FOO' => "bar ' baz")),
|
["FOO='bar '\\'' baz'", ['FOO' => "bar ' baz"]],
|
||||||
|
|
||||||
// comments
|
// comments
|
||||||
array("#FOO=bar\nBAR=foo", array('BAR' => 'foo')),
|
["#FOO=bar\nBAR=foo", ['BAR' => 'foo']],
|
||||||
array("#FOO=bar # Comment\nBAR=foo", array('BAR' => 'foo')),
|
["#FOO=bar # Comment\nBAR=foo", ['BAR' => 'foo']],
|
||||||
array("FOO='bar foo' # Comment", array('FOO' => 'bar foo')),
|
["FOO='bar foo' # Comment", ['FOO' => 'bar foo']],
|
||||||
array("FOO='bar#foo' # Comment", array('FOO' => 'bar#foo')),
|
["FOO='bar#foo' # Comment", ['FOO' => 'bar#foo']],
|
||||||
array("# Comment\r\nFOO=bar\n# Comment\nBAR=foo", array('FOO' => 'bar', 'BAR' => 'foo')),
|
["# Comment\r\nFOO=bar\n# Comment\nBAR=foo", ['FOO' => 'bar', 'BAR' => 'foo']],
|
||||||
array("FOO=bar # Another comment\nBAR=foo", array('FOO' => 'bar', 'BAR' => 'foo')),
|
["FOO=bar # Another comment\nBAR=foo", ['FOO' => 'bar', 'BAR' => 'foo']],
|
||||||
array("FOO=\n\n# comment\nBAR=bar", array('FOO' => '', 'BAR' => 'bar')),
|
["FOO=\n\n# comment\nBAR=bar", ['FOO' => '', 'BAR' => 'bar']],
|
||||||
array('FOO=NOT#COMMENT', array('FOO' => 'NOT#COMMENT')),
|
['FOO=NOT#COMMENT', ['FOO' => 'NOT#COMMENT']],
|
||||||
array('FOO= # Comment', array('FOO' => '')),
|
['FOO= # Comment', ['FOO' => '']],
|
||||||
|
|
||||||
// edge cases (no conversions, only strings as values)
|
// edge cases (no conversions, only strings as values)
|
||||||
array('FOO=0', array('FOO' => '0')),
|
['FOO=0', ['FOO' => '0']],
|
||||||
array('FOO=false', array('FOO' => 'false')),
|
['FOO=false', ['FOO' => 'false']],
|
||||||
array('FOO=null', array('FOO' => 'null')),
|
['FOO=null', ['FOO' => 'null']],
|
||||||
|
|
||||||
// export
|
// export
|
||||||
array('export FOO=bar', array('FOO' => 'bar')),
|
['export FOO=bar', ['FOO' => 'bar']],
|
||||||
array(' export FOO=bar', array('FOO' => 'bar')),
|
[' export FOO=bar', ['FOO' => 'bar']],
|
||||||
|
|
||||||
// variable expansion
|
// variable expansion
|
||||||
array("FOO=BAR\nBAR=\$FOO", array('FOO' => 'BAR', 'BAR' => 'BAR')),
|
["FOO=BAR\nBAR=\$FOO", ['FOO' => 'BAR', 'BAR' => 'BAR']],
|
||||||
array("FOO=BAR\nBAR=\"\$FOO\"", array('FOO' => 'BAR', 'BAR' => 'BAR')),
|
["FOO=BAR\nBAR=\"\$FOO\"", ['FOO' => 'BAR', 'BAR' => 'BAR']],
|
||||||
array("FOO=BAR\nBAR='\$FOO'", array('FOO' => 'BAR', 'BAR' => '$FOO')),
|
["FOO=BAR\nBAR='\$FOO'", ['FOO' => 'BAR', 'BAR' => '$FOO']],
|
||||||
array("FOO_BAR9=BAR\nBAR=\$FOO_BAR9", array('FOO_BAR9' => 'BAR', 'BAR' => 'BAR')),
|
["FOO_BAR9=BAR\nBAR=\$FOO_BAR9", ['FOO_BAR9' => 'BAR', 'BAR' => 'BAR']],
|
||||||
array("FOO=BAR\nBAR=\${FOO}Z", array('FOO' => 'BAR', 'BAR' => 'BARZ')),
|
["FOO=BAR\nBAR=\${FOO}Z", ['FOO' => 'BAR', 'BAR' => 'BARZ']],
|
||||||
array("FOO=BAR\nBAR=\$FOO}", array('FOO' => 'BAR', 'BAR' => 'BAR}')),
|
["FOO=BAR\nBAR=\$FOO}", ['FOO' => 'BAR', 'BAR' => 'BAR}']],
|
||||||
array("FOO=BAR\nBAR=\\\$FOO", array('FOO' => 'BAR', 'BAR' => '$FOO')),
|
["FOO=BAR\nBAR=\\\$FOO", ['FOO' => 'BAR', 'BAR' => '$FOO']],
|
||||||
array('FOO=" \\$ "', array('FOO' => ' $ ')),
|
['FOO=" \\$ "', ['FOO' => ' $ ']],
|
||||||
array('FOO=" $ "', array('FOO' => ' $ ')),
|
['FOO=" $ "', ['FOO' => ' $ ']],
|
||||||
array('BAR=$LOCAL', array('BAR' => 'local')),
|
['BAR=$LOCAL', ['BAR' => 'local']],
|
||||||
array('BAR=$REMOTE', array('BAR' => 'remote')),
|
['BAR=$REMOTE', ['BAR' => 'remote']],
|
||||||
array('BAR=$SERVERVAR', array('BAR' => 'servervar')),
|
['BAR=$SERVERVAR', ['BAR' => 'servervar']],
|
||||||
array('FOO=$NOTDEFINED', array('FOO' => '')),
|
['FOO=$NOTDEFINED', ['FOO' => '']],
|
||||||
);
|
];
|
||||||
|
|
||||||
if ('\\' !== \DIRECTORY_SEPARATOR) {
|
if ('\\' !== \DIRECTORY_SEPARATOR) {
|
||||||
$tests = array_merge($tests, array(
|
$tests = array_merge($tests, [
|
||||||
// command expansion
|
// command expansion
|
||||||
array('FOO=$(echo foo)', array('FOO' => 'foo')),
|
['FOO=$(echo foo)', ['FOO' => 'foo']],
|
||||||
array('FOO=$((1+2))', array('FOO' => '3')),
|
['FOO=$((1+2))', ['FOO' => '3']],
|
||||||
array('FOO=FOO$((1+2))BAR', array('FOO' => 'FOO3BAR')),
|
['FOO=FOO$((1+2))BAR', ['FOO' => 'FOO3BAR']],
|
||||||
array('FOO=$(echo "$(echo "$(echo "$(echo foo)")")")', array('FOO' => 'foo')),
|
['FOO=$(echo "$(echo "$(echo "$(echo foo)")")")', ['FOO' => 'foo']],
|
||||||
array("FOO=$(echo \"Quotes won't be a problem\")", array('FOO' => 'Quotes won\'t be a problem')),
|
["FOO=$(echo \"Quotes won't be a problem\")", ['FOO' => 'Quotes won\'t be a problem']],
|
||||||
array("FOO=bar\nBAR=$(echo \"FOO is \$FOO\")", array('FOO' => 'bar', 'BAR' => 'FOO is bar')),
|
["FOO=bar\nBAR=$(echo \"FOO is \$FOO\")", ['FOO' => 'bar', 'BAR' => 'FOO is bar']],
|
||||||
));
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tests;
|
return $tests;
|
||||||
@ -319,7 +319,7 @@ class DotenvTest extends TestCase
|
|||||||
$originalValue = $_SERVER['argc'];
|
$originalValue = $_SERVER['argc'];
|
||||||
|
|
||||||
$dotenv = new Dotenv();
|
$dotenv = new Dotenv();
|
||||||
$dotenv->populate(array('argc' => 'new_value'));
|
$dotenv->populate(['argc' => 'new_value']);
|
||||||
|
|
||||||
$this->assertSame($originalValue, $_SERVER['argc']);
|
$this->assertSame($originalValue, $_SERVER['argc']);
|
||||||
}
|
}
|
||||||
@ -330,7 +330,7 @@ class DotenvTest extends TestCase
|
|||||||
$_SERVER['TEST_ENV_VAR'] = 'original_value';
|
$_SERVER['TEST_ENV_VAR'] = 'original_value';
|
||||||
|
|
||||||
$dotenv = new Dotenv();
|
$dotenv = new Dotenv();
|
||||||
$dotenv->populate(array('TEST_ENV_VAR' => 'new_value'));
|
$dotenv->populate(['TEST_ENV_VAR' => 'new_value']);
|
||||||
|
|
||||||
$this->assertSame('original_value', getenv('TEST_ENV_VAR'));
|
$this->assertSame('original_value', getenv('TEST_ENV_VAR'));
|
||||||
}
|
}
|
||||||
@ -340,7 +340,7 @@ class DotenvTest extends TestCase
|
|||||||
$_SERVER['HTTP_TEST_ENV_VAR'] = 'http_value';
|
$_SERVER['HTTP_TEST_ENV_VAR'] = 'http_value';
|
||||||
|
|
||||||
$dotenv = new Dotenv();
|
$dotenv = new Dotenv();
|
||||||
$dotenv->populate(array('HTTP_TEST_ENV_VAR' => 'env_value'));
|
$dotenv->populate(['HTTP_TEST_ENV_VAR' => 'env_value']);
|
||||||
|
|
||||||
$this->assertSame('env_value', getenv('HTTP_TEST_ENV_VAR'));
|
$this->assertSame('env_value', getenv('HTTP_TEST_ENV_VAR'));
|
||||||
$this->assertSame('env_value', $_ENV['HTTP_TEST_ENV_VAR']);
|
$this->assertSame('env_value', $_ENV['HTTP_TEST_ENV_VAR']);
|
||||||
@ -352,7 +352,7 @@ class DotenvTest extends TestCase
|
|||||||
putenv('TEST_ENV_VAR_OVERRIDEN=original_value');
|
putenv('TEST_ENV_VAR_OVERRIDEN=original_value');
|
||||||
|
|
||||||
$dotenv = new Dotenv();
|
$dotenv = new Dotenv();
|
||||||
$dotenv->populate(array('TEST_ENV_VAR_OVERRIDEN' => 'new_value'), true);
|
$dotenv->populate(['TEST_ENV_VAR_OVERRIDEN' => 'new_value'], true);
|
||||||
|
|
||||||
$this->assertSame('new_value', getenv('TEST_ENV_VAR_OVERRIDEN'));
|
$this->assertSame('new_value', getenv('TEST_ENV_VAR_OVERRIDEN'));
|
||||||
$this->assertSame('new_value', $_ENV['TEST_ENV_VAR_OVERRIDEN']);
|
$this->assertSame('new_value', $_ENV['TEST_ENV_VAR_OVERRIDEN']);
|
||||||
@ -374,7 +374,7 @@ class DotenvTest extends TestCase
|
|||||||
putenv('DATABASE_URL');
|
putenv('DATABASE_URL');
|
||||||
|
|
||||||
$dotenv = new Dotenv();
|
$dotenv = new Dotenv();
|
||||||
$dotenv->populate(array('APP_DEBUG' => '1', 'DATABASE_URL' => 'mysql://root@localhost/db'));
|
$dotenv->populate(['APP_DEBUG' => '1', 'DATABASE_URL' => 'mysql://root@localhost/db']);
|
||||||
|
|
||||||
$this->assertSame('APP_DEBUG,DATABASE_URL', getenv('SYMFONY_DOTENV_VARS'));
|
$this->assertSame('APP_DEBUG,DATABASE_URL', getenv('SYMFONY_DOTENV_VARS'));
|
||||||
|
|
||||||
@ -391,8 +391,8 @@ class DotenvTest extends TestCase
|
|||||||
putenv('DATABASE_URL');
|
putenv('DATABASE_URL');
|
||||||
|
|
||||||
$dotenv = new Dotenv();
|
$dotenv = new Dotenv();
|
||||||
$dotenv->populate(array('APP_DEBUG' => '0', 'DATABASE_URL' => 'mysql://root@localhost/db'));
|
$dotenv->populate(['APP_DEBUG' => '0', 'DATABASE_URL' => 'mysql://root@localhost/db']);
|
||||||
$dotenv->populate(array('DATABASE_URL' => 'sqlite:///somedb.sqlite'));
|
$dotenv->populate(['DATABASE_URL' => 'sqlite:///somedb.sqlite']);
|
||||||
|
|
||||||
$this->assertSame('APP_ENV,DATABASE_URL', getenv('SYMFONY_DOTENV_VARS'));
|
$this->assertSame('APP_ENV,DATABASE_URL', getenv('SYMFONY_DOTENV_VARS'));
|
||||||
}
|
}
|
||||||
@ -407,7 +407,7 @@ class DotenvTest extends TestCase
|
|||||||
putenv('DOCUMENT_ROOT=/var/www');
|
putenv('DOCUMENT_ROOT=/var/www');
|
||||||
|
|
||||||
$dotenv = new Dotenv();
|
$dotenv = new Dotenv();
|
||||||
$dotenv->populate(array('FOO' => 'foo1', 'BAR' => 'bar1', 'BAZ' => 'baz1', 'DOCUMENT_ROOT' => '/boot'));
|
$dotenv->populate(['FOO' => 'foo1', 'BAR' => 'bar1', 'BAZ' => 'baz1', 'DOCUMENT_ROOT' => '/boot']);
|
||||||
|
|
||||||
$this->assertSame('foo1', getenv('FOO'));
|
$this->assertSame('foo1', getenv('FOO'));
|
||||||
$this->assertSame('bar1', getenv('BAR'));
|
$this->assertSame('bar1', getenv('BAR'));
|
||||||
|
@ -28,14 +28,14 @@ namespace Symfony\Component\EventDispatcher;
|
|||||||
*/
|
*/
|
||||||
class EventDispatcher implements EventDispatcherInterface
|
class EventDispatcher implements EventDispatcherInterface
|
||||||
{
|
{
|
||||||
private $listeners = array();
|
private $listeners = [];
|
||||||
private $sorted = array();
|
private $sorted = [];
|
||||||
private $optimized;
|
private $optimized;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
if (__CLASS__ === \get_class($this)) {
|
if (__CLASS__ === \get_class($this)) {
|
||||||
$this->optimized = array();
|
$this->optimized = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ class EventDispatcher implements EventDispatcherInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $this->optimized && null !== $eventName) {
|
if (null !== $this->optimized && null !== $eventName) {
|
||||||
$listeners = $this->optimized[$eventName] ?? (empty($this->listeners[$eventName]) ? array() : $this->optimizeListeners($eventName));
|
$listeners = $this->optimized[$eventName] ?? (empty($this->listeners[$eventName]) ? [] : $this->optimizeListeners($eventName));
|
||||||
} else {
|
} else {
|
||||||
$listeners = $this->getListeners($eventName);
|
$listeners = $this->getListeners($eventName);
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ class EventDispatcher implements EventDispatcherInterface
|
|||||||
{
|
{
|
||||||
if (null !== $eventName) {
|
if (null !== $eventName) {
|
||||||
if (empty($this->listeners[$eventName])) {
|
if (empty($this->listeners[$eventName])) {
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($this->sorted[$eventName])) {
|
if (!isset($this->sorted[$eventName])) {
|
||||||
@ -175,12 +175,12 @@ class EventDispatcher implements EventDispatcherInterface
|
|||||||
{
|
{
|
||||||
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
|
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
|
||||||
if (\is_string($params)) {
|
if (\is_string($params)) {
|
||||||
$this->addListener($eventName, array($subscriber, $params));
|
$this->addListener($eventName, [$subscriber, $params]);
|
||||||
} elseif (\is_string($params[0])) {
|
} elseif (\is_string($params[0])) {
|
||||||
$this->addListener($eventName, array($subscriber, $params[0]), isset($params[1]) ? $params[1] : 0);
|
$this->addListener($eventName, [$subscriber, $params[0]], isset($params[1]) ? $params[1] : 0);
|
||||||
} else {
|
} else {
|
||||||
foreach ($params as $listener) {
|
foreach ($params as $listener) {
|
||||||
$this->addListener($eventName, array($subscriber, $listener[0]), isset($listener[1]) ? $listener[1] : 0);
|
$this->addListener($eventName, [$subscriber, $listener[0]], isset($listener[1]) ? $listener[1] : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -194,10 +194,10 @@ class EventDispatcher implements EventDispatcherInterface
|
|||||||
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
|
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
|
||||||
if (\is_array($params) && \is_array($params[0])) {
|
if (\is_array($params) && \is_array($params[0])) {
|
||||||
foreach ($params as $listener) {
|
foreach ($params as $listener) {
|
||||||
$this->removeListener($eventName, array($subscriber, $listener[0]));
|
$this->removeListener($eventName, [$subscriber, $listener[0]]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->removeListener($eventName, array($subscriber, \is_string($params) ? $params : $params[0]));
|
$this->removeListener($eventName, [$subscriber, \is_string($params) ? $params : $params[0]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -228,7 +228,7 @@ class EventDispatcher implements EventDispatcherInterface
|
|||||||
private function sortListeners(string $eventName)
|
private function sortListeners(string $eventName)
|
||||||
{
|
{
|
||||||
krsort($this->listeners[$eventName]);
|
krsort($this->listeners[$eventName]);
|
||||||
$this->sorted[$eventName] = array();
|
$this->sorted[$eventName] = [];
|
||||||
|
|
||||||
foreach ($this->listeners[$eventName] as &$listeners) {
|
foreach ($this->listeners[$eventName] as &$listeners) {
|
||||||
foreach ($listeners as $k => $listener) {
|
foreach ($listeners as $k => $listener) {
|
||||||
@ -246,7 +246,7 @@ class EventDispatcher implements EventDispatcherInterface
|
|||||||
private function optimizeListeners(string $eventName): array
|
private function optimizeListeners(string $eventName): array
|
||||||
{
|
{
|
||||||
krsort($this->listeners[$eventName]);
|
krsort($this->listeners[$eventName]);
|
||||||
$this->optimized[$eventName] = array();
|
$this->optimized[$eventName] = [];
|
||||||
|
|
||||||
foreach ($this->listeners[$eventName] as &$listeners) {
|
foreach ($this->listeners[$eventName] as &$listeners) {
|
||||||
foreach ($listeners as &$listener) {
|
foreach ($listeners as &$listener) {
|
||||||
|
@ -50,15 +50,15 @@ class EventDispatcherTest extends TestCase
|
|||||||
|
|
||||||
public function testInitialState()
|
public function testInitialState()
|
||||||
{
|
{
|
||||||
$this->assertEquals(array(), $this->dispatcher->getListeners());
|
$this->assertEquals([], $this->dispatcher->getListeners());
|
||||||
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
|
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
|
||||||
$this->assertFalse($this->dispatcher->hasListeners(self::postFoo));
|
$this->assertFalse($this->dispatcher->hasListeners(self::postFoo));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddListener()
|
public function testAddListener()
|
||||||
{
|
{
|
||||||
$this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo'));
|
$this->dispatcher->addListener('pre.foo', [$this->listener, 'preFoo']);
|
||||||
$this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'));
|
$this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo']);
|
||||||
$this->assertTrue($this->dispatcher->hasListeners());
|
$this->assertTrue($this->dispatcher->hasListeners());
|
||||||
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
||||||
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
|
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
|
||||||
@ -76,15 +76,15 @@ class EventDispatcherTest extends TestCase
|
|||||||
$listener2->name = '2';
|
$listener2->name = '2';
|
||||||
$listener3->name = '3';
|
$listener3->name = '3';
|
||||||
|
|
||||||
$this->dispatcher->addListener('pre.foo', array($listener1, 'preFoo'), -10);
|
$this->dispatcher->addListener('pre.foo', [$listener1, 'preFoo'], -10);
|
||||||
$this->dispatcher->addListener('pre.foo', array($listener2, 'preFoo'), 10);
|
$this->dispatcher->addListener('pre.foo', [$listener2, 'preFoo'], 10);
|
||||||
$this->dispatcher->addListener('pre.foo', array($listener3, 'preFoo'));
|
$this->dispatcher->addListener('pre.foo', [$listener3, 'preFoo']);
|
||||||
|
|
||||||
$expected = array(
|
$expected = [
|
||||||
array($listener2, 'preFoo'),
|
[$listener2, 'preFoo'],
|
||||||
array($listener3, 'preFoo'),
|
[$listener3, 'preFoo'],
|
||||||
array($listener1, 'preFoo'),
|
[$listener1, 'preFoo'],
|
||||||
);
|
];
|
||||||
|
|
||||||
$this->assertSame($expected, $this->dispatcher->getListeners('pre.foo'));
|
$this->assertSame($expected, $this->dispatcher->getListeners('pre.foo'));
|
||||||
}
|
}
|
||||||
@ -105,10 +105,10 @@ class EventDispatcherTest extends TestCase
|
|||||||
$this->dispatcher->addListener('post.foo', $listener5);
|
$this->dispatcher->addListener('post.foo', $listener5);
|
||||||
$this->dispatcher->addListener('post.foo', $listener6, 10);
|
$this->dispatcher->addListener('post.foo', $listener6, 10);
|
||||||
|
|
||||||
$expected = array(
|
$expected = [
|
||||||
'pre.foo' => array($listener3, $listener2, $listener1),
|
'pre.foo' => [$listener3, $listener2, $listener1],
|
||||||
'post.foo' => array($listener6, $listener5, $listener4),
|
'post.foo' => [$listener6, $listener5, $listener4],
|
||||||
);
|
];
|
||||||
|
|
||||||
$this->assertSame($expected, $this->dispatcher->getListeners());
|
$this->assertSame($expected, $this->dispatcher->getListeners());
|
||||||
}
|
}
|
||||||
@ -129,8 +129,8 @@ class EventDispatcherTest extends TestCase
|
|||||||
|
|
||||||
public function testDispatch()
|
public function testDispatch()
|
||||||
{
|
{
|
||||||
$this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo'));
|
$this->dispatcher->addListener('pre.foo', [$this->listener, 'preFoo']);
|
||||||
$this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'));
|
$this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo']);
|
||||||
$this->dispatcher->dispatch(self::preFoo);
|
$this->dispatcher->dispatch(self::preFoo);
|
||||||
$this->assertTrue($this->listener->preFooInvoked);
|
$this->assertTrue($this->listener->preFooInvoked);
|
||||||
$this->assertFalse($this->listener->postFooInvoked);
|
$this->assertFalse($this->listener->postFooInvoked);
|
||||||
@ -160,8 +160,8 @@ class EventDispatcherTest extends TestCase
|
|||||||
// postFoo() stops the propagation, so only one listener should
|
// postFoo() stops the propagation, so only one listener should
|
||||||
// be executed
|
// be executed
|
||||||
// Manually set priority to enforce $this->listener to be called first
|
// Manually set priority to enforce $this->listener to be called first
|
||||||
$this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'), 10);
|
$this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo'], 10);
|
||||||
$this->dispatcher->addListener('post.foo', array($otherListener, 'postFoo'));
|
$this->dispatcher->addListener('post.foo', [$otherListener, 'postFoo']);
|
||||||
$this->dispatcher->dispatch(self::postFoo);
|
$this->dispatcher->dispatch(self::postFoo);
|
||||||
$this->assertTrue($this->listener->postFooInvoked);
|
$this->assertTrue($this->listener->postFooInvoked);
|
||||||
$this->assertFalse($otherListener->postFooInvoked);
|
$this->assertFalse($otherListener->postFooInvoked);
|
||||||
@ -169,7 +169,7 @@ class EventDispatcherTest extends TestCase
|
|||||||
|
|
||||||
public function testDispatchByPriority()
|
public function testDispatchByPriority()
|
||||||
{
|
{
|
||||||
$invoked = array();
|
$invoked = [];
|
||||||
$listener1 = function () use (&$invoked) {
|
$listener1 = function () use (&$invoked) {
|
||||||
$invoked[] = '1';
|
$invoked[] = '1';
|
||||||
};
|
};
|
||||||
@ -183,7 +183,7 @@ class EventDispatcherTest extends TestCase
|
|||||||
$this->dispatcher->addListener('pre.foo', $listener2);
|
$this->dispatcher->addListener('pre.foo', $listener2);
|
||||||
$this->dispatcher->addListener('pre.foo', $listener3, 10);
|
$this->dispatcher->addListener('pre.foo', $listener3, 10);
|
||||||
$this->dispatcher->dispatch(self::preFoo);
|
$this->dispatcher->dispatch(self::preFoo);
|
||||||
$this->assertEquals(array('3', '2', '1'), $invoked);
|
$this->assertEquals(['3', '2', '1'], $invoked);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveListener()
|
public function testRemoveListener()
|
||||||
@ -261,7 +261,7 @@ class EventDispatcherTest extends TestCase
|
|||||||
public function testEventReceivesTheDispatcherInstanceAsArgument()
|
public function testEventReceivesTheDispatcherInstanceAsArgument()
|
||||||
{
|
{
|
||||||
$listener = new TestWithDispatcher();
|
$listener = new TestWithDispatcher();
|
||||||
$this->dispatcher->addListener('test', array($listener, 'foo'));
|
$this->dispatcher->addListener('test', [$listener, 'foo']);
|
||||||
$this->assertNull($listener->name);
|
$this->assertNull($listener->name);
|
||||||
$this->assertNull($listener->dispatcher);
|
$this->assertNull($listener->dispatcher);
|
||||||
$this->dispatcher->dispatch('test');
|
$this->dispatcher->dispatch('test');
|
||||||
@ -298,7 +298,7 @@ class EventDispatcherTest extends TestCase
|
|||||||
$listener = function () {};
|
$listener = function () {};
|
||||||
$this->dispatcher->addListener('foo', $listener);
|
$this->dispatcher->addListener('foo', $listener);
|
||||||
$this->dispatcher->removeListener('foo', $listener);
|
$this->dispatcher->removeListener('foo', $listener);
|
||||||
$this->assertSame(array(), $this->dispatcher->getListeners());
|
$this->assertSame([], $this->dispatcher->getListeners());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHasListenersWithoutEventsReturnsFalseAfterHasListenersWithEventHasBeenCalled()
|
public function testHasListenersWithoutEventsReturnsFalseAfterHasListenersWithEventHasBeenCalled()
|
||||||
@ -310,7 +310,7 @@ class EventDispatcherTest extends TestCase
|
|||||||
public function testHasListenersIsLazy()
|
public function testHasListenersIsLazy()
|
||||||
{
|
{
|
||||||
$called = 0;
|
$called = 0;
|
||||||
$listener = array(function () use (&$called) { ++$called; }, 'onFoo');
|
$listener = [function () use (&$called) { ++$called; }, 'onFoo'];
|
||||||
$this->dispatcher->addListener('foo', $listener);
|
$this->dispatcher->addListener('foo', $listener);
|
||||||
$this->assertTrue($this->dispatcher->hasListeners());
|
$this->assertTrue($this->dispatcher->hasListeners());
|
||||||
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
||||||
@ -325,7 +325,7 @@ class EventDispatcherTest extends TestCase
|
|||||||
|
|
||||||
return new TestWithDispatcher();
|
return new TestWithDispatcher();
|
||||||
};
|
};
|
||||||
$this->dispatcher->addListener('foo', array($factory, 'foo'));
|
$this->dispatcher->addListener('foo', [$factory, 'foo']);
|
||||||
$this->assertSame(0, $called);
|
$this->assertSame(0, $called);
|
||||||
$this->dispatcher->dispatch('foo', new Event());
|
$this->dispatcher->dispatch('foo', new Event());
|
||||||
$this->dispatcher->dispatch('foo', new Event());
|
$this->dispatcher->dispatch('foo', new Event());
|
||||||
@ -337,14 +337,14 @@ class EventDispatcherTest extends TestCase
|
|||||||
$test = new TestWithDispatcher();
|
$test = new TestWithDispatcher();
|
||||||
$factory = function () use ($test) { return $test; };
|
$factory = function () use ($test) { return $test; };
|
||||||
|
|
||||||
$this->dispatcher->addListener('foo', array($factory, 'foo'));
|
$this->dispatcher->addListener('foo', [$factory, 'foo']);
|
||||||
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
||||||
$this->dispatcher->removeListener('foo', array($test, 'foo'));
|
$this->dispatcher->removeListener('foo', [$test, 'foo']);
|
||||||
$this->assertFalse($this->dispatcher->hasListeners('foo'));
|
$this->assertFalse($this->dispatcher->hasListeners('foo'));
|
||||||
|
|
||||||
$this->dispatcher->addListener('foo', array($test, 'foo'));
|
$this->dispatcher->addListener('foo', [$test, 'foo']);
|
||||||
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
||||||
$this->dispatcher->removeListener('foo', array($factory, 'foo'));
|
$this->dispatcher->removeListener('foo', [$factory, 'foo']);
|
||||||
$this->assertFalse($this->dispatcher->hasListeners('foo'));
|
$this->assertFalse($this->dispatcher->hasListeners('foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,12 +353,12 @@ class EventDispatcherTest extends TestCase
|
|||||||
$test = new TestWithDispatcher();
|
$test = new TestWithDispatcher();
|
||||||
$factory = function () use ($test) { return $test; };
|
$factory = function () use ($test) { return $test; };
|
||||||
|
|
||||||
$this->dispatcher->addListener('foo', array($factory, 'foo'), 3);
|
$this->dispatcher->addListener('foo', [$factory, 'foo'], 3);
|
||||||
$this->assertSame(3, $this->dispatcher->getListenerPriority('foo', array($test, 'foo')));
|
$this->assertSame(3, $this->dispatcher->getListenerPriority('foo', [$test, 'foo']));
|
||||||
$this->dispatcher->removeListener('foo', array($factory, 'foo'));
|
$this->dispatcher->removeListener('foo', [$factory, 'foo']);
|
||||||
|
|
||||||
$this->dispatcher->addListener('foo', array($test, 'foo'), 5);
|
$this->dispatcher->addListener('foo', [$test, 'foo'], 5);
|
||||||
$this->assertSame(5, $this->dispatcher->getListenerPriority('foo', array($factory, 'foo')));
|
$this->assertSame(5, $this->dispatcher->getListenerPriority('foo', [$factory, 'foo']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetLazyListeners()
|
public function testGetLazyListeners()
|
||||||
@ -366,31 +366,31 @@ class EventDispatcherTest extends TestCase
|
|||||||
$test = new TestWithDispatcher();
|
$test = new TestWithDispatcher();
|
||||||
$factory = function () use ($test) { return $test; };
|
$factory = function () use ($test) { return $test; };
|
||||||
|
|
||||||
$this->dispatcher->addListener('foo', array($factory, 'foo'), 3);
|
$this->dispatcher->addListener('foo', [$factory, 'foo'], 3);
|
||||||
$this->assertSame(array(array($test, 'foo')), $this->dispatcher->getListeners('foo'));
|
$this->assertSame([[$test, 'foo']], $this->dispatcher->getListeners('foo'));
|
||||||
|
|
||||||
$this->dispatcher->removeListener('foo', array($test, 'foo'));
|
$this->dispatcher->removeListener('foo', [$test, 'foo']);
|
||||||
$this->dispatcher->addListener('bar', array($factory, 'foo'), 3);
|
$this->dispatcher->addListener('bar', [$factory, 'foo'], 3);
|
||||||
$this->assertSame(array('bar' => array(array($test, 'foo'))), $this->dispatcher->getListeners());
|
$this->assertSame(['bar' => [[$test, 'foo']]], $this->dispatcher->getListeners());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMutatingWhilePropagationIsStopped()
|
public function testMutatingWhilePropagationIsStopped()
|
||||||
{
|
{
|
||||||
$testLoaded = false;
|
$testLoaded = false;
|
||||||
$test = new TestEventListener();
|
$test = new TestEventListener();
|
||||||
$this->dispatcher->addListener('foo', array($test, 'postFoo'));
|
$this->dispatcher->addListener('foo', [$test, 'postFoo']);
|
||||||
$this->dispatcher->addListener('foo', array(function () use ($test, &$testLoaded) {
|
$this->dispatcher->addListener('foo', [function () use ($test, &$testLoaded) {
|
||||||
$testLoaded = true;
|
$testLoaded = true;
|
||||||
|
|
||||||
return $test;
|
return $test;
|
||||||
}, 'preFoo'));
|
}, 'preFoo']);
|
||||||
|
|
||||||
$this->dispatcher->dispatch('foo');
|
$this->dispatcher->dispatch('foo');
|
||||||
|
|
||||||
$this->assertTrue($test->postFooInvoked);
|
$this->assertTrue($test->postFooInvoked);
|
||||||
$this->assertFalse($test->preFooInvoked);
|
$this->assertFalse($test->preFooInvoked);
|
||||||
|
|
||||||
$this->assertsame(0, $this->dispatcher->getListenerPriority('foo', array($test, 'preFoo')));
|
$this->assertsame(0, $this->dispatcher->getListenerPriority('foo', [$test, 'preFoo']));
|
||||||
|
|
||||||
$test->preFoo(new Event());
|
$test->preFoo(new Event());
|
||||||
$this->dispatcher->dispatch('foo');
|
$this->dispatcher->dispatch('foo');
|
||||||
@ -444,7 +444,7 @@ class TestEventSubscriber implements EventSubscriberInterface
|
|||||||
{
|
{
|
||||||
public static function getSubscribedEvents()
|
public static function getSubscribedEvents()
|
||||||
{
|
{
|
||||||
return array('pre.foo' => 'preFoo', 'post.foo' => 'postFoo');
|
return ['pre.foo' => 'preFoo', 'post.foo' => 'postFoo'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,10 +452,10 @@ class TestEventSubscriberWithPriorities implements EventSubscriberInterface
|
|||||||
{
|
{
|
||||||
public static function getSubscribedEvents()
|
public static function getSubscribedEvents()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
'pre.foo' => array('preFoo', 10),
|
'pre.foo' => ['preFoo', 10],
|
||||||
'post.foo' => array('postFoo'),
|
'post.foo' => ['postFoo'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,9 +463,9 @@ class TestEventSubscriberWithMultipleListeners implements EventSubscriberInterfa
|
|||||||
{
|
{
|
||||||
public static function getSubscribedEvents()
|
public static function getSubscribedEvents()
|
||||||
{
|
{
|
||||||
return array('pre.foo' => array(
|
return ['pre.foo' => [
|
||||||
array('preFoo1'),
|
['preFoo1'],
|
||||||
array('preFoo2', 10),
|
['preFoo2', 10],
|
||||||
));
|
]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ abstract class BaseType extends AbstractType
|
|||||||
'auto_initialize' => true,
|
'auto_initialize' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$resolver->setAllowedTypes('block_prefix', array('null', 'string'));
|
$resolver->setAllowedTypes('block_prefix', ['null', 'string']);
|
||||||
$resolver->setAllowedTypes('attr', 'array');
|
$resolver->setAllowedTypes('attr', 'array');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer();
|
$transformer = new DateIntervalToArrayTransformer();
|
||||||
$input = new \DateInterval('P1Y2M3DT4H5M6S');
|
$input = new \DateInterval('P1Y2M3DT4H5M6S');
|
||||||
$output = array(
|
$output = [
|
||||||
'years' => '1',
|
'years' => '1',
|
||||||
'months' => '2',
|
'months' => '2',
|
||||||
'days' => '3',
|
'days' => '3',
|
||||||
@ -32,14 +32,14 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||||||
'minutes' => '5',
|
'minutes' => '5',
|
||||||
'seconds' => '6',
|
'seconds' => '6',
|
||||||
'invert' => false,
|
'invert' => false,
|
||||||
);
|
];
|
||||||
$this->assertSame($output, $transformer->transform($input));
|
$this->assertSame($output, $transformer->transform($input));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTransformEmpty()
|
public function testTransformEmpty()
|
||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer();
|
$transformer = new DateIntervalToArrayTransformer();
|
||||||
$output = array(
|
$output = [
|
||||||
'years' => '',
|
'years' => '',
|
||||||
'months' => '',
|
'months' => '',
|
||||||
'days' => '',
|
'days' => '',
|
||||||
@ -47,43 +47,43 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||||||
'minutes' => '',
|
'minutes' => '',
|
||||||
'seconds' => '',
|
'seconds' => '',
|
||||||
'invert' => false,
|
'invert' => false,
|
||||||
);
|
];
|
||||||
$this->assertSame($output, $transformer->transform(null));
|
$this->assertSame($output, $transformer->transform(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTransformEmptyWithFields()
|
public function testTransformEmptyWithFields()
|
||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer(array('years', 'weeks', 'minutes', 'seconds'));
|
$transformer = new DateIntervalToArrayTransformer(['years', 'weeks', 'minutes', 'seconds']);
|
||||||
$output = array(
|
$output = [
|
||||||
'years' => '',
|
'years' => '',
|
||||||
'weeks' => '',
|
'weeks' => '',
|
||||||
'minutes' => '',
|
'minutes' => '',
|
||||||
'seconds' => '',
|
'seconds' => '',
|
||||||
);
|
];
|
||||||
$this->assertSame($output, $transformer->transform(null));
|
$this->assertSame($output, $transformer->transform(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTransformWithFields()
|
public function testTransformWithFields()
|
||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer(array('years', 'minutes', 'seconds'));
|
$transformer = new DateIntervalToArrayTransformer(['years', 'minutes', 'seconds']);
|
||||||
$input = new \DateInterval('P1Y2M3DT4H5M6S');
|
$input = new \DateInterval('P1Y2M3DT4H5M6S');
|
||||||
$output = array(
|
$output = [
|
||||||
'years' => '1',
|
'years' => '1',
|
||||||
'minutes' => '5',
|
'minutes' => '5',
|
||||||
'seconds' => '6',
|
'seconds' => '6',
|
||||||
);
|
];
|
||||||
$this->assertSame($output, $transformer->transform($input));
|
$this->assertSame($output, $transformer->transform($input));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTransformWithWeek()
|
public function testTransformWithWeek()
|
||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer(array('weeks', 'minutes', 'seconds'));
|
$transformer = new DateIntervalToArrayTransformer(['weeks', 'minutes', 'seconds']);
|
||||||
$input = new \DateInterval('P1Y2M3WT4H5M6S');
|
$input = new \DateInterval('P1Y2M3WT4H5M6S');
|
||||||
$output = array(
|
$output = [
|
||||||
'weeks' => '3',
|
'weeks' => '3',
|
||||||
'minutes' => '5',
|
'minutes' => '5',
|
||||||
'seconds' => '6',
|
'seconds' => '6',
|
||||||
);
|
];
|
||||||
$input = $transformer->transform($input);
|
$input = $transformer->transform($input);
|
||||||
ksort($input);
|
ksort($input);
|
||||||
ksort($output);
|
ksort($output);
|
||||||
@ -92,13 +92,13 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||||||
|
|
||||||
public function testTransformWithZeroWeek()
|
public function testTransformWithZeroWeek()
|
||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer(array('weeks', 'minutes', 'seconds'));
|
$transformer = new DateIntervalToArrayTransformer(['weeks', 'minutes', 'seconds']);
|
||||||
$input = new \DateInterval('P1Y2M0WT4H5M6S');
|
$input = new \DateInterval('P1Y2M0WT4H5M6S');
|
||||||
$output = array(
|
$output = [
|
||||||
'weeks' => '0',
|
'weeks' => '0',
|
||||||
'minutes' => '5',
|
'minutes' => '5',
|
||||||
'seconds' => '6',
|
'seconds' => '6',
|
||||||
);
|
];
|
||||||
$input = $transformer->transform($input);
|
$input = $transformer->transform($input);
|
||||||
ksort($input);
|
ksort($input);
|
||||||
ksort($output);
|
ksort($output);
|
||||||
@ -107,13 +107,13 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||||||
|
|
||||||
public function testTransformDaysToWeeks()
|
public function testTransformDaysToWeeks()
|
||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer(array('weeks', 'minutes', 'seconds'));
|
$transformer = new DateIntervalToArrayTransformer(['weeks', 'minutes', 'seconds']);
|
||||||
$input = new \DateInterval('P1Y2M23DT4H5M6S');
|
$input = new \DateInterval('P1Y2M23DT4H5M6S');
|
||||||
$output = array(
|
$output = [
|
||||||
'weeks' => '3',
|
'weeks' => '3',
|
||||||
'minutes' => '5',
|
'minutes' => '5',
|
||||||
'seconds' => '6',
|
'seconds' => '6',
|
||||||
);
|
];
|
||||||
$input = $transformer->transform($input);
|
$input = $transformer->transform($input);
|
||||||
ksort($input);
|
ksort($input);
|
||||||
ksort($output);
|
ksort($output);
|
||||||
@ -122,25 +122,25 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||||||
|
|
||||||
public function testTransformDaysNotOverflowingToWeeks()
|
public function testTransformDaysNotOverflowingToWeeks()
|
||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer(array('days', 'minutes', 'seconds'));
|
$transformer = new DateIntervalToArrayTransformer(['days', 'minutes', 'seconds']);
|
||||||
$input = new \DateInterval('P1Y2M23DT4H5M6S');
|
$input = new \DateInterval('P1Y2M23DT4H5M6S');
|
||||||
$output = array(
|
$output = [
|
||||||
'days' => '23',
|
'days' => '23',
|
||||||
'minutes' => '5',
|
'minutes' => '5',
|
||||||
'seconds' => '6',
|
'seconds' => '6',
|
||||||
);
|
];
|
||||||
$this->assertSame($output, $transformer->transform($input));
|
$this->assertSame($output, $transformer->transform($input));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTransformWithInvert()
|
public function testTransformWithInvert()
|
||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer(array('years', 'invert'));
|
$transformer = new DateIntervalToArrayTransformer(['years', 'invert']);
|
||||||
$input = new \DateInterval('P1Y');
|
$input = new \DateInterval('P1Y');
|
||||||
$input->invert = 1;
|
$input->invert = 1;
|
||||||
$output = array(
|
$output = [
|
||||||
'years' => '1',
|
'years' => '1',
|
||||||
'invert' => true,
|
'invert' => true,
|
||||||
);
|
];
|
||||||
$this->assertSame($output, $transformer->transform($input));
|
$this->assertSame($output, $transformer->transform($input));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer(null, true);
|
$transformer = new DateIntervalToArrayTransformer(null, true);
|
||||||
$input = new \DateInterval('P1Y2M3DT4H5M6S');
|
$input = new \DateInterval('P1Y2M3DT4H5M6S');
|
||||||
$output = array(
|
$output = [
|
||||||
'years' => '01',
|
'years' => '01',
|
||||||
'months' => '02',
|
'months' => '02',
|
||||||
'days' => '03',
|
'days' => '03',
|
||||||
@ -156,19 +156,19 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||||||
'minutes' => '05',
|
'minutes' => '05',
|
||||||
'seconds' => '06',
|
'seconds' => '06',
|
||||||
'invert' => false,
|
'invert' => false,
|
||||||
);
|
];
|
||||||
$this->assertSame($output, $transformer->transform($input));
|
$this->assertSame($output, $transformer->transform($input));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTransformWithFieldsAndPadding()
|
public function testTransformWithFieldsAndPadding()
|
||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer(array('years', 'minutes', 'seconds'), true);
|
$transformer = new DateIntervalToArrayTransformer(['years', 'minutes', 'seconds'], true);
|
||||||
$input = new \DateInterval('P1Y2M3DT4H5M6S');
|
$input = new \DateInterval('P1Y2M3DT4H5M6S');
|
||||||
$output = array(
|
$output = [
|
||||||
'years' => '01',
|
'years' => '01',
|
||||||
'minutes' => '05',
|
'minutes' => '05',
|
||||||
'seconds' => '06',
|
'seconds' => '06',
|
||||||
);
|
];
|
||||||
$this->assertSame($output, $transformer->transform($input));
|
$this->assertSame($output, $transformer->transform($input));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,19 +183,19 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||||||
public function testReverseTransformWithUnsetFields()
|
public function testReverseTransformWithUnsetFields()
|
||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer();
|
$transformer = new DateIntervalToArrayTransformer();
|
||||||
$input = array('years' => '1');
|
$input = ['years' => '1'];
|
||||||
$this->expectException(TransformationFailedException::class);
|
$this->expectException(TransformationFailedException::class);
|
||||||
$transformer->reverseTransform($input);
|
$transformer->reverseTransform($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReverseTransformWithEmptyFields()
|
public function testReverseTransformWithEmptyFields()
|
||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer(array('years', 'minutes', 'seconds'));
|
$transformer = new DateIntervalToArrayTransformer(['years', 'minutes', 'seconds']);
|
||||||
$input = array(
|
$input = [
|
||||||
'years' => '1',
|
'years' => '1',
|
||||||
'minutes' => '',
|
'minutes' => '',
|
||||||
'seconds' => '6',
|
'seconds' => '6',
|
||||||
);
|
];
|
||||||
if (method_exists($this, 'expectException')) {
|
if (method_exists($this, 'expectException')) {
|
||||||
$this->expectException(TransformationFailedException::class);
|
$this->expectException(TransformationFailedException::class);
|
||||||
$this->expectExceptionMessage('This amount of "minutes" is invalid');
|
$this->expectExceptionMessage('This amount of "minutes" is invalid');
|
||||||
@ -207,10 +207,10 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||||||
|
|
||||||
public function testReverseTransformWithWrongInvertType()
|
public function testReverseTransformWithWrongInvertType()
|
||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer(array('invert'));
|
$transformer = new DateIntervalToArrayTransformer(['invert']);
|
||||||
$input = array(
|
$input = [
|
||||||
'invert' => '1',
|
'invert' => '1',
|
||||||
);
|
];
|
||||||
if (method_exists($this, 'expectException')) {
|
if (method_exists($this, 'expectException')) {
|
||||||
$this->expectException(TransformationFailedException::class);
|
$this->expectException(TransformationFailedException::class);
|
||||||
$this->expectExceptionMessage('The value of "invert" must be boolean');
|
$this->expectExceptionMessage('The value of "invert" must be boolean');
|
||||||
@ -223,7 +223,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||||||
public function testReverseTransform()
|
public function testReverseTransform()
|
||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer();
|
$transformer = new DateIntervalToArrayTransformer();
|
||||||
$input = array(
|
$input = [
|
||||||
'years' => '1',
|
'years' => '1',
|
||||||
'months' => '2',
|
'months' => '2',
|
||||||
'days' => '3',
|
'days' => '3',
|
||||||
@ -231,7 +231,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||||||
'minutes' => '5',
|
'minutes' => '5',
|
||||||
'seconds' => '6',
|
'seconds' => '6',
|
||||||
'invert' => false,
|
'invert' => false,
|
||||||
);
|
];
|
||||||
$output = new \DateInterval('P01Y02M03DT04H05M06S');
|
$output = new \DateInterval('P01Y02M03DT04H05M06S');
|
||||||
$this->assertDateIntervalEquals($output, $transformer->reverseTransform($input));
|
$this->assertDateIntervalEquals($output, $transformer->reverseTransform($input));
|
||||||
}
|
}
|
||||||
@ -239,28 +239,28 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||||||
public function testReverseTransformWithWeek()
|
public function testReverseTransformWithWeek()
|
||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer(
|
$transformer = new DateIntervalToArrayTransformer(
|
||||||
array('years', 'months', 'weeks', 'hours', 'minutes', 'seconds')
|
['years', 'months', 'weeks', 'hours', 'minutes', 'seconds']
|
||||||
);
|
);
|
||||||
$input = array(
|
$input = [
|
||||||
'years' => '1',
|
'years' => '1',
|
||||||
'months' => '2',
|
'months' => '2',
|
||||||
'weeks' => '3',
|
'weeks' => '3',
|
||||||
'hours' => '4',
|
'hours' => '4',
|
||||||
'minutes' => '5',
|
'minutes' => '5',
|
||||||
'seconds' => '6',
|
'seconds' => '6',
|
||||||
);
|
];
|
||||||
$output = new \DateInterval('P1Y2M21DT4H5M6S');
|
$output = new \DateInterval('P1Y2M21DT4H5M6S');
|
||||||
$this->assertDateIntervalEquals($output, $transformer->reverseTransform($input));
|
$this->assertDateIntervalEquals($output, $transformer->reverseTransform($input));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReverseTransformWithFields()
|
public function testReverseTransformWithFields()
|
||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer(array('years', 'minutes', 'seconds'));
|
$transformer = new DateIntervalToArrayTransformer(['years', 'minutes', 'seconds']);
|
||||||
$input = array(
|
$input = [
|
||||||
'years' => '1',
|
'years' => '1',
|
||||||
'minutes' => '5',
|
'minutes' => '5',
|
||||||
'seconds' => '6',
|
'seconds' => '6',
|
||||||
);
|
];
|
||||||
$output = new \DateInterval('P1Y0M0DT0H5M6S');
|
$output = new \DateInterval('P1Y0M0DT0H5M6S');
|
||||||
$this->assertDateIntervalEquals($output, $transformer->reverseTransform($input));
|
$this->assertDateIntervalEquals($output, $transformer->reverseTransform($input));
|
||||||
}
|
}
|
||||||
@ -268,17 +268,17 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
|
|||||||
public function testBothTransformsWithWeek()
|
public function testBothTransformsWithWeek()
|
||||||
{
|
{
|
||||||
$transformer = new DateIntervalToArrayTransformer(
|
$transformer = new DateIntervalToArrayTransformer(
|
||||||
array('years', 'months', 'weeks', 'hours', 'minutes', 'seconds')
|
['years', 'months', 'weeks', 'hours', 'minutes', 'seconds']
|
||||||
);
|
);
|
||||||
$interval = new \DateInterval('P1Y2M21DT4H5M6S');
|
$interval = new \DateInterval('P1Y2M21DT4H5M6S');
|
||||||
$array = array(
|
$array = [
|
||||||
'years' => '1',
|
'years' => '1',
|
||||||
'months' => '2',
|
'months' => '2',
|
||||||
'weeks' => '3',
|
'weeks' => '3',
|
||||||
'hours' => '4',
|
'hours' => '4',
|
||||||
'minutes' => '5',
|
'minutes' => '5',
|
||||||
'seconds' => '6',
|
'seconds' => '6',
|
||||||
);
|
];
|
||||||
$input = $transformer->transform($interval);
|
$input = $transformer->transform($interval);
|
||||||
ksort($input);
|
ksort($input);
|
||||||
ksort($array);
|
ksort($array);
|
||||||
|
@ -20,22 +20,22 @@ class CollectionTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testContainsNoChildByDefault()
|
public function testContainsNoChildByDefault()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
));
|
]);
|
||||||
|
|
||||||
$this->assertCount(0, $form);
|
$this->assertCount(0, $form);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetDataAdjustsSize()
|
public function testSetDataAdjustsSize()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
'entry_options' => array(
|
'entry_options' => [
|
||||||
'attr' => array('maxlength' => 20),
|
'attr' => ['maxlength' => 20],
|
||||||
),
|
],
|
||||||
));
|
]);
|
||||||
$form->setData(array('foo@foo.com', 'foo@bar.com'));
|
$form->setData(['foo@foo.com', 'foo@bar.com']);
|
||||||
|
|
||||||
$this->assertInstanceOf('Symfony\Component\Form\Form', $form[0]);
|
$this->assertInstanceOf('Symfony\Component\Form\Form', $form[0]);
|
||||||
$this->assertInstanceOf('Symfony\Component\Form\Form', $form[1]);
|
$this->assertInstanceOf('Symfony\Component\Form\Form', $form[1]);
|
||||||
@ -47,7 +47,7 @@ class CollectionTypeTest extends BaseTypeTest
|
|||||||
$this->assertEquals(20, $formAttrs0['maxlength']);
|
$this->assertEquals(20, $formAttrs0['maxlength']);
|
||||||
$this->assertEquals(20, $formAttrs1['maxlength']);
|
$this->assertEquals(20, $formAttrs1['maxlength']);
|
||||||
|
|
||||||
$form->setData(array('foo@baz.com'));
|
$form->setData(['foo@baz.com']);
|
||||||
$this->assertInstanceOf('Symfony\Component\Form\Form', $form[0]);
|
$this->assertInstanceOf('Symfony\Component\Form\Form', $form[0]);
|
||||||
$this->assertArrayNotHasKey(1, $form);
|
$this->assertArrayNotHasKey(1, $form);
|
||||||
$this->assertCount(1, $form);
|
$this->assertCount(1, $form);
|
||||||
@ -58,20 +58,20 @@ class CollectionTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testThrowsExceptionIfObjectIsNotTraversable()
|
public function testThrowsExceptionIfObjectIsNotTraversable()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
));
|
]);
|
||||||
$this->expectException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
$this->expectException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
||||||
$form->setData(new \stdClass());
|
$form->setData(new \stdClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotResizedIfSubmittedWithMissingData()
|
public function testNotResizedIfSubmittedWithMissingData()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
));
|
]);
|
||||||
$form->setData(array('foo@foo.com', 'bar@bar.com'));
|
$form->setData(['foo@foo.com', 'bar@bar.com']);
|
||||||
$form->submit(array('foo@bar.com'));
|
$form->submit(['foo@bar.com']);
|
||||||
|
|
||||||
$this->assertTrue($form->has('0'));
|
$this->assertTrue($form->has('0'));
|
||||||
$this->assertTrue($form->has('1'));
|
$this->assertTrue($form->has('1'));
|
||||||
@ -81,106 +81,106 @@ class CollectionTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testResizedDownIfSubmittedWithMissingDataAndAllowDelete()
|
public function testResizedDownIfSubmittedWithMissingDataAndAllowDelete()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
'allow_delete' => true,
|
'allow_delete' => true,
|
||||||
));
|
]);
|
||||||
$form->setData(array('foo@foo.com', 'bar@bar.com'));
|
$form->setData(['foo@foo.com', 'bar@bar.com']);
|
||||||
$form->submit(array('foo@foo.com'));
|
$form->submit(['foo@foo.com']);
|
||||||
|
|
||||||
$this->assertTrue($form->has('0'));
|
$this->assertTrue($form->has('0'));
|
||||||
$this->assertFalse($form->has('1'));
|
$this->assertFalse($form->has('1'));
|
||||||
$this->assertEquals('foo@foo.com', $form[0]->getData());
|
$this->assertEquals('foo@foo.com', $form[0]->getData());
|
||||||
$this->assertEquals(array('foo@foo.com'), $form->getData());
|
$this->assertEquals(['foo@foo.com'], $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testResizedDownIfSubmittedWithEmptyDataAndDeleteEmpty()
|
public function testResizedDownIfSubmittedWithEmptyDataAndDeleteEmpty()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
'allow_delete' => true,
|
'allow_delete' => true,
|
||||||
'delete_empty' => true,
|
'delete_empty' => true,
|
||||||
));
|
]);
|
||||||
|
|
||||||
$form->setData(array('foo@foo.com', 'bar@bar.com'));
|
$form->setData(['foo@foo.com', 'bar@bar.com']);
|
||||||
$form->submit(array('foo@foo.com', ''));
|
$form->submit(['foo@foo.com', '']);
|
||||||
|
|
||||||
$this->assertTrue($form->has('0'));
|
$this->assertTrue($form->has('0'));
|
||||||
$this->assertFalse($form->has('1'));
|
$this->assertFalse($form->has('1'));
|
||||||
$this->assertEquals('foo@foo.com', $form[0]->getData());
|
$this->assertEquals('foo@foo.com', $form[0]->getData());
|
||||||
$this->assertEquals(array('foo@foo.com'), $form->getData());
|
$this->assertEquals(['foo@foo.com'], $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testResizedDownWithDeleteEmptyCallable()
|
public function testResizedDownWithDeleteEmptyCallable()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
'entry_type' => AuthorType::class,
|
'entry_type' => AuthorType::class,
|
||||||
'allow_delete' => true,
|
'allow_delete' => true,
|
||||||
'delete_empty' => function (Author $obj = null) {
|
'delete_empty' => function (Author $obj = null) {
|
||||||
return null === $obj || empty($obj->firstName);
|
return null === $obj || empty($obj->firstName);
|
||||||
},
|
},
|
||||||
));
|
]);
|
||||||
|
|
||||||
$form->setData(array(new Author('Bob'), new Author('Alice')));
|
$form->setData([new Author('Bob'), new Author('Alice')]);
|
||||||
$form->submit(array(array('firstName' => 'Bob'), array('firstName' => '')));
|
$form->submit([['firstName' => 'Bob'], ['firstName' => '']]);
|
||||||
|
|
||||||
$this->assertTrue($form->has('0'));
|
$this->assertTrue($form->has('0'));
|
||||||
$this->assertFalse($form->has('1'));
|
$this->assertFalse($form->has('1'));
|
||||||
$this->assertEquals(new Author('Bob'), $form[0]->getData());
|
$this->assertEquals(new Author('Bob'), $form[0]->getData());
|
||||||
$this->assertEquals(array(new Author('Bob')), $form->getData());
|
$this->assertEquals([new Author('Bob')], $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testResizedDownIfSubmittedWithCompoundEmptyDataDeleteEmptyAndNoDataClass()
|
public function testResizedDownIfSubmittedWithCompoundEmptyDataDeleteEmptyAndNoDataClass()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
'entry_type' => AuthorType::class,
|
'entry_type' => AuthorType::class,
|
||||||
// If the field is not required, no new Author will be created if the
|
// If the field is not required, no new Author will be created if the
|
||||||
// form is completely empty
|
// form is completely empty
|
||||||
'entry_options' => array('data_class' => null),
|
'entry_options' => ['data_class' => null],
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'allow_delete' => true,
|
'allow_delete' => true,
|
||||||
'delete_empty' => function ($author) {
|
'delete_empty' => function ($author) {
|
||||||
return empty($author['firstName']);
|
return empty($author['firstName']);
|
||||||
},
|
},
|
||||||
));
|
]);
|
||||||
$form->setData(array(array('firstName' => 'first', 'lastName' => 'last')));
|
$form->setData([['firstName' => 'first', 'lastName' => 'last']]);
|
||||||
$form->submit(array(
|
$form->submit([
|
||||||
array('firstName' => 's_first', 'lastName' => 's_last'),
|
['firstName' => 's_first', 'lastName' => 's_last'],
|
||||||
array('firstName' => '', 'lastName' => ''),
|
['firstName' => '', 'lastName' => ''],
|
||||||
));
|
]);
|
||||||
$this->assertTrue($form->has('0'));
|
$this->assertTrue($form->has('0'));
|
||||||
$this->assertFalse($form->has('1'));
|
$this->assertFalse($form->has('1'));
|
||||||
$this->assertEquals(array('firstName' => 's_first', 'lastName' => 's_last'), $form[0]->getData());
|
$this->assertEquals(['firstName' => 's_first', 'lastName' => 's_last'], $form[0]->getData());
|
||||||
$this->assertEquals(array(array('firstName' => 's_first', 'lastName' => 's_last')), $form->getData());
|
$this->assertEquals([['firstName' => 's_first', 'lastName' => 's_last']], $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDontAddEmptyDataIfDeleteEmpty()
|
public function testDontAddEmptyDataIfDeleteEmpty()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'delete_empty' => true,
|
'delete_empty' => true,
|
||||||
));
|
]);
|
||||||
|
|
||||||
$form->setData(array('foo@foo.com'));
|
$form->setData(['foo@foo.com']);
|
||||||
$form->submit(array('foo@foo.com', ''));
|
$form->submit(['foo@foo.com', '']);
|
||||||
|
|
||||||
$this->assertTrue($form->has('0'));
|
$this->assertTrue($form->has('0'));
|
||||||
$this->assertFalse($form->has('1'));
|
$this->assertFalse($form->has('1'));
|
||||||
$this->assertEquals('foo@foo.com', $form[0]->getData());
|
$this->assertEquals('foo@foo.com', $form[0]->getData());
|
||||||
$this->assertEquals(array('foo@foo.com'), $form->getData());
|
$this->assertEquals(['foo@foo.com'], $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNoDeleteEmptyIfDeleteNotAllowed()
|
public function testNoDeleteEmptyIfDeleteNotAllowed()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
'allow_delete' => false,
|
'allow_delete' => false,
|
||||||
'delete_empty' => true,
|
'delete_empty' => true,
|
||||||
));
|
]);
|
||||||
|
|
||||||
$form->setData(array('foo@foo.com'));
|
$form->setData(['foo@foo.com']);
|
||||||
$form->submit(array(''));
|
$form->submit(['']);
|
||||||
|
|
||||||
$this->assertTrue($form->has('0'));
|
$this->assertTrue($form->has('0'));
|
||||||
$this->assertEquals('', $form[0]->getData());
|
$this->assertEquals('', $form[0]->getData());
|
||||||
@ -188,34 +188,34 @@ class CollectionTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testResizedDownIfSubmittedWithCompoundEmptyDataAndDeleteEmpty()
|
public function testResizedDownIfSubmittedWithCompoundEmptyDataAndDeleteEmpty()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
'entry_type' => 'Symfony\Component\Form\Tests\Fixtures\AuthorType',
|
'entry_type' => 'Symfony\Component\Form\Tests\Fixtures\AuthorType',
|
||||||
// If the field is not required, no new Author will be created if the
|
// If the field is not required, no new Author will be created if the
|
||||||
// form is completely empty
|
// form is completely empty
|
||||||
'entry_options' => array('required' => false),
|
'entry_options' => ['required' => false],
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'delete_empty' => true,
|
'delete_empty' => true,
|
||||||
));
|
]);
|
||||||
|
|
||||||
$form->setData(array(new Author('first', 'last')));
|
$form->setData([new Author('first', 'last')]);
|
||||||
$form->submit(array(
|
$form->submit([
|
||||||
array('firstName' => 's_first', 'lastName' => 's_last'),
|
['firstName' => 's_first', 'lastName' => 's_last'],
|
||||||
array('firstName' => '', 'lastName' => ''),
|
['firstName' => '', 'lastName' => ''],
|
||||||
));
|
]);
|
||||||
|
|
||||||
$this->assertTrue($form->has('0'));
|
$this->assertTrue($form->has('0'));
|
||||||
$this->assertFalse($form->has('1'));
|
$this->assertFalse($form->has('1'));
|
||||||
$this->assertEquals(new Author('s_first', 's_last'), $form[0]->getData());
|
$this->assertEquals(new Author('s_first', 's_last'), $form[0]->getData());
|
||||||
$this->assertEquals(array(new Author('s_first', 's_last')), $form->getData());
|
$this->assertEquals([new Author('s_first', 's_last')], $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotResizedIfSubmittedWithExtraData()
|
public function testNotResizedIfSubmittedWithExtraData()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
));
|
]);
|
||||||
$form->setData(array('foo@bar.com'));
|
$form->setData(['foo@bar.com']);
|
||||||
$form->submit(array('foo@foo.com', 'bar@bar.com'));
|
$form->submit(['foo@foo.com', 'bar@bar.com']);
|
||||||
|
|
||||||
$this->assertTrue($form->has('0'));
|
$this->assertTrue($form->has('0'));
|
||||||
$this->assertFalse($form->has('1'));
|
$this->assertFalse($form->has('1'));
|
||||||
@ -224,27 +224,27 @@ class CollectionTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testResizedUpIfSubmittedWithExtraDataAndAllowAdd()
|
public function testResizedUpIfSubmittedWithExtraDataAndAllowAdd()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
));
|
]);
|
||||||
$form->setData(array('foo@bar.com'));
|
$form->setData(['foo@bar.com']);
|
||||||
$form->submit(array('foo@bar.com', 'bar@bar.com'));
|
$form->submit(['foo@bar.com', 'bar@bar.com']);
|
||||||
|
|
||||||
$this->assertTrue($form->has('0'));
|
$this->assertTrue($form->has('0'));
|
||||||
$this->assertTrue($form->has('1'));
|
$this->assertTrue($form->has('1'));
|
||||||
$this->assertEquals('foo@bar.com', $form[0]->getData());
|
$this->assertEquals('foo@bar.com', $form[0]->getData());
|
||||||
$this->assertEquals('bar@bar.com', $form[1]->getData());
|
$this->assertEquals('bar@bar.com', $form[1]->getData());
|
||||||
$this->assertEquals(array('foo@bar.com', 'bar@bar.com'), $form->getData());
|
$this->assertEquals(['foo@bar.com', 'bar@bar.com'], $form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAllowAddButNoPrototype()
|
public function testAllowAddButNoPrototype()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
'entry_type' => FormTypeTest::TESTED_TYPE,
|
'entry_type' => FormTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => false,
|
'prototype' => false,
|
||||||
));
|
]);
|
||||||
|
|
||||||
$this->assertFalse($form->has('__name__'));
|
$this->assertFalse($form->has('__name__'));
|
||||||
}
|
}
|
||||||
@ -252,11 +252,11 @@ class CollectionTypeTest extends BaseTypeTest
|
|||||||
public function testPrototypeMultipartPropagation()
|
public function testPrototypeMultipartPropagation()
|
||||||
{
|
{
|
||||||
$form = $this->factory
|
$form = $this->factory
|
||||||
->create(static::TESTED_TYPE, null, array(
|
->create(static::TESTED_TYPE, null, [
|
||||||
'entry_type' => FileTypeTest::TESTED_TYPE,
|
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
))
|
])
|
||||||
;
|
;
|
||||||
|
|
||||||
$this->assertTrue($form->createView()->vars['multipart']);
|
$this->assertTrue($form->createView()->vars['multipart']);
|
||||||
@ -264,11 +264,11 @@ class CollectionTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testGetDataDoesNotContainsPrototypeNameBeforeDataAreSet()
|
public function testGetDataDoesNotContainsPrototypeNameBeforeDataAreSet()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
$form = $this->factory->create(static::TESTED_TYPE, [], [
|
||||||
'entry_type' => FileTypeTest::TESTED_TYPE,
|
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
));
|
]);
|
||||||
|
|
||||||
$data = $form->getData();
|
$data = $form->getData();
|
||||||
$this->assertArrayNotHasKey('__name__', $data);
|
$this->assertArrayNotHasKey('__name__', $data);
|
||||||
@ -276,61 +276,61 @@ class CollectionTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testGetDataDoesNotContainsPrototypeNameAfterDataAreSet()
|
public function testGetDataDoesNotContainsPrototypeNameAfterDataAreSet()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
$form = $this->factory->create(static::TESTED_TYPE, [], [
|
||||||
'entry_type' => FileTypeTest::TESTED_TYPE,
|
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
));
|
]);
|
||||||
|
|
||||||
$form->setData(array('foobar.png'));
|
$form->setData(['foobar.png']);
|
||||||
$data = $form->getData();
|
$data = $form->getData();
|
||||||
$this->assertArrayNotHasKey('__name__', $data);
|
$this->assertArrayNotHasKey('__name__', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPrototypeNameOption()
|
public function testPrototypeNameOption()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
'entry_type' => FormTypeTest::TESTED_TYPE,
|
'entry_type' => FormTypeTest::TESTED_TYPE,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
));
|
]);
|
||||||
|
|
||||||
$this->assertSame('__name__', $form->getConfig()->getAttribute('prototype')->getName(), '__name__ is the default');
|
$this->assertSame('__name__', $form->getConfig()->getAttribute('prototype')->getName(), '__name__ is the default');
|
||||||
|
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, null, array(
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
'entry_type' => FormTypeTest::TESTED_TYPE,
|
'entry_type' => FormTypeTest::TESTED_TYPE,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype_name' => '__test__',
|
'prototype_name' => '__test__',
|
||||||
));
|
]);
|
||||||
|
|
||||||
$this->assertSame('__test__', $form->getConfig()->getAttribute('prototype')->getName());
|
$this->assertSame('__test__', $form->getConfig()->getAttribute('prototype')->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPrototypeDefaultLabel()
|
public function testPrototypeDefaultLabel()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
$form = $this->factory->create(static::TESTED_TYPE, [], [
|
||||||
'entry_type' => FileTypeTest::TESTED_TYPE,
|
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'prototype_name' => '__test__',
|
'prototype_name' => '__test__',
|
||||||
));
|
]);
|
||||||
|
|
||||||
$this->assertSame('__test__label__', $form->createView()->vars['prototype']->vars['label']);
|
$this->assertSame('__test__label__', $form->createView()->vars['prototype']->vars['label']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPrototypeData()
|
public function testPrototypeData()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
$form = $this->factory->create(static::TESTED_TYPE, [], [
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'prototype_data' => 'foo',
|
'prototype_data' => 'foo',
|
||||||
'entry_type' => TextTypeTest::TESTED_TYPE,
|
'entry_type' => TextTypeTest::TESTED_TYPE,
|
||||||
'entry_options' => array(
|
'entry_options' => [
|
||||||
'data' => 'bar',
|
'data' => 'bar',
|
||||||
'label' => false,
|
'label' => false,
|
||||||
),
|
],
|
||||||
));
|
]);
|
||||||
|
|
||||||
$this->assertSame('foo', $form->createView()->vars['prototype']->vars['value']);
|
$this->assertSame('foo', $form->createView()->vars['prototype']->vars['value']);
|
||||||
$this->assertFalse($form->createView()->vars['prototype']->vars['label']);
|
$this->assertFalse($form->createView()->vars['prototype']->vars['label']);
|
||||||
@ -338,25 +338,25 @@ class CollectionTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testPrototypeDefaultRequired()
|
public function testPrototypeDefaultRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
$form = $this->factory->create(static::TESTED_TYPE, [], [
|
||||||
'entry_type' => FileTypeTest::TESTED_TYPE,
|
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'prototype_name' => '__test__',
|
'prototype_name' => '__test__',
|
||||||
));
|
]);
|
||||||
|
|
||||||
$this->assertTrue($form->createView()->vars['prototype']->vars['required']);
|
$this->assertTrue($form->createView()->vars['prototype']->vars['required']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPrototypeSetNotRequired()
|
public function testPrototypeSetNotRequired()
|
||||||
{
|
{
|
||||||
$form = $this->factory->create(static::TESTED_TYPE, array(), array(
|
$form = $this->factory->create(static::TESTED_TYPE, [], [
|
||||||
'entry_type' => FileTypeTest::TESTED_TYPE,
|
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'prototype_name' => '__test__',
|
'prototype_name' => '__test__',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
));
|
]);
|
||||||
|
|
||||||
$this->assertFalse($form->createView()->vars['required'], 'collection is not required');
|
$this->assertFalse($form->createView()->vars['required'], 'collection is not required');
|
||||||
$this->assertFalse($form->createView()->vars['prototype']->vars['required'], '"prototype" should not be required');
|
$this->assertFalse($form->createView()->vars['prototype']->vars['required'], '"prototype" should not be required');
|
||||||
@ -364,16 +364,16 @@ class CollectionTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testPrototypeSetNotRequiredIfParentNotRequired()
|
public function testPrototypeSetNotRequiredIfParentNotRequired()
|
||||||
{
|
{
|
||||||
$child = $this->factory->create(static::TESTED_TYPE, array(), array(
|
$child = $this->factory->create(static::TESTED_TYPE, [], [
|
||||||
'entry_type' => FileTypeTest::TESTED_TYPE,
|
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'prototype_name' => '__test__',
|
'prototype_name' => '__test__',
|
||||||
));
|
]);
|
||||||
|
|
||||||
$parent = $this->factory->create(FormTypeTest::TESTED_TYPE, array(), array(
|
$parent = $this->factory->create(FormTypeTest::TESTED_TYPE, [], [
|
||||||
'required' => false,
|
'required' => false,
|
||||||
));
|
]);
|
||||||
|
|
||||||
$child->setParent($parent);
|
$child->setParent($parent);
|
||||||
$this->assertFalse($parent->createView()->vars['required'], 'Parent is not required');
|
$this->assertFalse($parent->createView()->vars['required'], 'Parent is not required');
|
||||||
@ -383,19 +383,19 @@ class CollectionTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testPrototypeNotOverrideRequiredByEntryOptionsInFavorOfParent()
|
public function testPrototypeNotOverrideRequiredByEntryOptionsInFavorOfParent()
|
||||||
{
|
{
|
||||||
$child = $this->factory->create(static::TESTED_TYPE, array(), array(
|
$child = $this->factory->create(static::TESTED_TYPE, [], [
|
||||||
'entry_type' => FileTypeTest::TESTED_TYPE,
|
'entry_type' => FileTypeTest::TESTED_TYPE,
|
||||||
'allow_add' => true,
|
'allow_add' => true,
|
||||||
'prototype' => true,
|
'prototype' => true,
|
||||||
'prototype_name' => '__test__',
|
'prototype_name' => '__test__',
|
||||||
'entry_options' => array(
|
'entry_options' => [
|
||||||
'required' => true,
|
'required' => true,
|
||||||
),
|
],
|
||||||
));
|
]);
|
||||||
|
|
||||||
$parent = $this->factory->create(FormTypeTest::TESTED_TYPE, array(), array(
|
$parent = $this->factory->create(FormTypeTest::TESTED_TYPE, [], [
|
||||||
'required' => false,
|
'required' => false,
|
||||||
));
|
]);
|
||||||
|
|
||||||
$child->setParent($parent);
|
$child->setParent($parent);
|
||||||
|
|
||||||
@ -406,10 +406,10 @@ class CollectionTypeTest extends BaseTypeTest
|
|||||||
|
|
||||||
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
public function testSubmitNull($expected = null, $norm = null, $view = null)
|
||||||
{
|
{
|
||||||
parent::testSubmitNull(array(), array(), array());
|
parent::testSubmitNull([], [], []);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitNullUsesDefaultEmptyData($emptyData = array(), $expectedData = array())
|
public function testSubmitNullUsesDefaultEmptyData($emptyData = [], $expectedData = [])
|
||||||
{
|
{
|
||||||
// resize form listener always set an empty array
|
// resize form listener always set an empty array
|
||||||
parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData);
|
parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData);
|
||||||
|
@ -643,12 +643,12 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
public function testPassBlockPrefixToViewWithParent()
|
public function testPassBlockPrefixToViewWithParent()
|
||||||
{
|
{
|
||||||
$view = $this->factory->createNamedBuilder('parent', static::TESTED_TYPE)
|
$view = $this->factory->createNamedBuilder('parent', static::TESTED_TYPE)
|
||||||
->add('child', $this->getTestedType(), array(
|
->add('child', $this->getTestedType(), [
|
||||||
'block_prefix' => 'child',
|
'block_prefix' => 'child',
|
||||||
))
|
])
|
||||||
->getForm()
|
->getForm()
|
||||||
->createView();
|
->createView();
|
||||||
|
|
||||||
$this->assertSame(array('form', 'child', '_parent_child'), $view['child']->vars['block_prefixes']);
|
$this->assertSame(['form', 'child', '_parent_child'], $view['child']->vars['block_prefixes']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
|||||||
} else {
|
} else {
|
||||||
$dumper = new CliDumper('php://output', $this->charset);
|
$dumper = new CliDumper('php://output', $this->charset);
|
||||||
if (method_exists($dumper, 'setDisplayOptions')) {
|
if (method_exists($dumper, 'setDisplayOptions')) {
|
||||||
$dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat));
|
$dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,7 +219,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
|||||||
} else {
|
} else {
|
||||||
$dumper = new CliDumper('php://output', $this->charset);
|
$dumper = new CliDumper('php://output', $this->charset);
|
||||||
if (method_exists($dumper, 'setDisplayOptions')) {
|
if (method_exists($dumper, 'setDisplayOptions')) {
|
||||||
$dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat));
|
$dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
|||||||
if ($this->logger instanceof DebugLoggerInterface) {
|
if ($this->logger instanceof DebugLoggerInterface) {
|
||||||
$this->logger->clear();
|
$this->logger->clear();
|
||||||
}
|
}
|
||||||
$this->data = array();
|
$this->data = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,7 +67,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
|||||||
$containerDeprecationLogs = $this->getContainerDeprecationLogs();
|
$containerDeprecationLogs = $this->getContainerDeprecationLogs();
|
||||||
$this->data = $this->computeErrorsCount($containerDeprecationLogs);
|
$this->data = $this->computeErrorsCount($containerDeprecationLogs);
|
||||||
// get compiler logs later (only when they are needed) to improve performance
|
// get compiler logs later (only when they are needed) to improve performance
|
||||||
$this->data['compiler_logs'] = array();
|
$this->data['compiler_logs'] = [];
|
||||||
$this->data['compiler_logs_filepath'] = $this->containerPathPrefix.'Compiler.log';
|
$this->data['compiler_logs_filepath'] = $this->containerPathPrefix.'Compiler.log';
|
||||||
$this->data['logs'] = $this->sanitizeLogs(array_merge($this->logger->getLogs($this->currentRequest), $containerDeprecationLogs));
|
$this->data['logs'] = $this->sanitizeLogs(array_merge($this->logger->getLogs($this->currentRequest), $containerDeprecationLogs));
|
||||||
$this->data = $this->cloneVar($this->data);
|
$this->data = $this->cloneVar($this->data);
|
||||||
@ -82,12 +82,12 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
|||||||
*/
|
*/
|
||||||
public function getLogs()
|
public function getLogs()
|
||||||
{
|
{
|
||||||
return isset($this->data['logs']) ? $this->data['logs'] : array();
|
return isset($this->data['logs']) ? $this->data['logs'] : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPriorities()
|
public function getPriorities()
|
||||||
{
|
{
|
||||||
return isset($this->data['priorities']) ? $this->data['priorities'] : array();
|
return isset($this->data['priorities']) ? $this->data['priorities'] : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function countErrors()
|
public function countErrors()
|
||||||
@ -126,13 +126,13 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
|||||||
private function getContainerDeprecationLogs()
|
private function getContainerDeprecationLogs()
|
||||||
{
|
{
|
||||||
if (null === $this->containerPathPrefix || !file_exists($file = $this->containerPathPrefix.'Deprecations.log')) {
|
if (null === $this->containerPathPrefix || !file_exists($file = $this->containerPathPrefix.'Deprecations.log')) {
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$bootTime = filemtime($file);
|
$bootTime = filemtime($file);
|
||||||
$logs = array();
|
$logs = [];
|
||||||
foreach (unserialize(file_get_contents($file)) as $log) {
|
foreach (unserialize(file_get_contents($file)) as $log) {
|
||||||
$log['context'] = array('exception' => new SilencedErrorContext($log['type'], $log['file'], $log['line'], $log['trace'], $log['count']));
|
$log['context'] = ['exception' => new SilencedErrorContext($log['type'], $log['file'], $log['line'], $log['trace'], $log['count'])];
|
||||||
$log['timestamp'] = $bootTime;
|
$log['timestamp'] = $bootTime;
|
||||||
$log['priority'] = 100;
|
$log['priority'] = 100;
|
||||||
$log['priorityName'] = 'DEBUG';
|
$log['priorityName'] = 'DEBUG';
|
||||||
@ -148,17 +148,17 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
|||||||
private function getContainerCompilerLogs(?string $compilerLogsFilepath = null): array
|
private function getContainerCompilerLogs(?string $compilerLogsFilepath = null): array
|
||||||
{
|
{
|
||||||
if (!file_exists($compilerLogsFilepath)) {
|
if (!file_exists($compilerLogsFilepath)) {
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$logs = array();
|
$logs = [];
|
||||||
foreach (file($compilerLogsFilepath, FILE_IGNORE_NEW_LINES) as $log) {
|
foreach (file($compilerLogsFilepath, FILE_IGNORE_NEW_LINES) as $log) {
|
||||||
$log = explode(': ', $log, 2);
|
$log = explode(': ', $log, 2);
|
||||||
if (!isset($log[1]) || !preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $log[0])) {
|
if (!isset($log[1]) || !preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $log[0])) {
|
||||||
$log = array('Unknown Compiler Pass', implode(': ', $log));
|
$log = ['Unknown Compiler Pass', implode(': ', $log)];
|
||||||
}
|
}
|
||||||
|
|
||||||
$logs[$log[0]][] = array('message' => $log[1]);
|
$logs[$log[0]][] = ['message' => $log[1]];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $logs;
|
return $logs;
|
||||||
@ -166,8 +166,8 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
|||||||
|
|
||||||
private function sanitizeLogs($logs)
|
private function sanitizeLogs($logs)
|
||||||
{
|
{
|
||||||
$sanitizedLogs = array();
|
$sanitizedLogs = [];
|
||||||
$silencedLogs = array();
|
$silencedLogs = [];
|
||||||
|
|
||||||
foreach ($logs as $log) {
|
foreach ($logs as $log) {
|
||||||
if (!$this->isSilencedOrDeprecationErrorLog($log)) {
|
if (!$this->isSilencedOrDeprecationErrorLog($log)) {
|
||||||
@ -186,10 +186,10 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
|||||||
$silencedLogs[$h] = true;
|
$silencedLogs[$h] = true;
|
||||||
|
|
||||||
if (!isset($sanitizedLogs[$message])) {
|
if (!isset($sanitizedLogs[$message])) {
|
||||||
$sanitizedLogs[$message] = $log + array(
|
$sanitizedLogs[$message] = $log + [
|
||||||
'errorCount' => 0,
|
'errorCount' => 0,
|
||||||
'scream' => true,
|
'scream' => true,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
$sanitizedLogs[$message]['errorCount'] += $exception->count;
|
$sanitizedLogs[$message]['errorCount'] += $exception->count;
|
||||||
|
|
||||||
@ -201,10 +201,10 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
|||||||
if (isset($sanitizedLogs[$errorId])) {
|
if (isset($sanitizedLogs[$errorId])) {
|
||||||
++$sanitizedLogs[$errorId]['errorCount'];
|
++$sanitizedLogs[$errorId]['errorCount'];
|
||||||
} else {
|
} else {
|
||||||
$log += array(
|
$log += [
|
||||||
'errorCount' => 1,
|
'errorCount' => 1,
|
||||||
'scream' => false,
|
'scream' => false,
|
||||||
);
|
];
|
||||||
|
|
||||||
$sanitizedLogs[$errorId] = $log;
|
$sanitizedLogs[$errorId] = $log;
|
||||||
}
|
}
|
||||||
@ -225,7 +225,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($exception instanceof \ErrorException && \in_array($exception->getSeverity(), array(E_DEPRECATED, E_USER_DEPRECATED), true)) {
|
if ($exception instanceof \ErrorException && \in_array($exception->getSeverity(), [E_DEPRECATED, E_USER_DEPRECATED], true)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,23 +234,23 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
|||||||
|
|
||||||
private function computeErrorsCount(array $containerDeprecationLogs)
|
private function computeErrorsCount(array $containerDeprecationLogs)
|
||||||
{
|
{
|
||||||
$silencedLogs = array();
|
$silencedLogs = [];
|
||||||
$count = array(
|
$count = [
|
||||||
'error_count' => $this->logger->countErrors($this->currentRequest),
|
'error_count' => $this->logger->countErrors($this->currentRequest),
|
||||||
'deprecation_count' => 0,
|
'deprecation_count' => 0,
|
||||||
'warning_count' => 0,
|
'warning_count' => 0,
|
||||||
'scream_count' => 0,
|
'scream_count' => 0,
|
||||||
'priorities' => array(),
|
'priorities' => [],
|
||||||
);
|
];
|
||||||
|
|
||||||
foreach ($this->logger->getLogs($this->currentRequest) as $log) {
|
foreach ($this->logger->getLogs($this->currentRequest) as $log) {
|
||||||
if (isset($count['priorities'][$log['priority']])) {
|
if (isset($count['priorities'][$log['priority']])) {
|
||||||
++$count['priorities'][$log['priority']]['count'];
|
++$count['priorities'][$log['priority']]['count'];
|
||||||
} else {
|
} else {
|
||||||
$count['priorities'][$log['priority']] = array(
|
$count['priorities'][$log['priority']] = [
|
||||||
'count' => 1,
|
'count' => 1,
|
||||||
'name' => $log['priorityName'],
|
'name' => $log['priorityName'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
if ('WARNING' === $log['priorityName']) {
|
if ('WARNING' === $log['priorityName']) {
|
||||||
++$count['warning_count'];
|
++$count['warning_count'];
|
||||||
|
@ -45,6 +45,6 @@ class AddRequestFormatsListener implements EventSubscriberInterface
|
|||||||
*/
|
*/
|
||||||
public static function getSubscribedEvents()
|
public static function getSubscribedEvents()
|
||||||
{
|
{
|
||||||
return array(KernelEvents::REQUEST => array('onKernelRequest', 100));
|
return [KernelEvents::REQUEST => ['onKernelRequest', 100]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,13 +79,13 @@ class LocaleListener implements EventSubscriberInterface
|
|||||||
|
|
||||||
public static function getSubscribedEvents()
|
public static function getSubscribedEvents()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
KernelEvents::REQUEST => array(
|
KernelEvents::REQUEST => [
|
||||||
array('setDefaultLocale', 100),
|
['setDefaultLocale', 100],
|
||||||
// must be registered after the Router to have access to the _locale
|
// must be registered after the Router to have access to the _locale
|
||||||
array('onKernelRequest', 16),
|
['onKernelRequest', 16],
|
||||||
),
|
],
|
||||||
KernelEvents::FINISH_REQUEST => array(array('onKernelFinishRequest', 0)),
|
KernelEvents::FINISH_REQUEST => [['onKernelFinishRequest', 0]],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ class AddRequestFormatsListenerTest extends TestCase
|
|||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->listener = new AddRequestFormatsListener(array('csv' => array('text/csv', 'text/plain')));
|
$this->listener = new AddRequestFormatsListener(['csv' => ['text/csv', 'text/plain']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
@ -46,7 +46,7 @@ class AddRequestFormatsListenerTest extends TestCase
|
|||||||
public function testRegisteredEvent()
|
public function testRegisteredEvent()
|
||||||
{
|
{
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(KernelEvents::REQUEST => array('onKernelRequest', 100)),
|
[KernelEvents::REQUEST => ['onKernelRequest', 100]],
|
||||||
AddRequestFormatsListener::getSubscribedEvents()
|
AddRequestFormatsListener::getSubscribedEvents()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ class AddRequestFormatsListenerTest extends TestCase
|
|||||||
|
|
||||||
$request->expects($this->once())
|
$request->expects($this->once())
|
||||||
->method('setFormat')
|
->method('setFormat')
|
||||||
->with('csv', array('text/csv', 'text/plain'));
|
->with('csv', ['text/csv', 'text/plain']);
|
||||||
|
|
||||||
$this->listener->onKernelRequest($event);
|
$this->listener->onKernelRequest($event);
|
||||||
}
|
}
|
||||||
|
@ -36,10 +36,10 @@ class LocaleListenerTest extends TestCase
|
|||||||
public function testRegisteredEvent()
|
public function testRegisteredEvent()
|
||||||
{
|
{
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
[
|
||||||
KernelEvents::REQUEST => array(array('setDefaultLocale', 100), array('onKernelRequest', 16)),
|
KernelEvents::REQUEST => [['setDefaultLocale', 100], ['onKernelRequest', 16]],
|
||||||
KernelEvents::FINISH_REQUEST => array(array('onKernelFinishRequest', 0)),
|
KernelEvents::FINISH_REQUEST => [['onKernelFinishRequest', 0]],
|
||||||
),
|
],
|
||||||
LocaleListener::getSubscribedEvents()
|
LocaleListener::getSubscribedEvents()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ class AdapterTest extends LdapTestCase
|
|||||||
$ldap = new Adapter($this->getLdapConfig());
|
$ldap = new Adapter($this->getLdapConfig());
|
||||||
|
|
||||||
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
|
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
|
||||||
$query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', array());
|
$query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', []);
|
||||||
$result = $query->execute();
|
$result = $query->execute();
|
||||||
|
|
||||||
$this->assertInstanceOf(Collection::class, $result);
|
$this->assertInstanceOf(Collection::class, $result);
|
||||||
@ -46,8 +46,8 @@ class AdapterTest extends LdapTestCase
|
|||||||
|
|
||||||
$entry = $result[0];
|
$entry = $result[0];
|
||||||
$this->assertInstanceOf(Entry::class, $entry);
|
$this->assertInstanceOf(Entry::class, $entry);
|
||||||
$this->assertEquals(array('Fabien Potencier'), $entry->getAttribute('cn'));
|
$this->assertEquals(['Fabien Potencier'], $entry->getAttribute('cn'));
|
||||||
$this->assertEquals(array('fabpot@symfony.com', 'fabien@potencier.com'), $entry->getAttribute('mail'));
|
$this->assertEquals(['fabpot@symfony.com', 'fabien@potencier.com'], $entry->getAttribute('mail'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,14 +58,14 @@ class AdapterTest extends LdapTestCase
|
|||||||
$ldap = new Adapter($this->getLdapConfig());
|
$ldap = new Adapter($this->getLdapConfig());
|
||||||
|
|
||||||
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
|
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
|
||||||
$query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', array());
|
$query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', []);
|
||||||
$result = $query->execute();
|
$result = $query->execute();
|
||||||
$iterator = $result->getIterator();
|
$iterator = $result->getIterator();
|
||||||
$iterator->rewind();
|
$iterator->rewind();
|
||||||
$entry = $iterator->current();
|
$entry = $iterator->current();
|
||||||
$this->assertInstanceOf(Entry::class, $entry);
|
$this->assertInstanceOf(Entry::class, $entry);
|
||||||
$this->assertEquals(array('Fabien Potencier'), $entry->getAttribute('cn'));
|
$this->assertEquals(['Fabien Potencier'], $entry->getAttribute('cn'));
|
||||||
$this->assertEquals(array('fabpot@symfony.com', 'fabien@potencier.com'), $entry->getAttribute('mail'));
|
$this->assertEquals(['fabpot@symfony.com', 'fabien@potencier.com'], $entry->getAttribute('mail'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,7 +75,7 @@ class AdapterTest extends LdapTestCase
|
|||||||
{
|
{
|
||||||
$ldap = new Adapter($this->getLdapConfig());
|
$ldap = new Adapter($this->getLdapConfig());
|
||||||
$this->expectException(NotBoundException::class);
|
$this->expectException(NotBoundException::class);
|
||||||
$query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', array());
|
$query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', []);
|
||||||
$query->execute();
|
$query->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,14 +85,14 @@ class AdapterTest extends LdapTestCase
|
|||||||
|
|
||||||
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
|
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
|
||||||
|
|
||||||
$query = $ldap->createQuery('cn=Fabien Potencier,dc=symfony,dc=com', '(objectclass=*)', array(
|
$query = $ldap->createQuery('cn=Fabien Potencier,dc=symfony,dc=com', '(objectclass=*)', [
|
||||||
'scope' => Query::SCOPE_BASE,
|
'scope' => Query::SCOPE_BASE,
|
||||||
));
|
]);
|
||||||
$result = $query->execute();
|
$result = $query->execute();
|
||||||
|
|
||||||
$entry = $result[0];
|
$entry = $result[0];
|
||||||
$this->assertEquals($result->count(), 1);
|
$this->assertEquals($result->count(), 1);
|
||||||
$this->assertEquals(array('Fabien Potencier'), $entry->getAttribute('cn'));
|
$this->assertEquals(['Fabien Potencier'], $entry->getAttribute('cn'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLdapQueryScopeOneLevel()
|
public function testLdapQueryScopeOneLevel()
|
||||||
@ -101,14 +101,14 @@ class AdapterTest extends LdapTestCase
|
|||||||
|
|
||||||
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
|
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
|
||||||
|
|
||||||
$one_level_result = $ldap->createQuery('ou=Components,dc=symfony,dc=com', '(objectclass=*)', array(
|
$one_level_result = $ldap->createQuery('ou=Components,dc=symfony,dc=com', '(objectclass=*)', [
|
||||||
'scope' => Query::SCOPE_ONE,
|
'scope' => Query::SCOPE_ONE,
|
||||||
))->execute();
|
])->execute();
|
||||||
|
|
||||||
$subtree_count = $ldap->createQuery('ou=Components,dc=symfony,dc=com', '(objectclass=*)')->execute()->count();
|
$subtree_count = $ldap->createQuery('ou=Components,dc=symfony,dc=com', '(objectclass=*)')->execute()->count();
|
||||||
|
|
||||||
$this->assertNotEquals($one_level_result->count(), $subtree_count);
|
$this->assertNotEquals($one_level_result->count(), $subtree_count);
|
||||||
$this->assertEquals($one_level_result->count(), 1);
|
$this->assertEquals($one_level_result->count(), 1);
|
||||||
$this->assertEquals($one_level_result[0]->getAttribute('ou'), array('Ldap'));
|
$this->assertEquals($one_level_result[0]->getAttribute('ou'), ['Ldap']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
|
|||||||
* "?" and "#" (would be interpreted wrongly as query and fragment identifier),
|
* "?" and "#" (would be interpreted wrongly as query and fragment identifier),
|
||||||
* "'" and """ (are used as delimiters in HTML).
|
* "'" and """ (are used as delimiters in HTML).
|
||||||
*/
|
*/
|
||||||
protected $decodedChars = array(
|
protected $decodedChars = [
|
||||||
// the slash can be used to designate a hierarchical structure and we want allow using it with this meaning
|
// the slash can be used to designate a hierarchical structure and we want allow using it with this meaning
|
||||||
// some webservers don't allow the slash in encoded form in the path for security reasons anyway
|
// some webservers don't allow the slash in encoded form in the path for security reasons anyway
|
||||||
// see http://stackoverflow.com/questions/4069002/http-400-if-2f-part-of-get-url-in-jboss
|
// see http://stackoverflow.com/questions/4069002/http-400-if-2f-part-of-get-url-in-jboss
|
||||||
@ -65,7 +65,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
|
|||||||
'%21' => '!',
|
'%21' => '!',
|
||||||
'%2A' => '*',
|
'%2A' => '*',
|
||||||
'%7C' => '|',
|
'%7C' => '|',
|
||||||
);
|
];
|
||||||
|
|
||||||
public function __construct(RouteCollection $routes, RequestContext $context, LoggerInterface $logger = null, string $defaultLocale = null)
|
public function __construct(RouteCollection $routes, RequestContext $context, LoggerInterface $logger = null, string $defaultLocale = null)
|
||||||
{
|
{
|
||||||
@ -110,7 +110,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
|
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
|
||||||
{
|
{
|
||||||
$route = null;
|
$route = null;
|
||||||
$locale = $parameters['_locale']
|
$locale = $parameters['_locale']
|
||||||
@ -141,7 +141,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
|
|||||||
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
|
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
|
||||||
* it does not match the requirement
|
* it does not match the requirement
|
||||||
*/
|
*/
|
||||||
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = array())
|
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = [])
|
||||||
{
|
{
|
||||||
$variables = array_flip($variables);
|
$variables = array_flip($variables);
|
||||||
$mergedParams = array_replace($defaults, $this->context->getParameters(), $parameters);
|
$mergedParams = array_replace($defaults, $this->context->getParameters(), $parameters);
|
||||||
@ -165,11 +165,11 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
|
|||||||
// check requirement
|
// check requirement
|
||||||
if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#'.(empty($token[4]) ? '' : 'u'), $mergedParams[$varName])) {
|
if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#'.(empty($token[4]) ? '' : 'u'), $mergedParams[$varName])) {
|
||||||
if ($this->strictRequirements) {
|
if ($this->strictRequirements) {
|
||||||
throw new InvalidParameterException(strtr($message, array('{parameter}' => $varName, '{route}' => $name, '{expected}' => $token[2], '{given}' => $mergedParams[$varName])));
|
throw new InvalidParameterException(strtr($message, ['{parameter}' => $varName, '{route}' => $name, '{expected}' => $token[2], '{given}' => $mergedParams[$varName]]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->logger) {
|
if ($this->logger) {
|
||||||
$this->logger->error($message, array('parameter' => $varName, 'route' => $name, 'expected' => $token[2], 'given' => $mergedParams[$varName]));
|
$this->logger->error($message, ['parameter' => $varName, 'route' => $name, 'expected' => $token[2], 'given' => $mergedParams[$varName]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -195,7 +195,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
|
|||||||
// the path segments "." and ".." are interpreted as relative reference when resolving a URI; see http://tools.ietf.org/html/rfc3986#section-3.3
|
// the path segments "." and ".." are interpreted as relative reference when resolving a URI; see http://tools.ietf.org/html/rfc3986#section-3.3
|
||||||
// so we need to encode them as they are not used for this purpose here
|
// so we need to encode them as they are not used for this purpose here
|
||||||
// otherwise we would generate a URI that, when followed by a user agent (e.g. browser), does not match this route
|
// otherwise we would generate a URI that, when followed by a user agent (e.g. browser), does not match this route
|
||||||
$url = strtr($url, array('/../' => '/%2E%2E/', '/./' => '/%2E/'));
|
$url = strtr($url, ['/../' => '/%2E%2E/', '/./' => '/%2E/']);
|
||||||
if ('/..' === substr($url, -3)) {
|
if ('/..' === substr($url, -3)) {
|
||||||
$url = substr($url, 0, -2).'%2E%2E';
|
$url = substr($url, 0, -2).'%2E%2E';
|
||||||
} elseif ('/.' === substr($url, -2)) {
|
} elseif ('/.' === substr($url, -2)) {
|
||||||
@ -219,11 +219,11 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
|
|||||||
if ('variable' === $token[0]) {
|
if ('variable' === $token[0]) {
|
||||||
if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#i'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]])) {
|
if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#i'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]])) {
|
||||||
if ($this->strictRequirements) {
|
if ($this->strictRequirements) {
|
||||||
throw new InvalidParameterException(strtr($message, array('{parameter}' => $token[3], '{route}' => $name, '{expected}' => $token[2], '{given}' => $mergedParams[$token[3]])));
|
throw new InvalidParameterException(strtr($message, ['{parameter}' => $token[3], '{route}' => $name, '{expected}' => $token[2], '{given}' => $mergedParams[$token[3]]]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->logger) {
|
if ($this->logger) {
|
||||||
$this->logger->error($message, array('parameter' => $token[3], 'route' => $name, 'expected' => $token[2], 'given' => $mergedParams[$token[3]]));
|
$this->logger->error($message, ['parameter' => $token[3], 'route' => $name, 'expected' => $token[2], 'given' => $mergedParams[$token[3]]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -277,11 +277,11 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
|
|||||||
if ($extra && $query = http_build_query($extra, '', '&', PHP_QUERY_RFC3986)) {
|
if ($extra && $query = http_build_query($extra, '', '&', PHP_QUERY_RFC3986)) {
|
||||||
// "/" and "?" can be left decoded for better user experience, see
|
// "/" and "?" can be left decoded for better user experience, see
|
||||||
// http://tools.ietf.org/html/rfc3986#section-3.4
|
// http://tools.ietf.org/html/rfc3986#section-3.4
|
||||||
$url .= '?'.strtr($query, array('%2F' => '/'));
|
$url .= '?'.strtr($query, ['%2F' => '/']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('' !== $fragment) {
|
if ('' !== $fragment) {
|
||||||
$url .= '#'.strtr(rawurlencode($fragment), array('%2F' => '/', '%3F' => '?'));
|
$url .= '#'.strtr(rawurlencode($fragment), ['%2F' => '/', '%3F' => '?']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
|
@ -46,10 +46,10 @@ class RouteCompiler implements RouteCompilerInterface
|
|||||||
*/
|
*/
|
||||||
public static function compile(Route $route)
|
public static function compile(Route $route)
|
||||||
{
|
{
|
||||||
$hostVariables = array();
|
$hostVariables = [];
|
||||||
$variables = array();
|
$variables = [];
|
||||||
$hostRegex = null;
|
$hostRegex = null;
|
||||||
$hostTokens = array();
|
$hostTokens = [];
|
||||||
|
|
||||||
if ('' !== $host = $route->getHost()) {
|
if ('' !== $host = $route->getHost()) {
|
||||||
$result = self::compilePattern($route, $host, true);
|
$result = self::compilePattern($route, $host, true);
|
||||||
@ -94,9 +94,9 @@ class RouteCompiler implements RouteCompilerInterface
|
|||||||
|
|
||||||
private static function compilePattern(Route $route, $pattern, $isHost)
|
private static function compilePattern(Route $route, $pattern, $isHost)
|
||||||
{
|
{
|
||||||
$tokens = array();
|
$tokens = [];
|
||||||
$variables = array();
|
$variables = [];
|
||||||
$matches = array();
|
$matches = [];
|
||||||
$pos = 0;
|
$pos = 0;
|
||||||
$defaultSeparator = $isHost ? '.' : '/';
|
$defaultSeparator = $isHost ? '.' : '/';
|
||||||
$useUtf8 = preg_match('//u', $pattern);
|
$useUtf8 = preg_match('//u', $pattern);
|
||||||
@ -142,9 +142,9 @@ class RouteCompiler implements RouteCompilerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($isSeparator && $precedingText !== $precedingChar) {
|
if ($isSeparator && $precedingText !== $precedingChar) {
|
||||||
$tokens[] = array('text', substr($precedingText, 0, -\strlen($precedingChar)));
|
$tokens[] = ['text', substr($precedingText, 0, -\strlen($precedingChar))];
|
||||||
} elseif (!$isSeparator && \strlen($precedingText) > 0) {
|
} elseif (!$isSeparator && \strlen($precedingText) > 0) {
|
||||||
$tokens[] = array('text', $precedingText);
|
$tokens[] = ['text', $precedingText];
|
||||||
}
|
}
|
||||||
|
|
||||||
$regexp = $route->getRequirement($varName);
|
$regexp = $route->getRequirement($varName);
|
||||||
@ -183,7 +183,7 @@ class RouteCompiler implements RouteCompilerInterface
|
|||||||
$regexp = self::transformCapturingGroupsToNonCapturings($regexp);
|
$regexp = self::transformCapturingGroupsToNonCapturings($regexp);
|
||||||
}
|
}
|
||||||
|
|
||||||
$tokens[] = array('variable', $isSeparator ? $precedingChar : '', $regexp, $varName);
|
$tokens[] = ['variable', $isSeparator ? $precedingChar : '', $regexp, $varName];
|
||||||
if ('!' === $varName[0]) {
|
if ('!' === $varName[0]) {
|
||||||
$varName = substr($varName, 1);
|
$varName = substr($varName, 1);
|
||||||
}
|
}
|
||||||
@ -191,7 +191,7 @@ class RouteCompiler implements RouteCompilerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($pos < \strlen($pattern)) {
|
if ($pos < \strlen($pattern)) {
|
||||||
$tokens[] = array('text', substr($pattern, $pos));
|
$tokens[] = ['text', substr($pattern, $pos)];
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the first optional token
|
// find the first optional token
|
||||||
@ -224,12 +224,12 @@ class RouteCompiler implements RouteCompilerInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return [
|
||||||
'staticPrefix' => self::determineStaticPrefix($route, $tokens),
|
'staticPrefix' => self::determineStaticPrefix($route, $tokens),
|
||||||
'regex' => $regexp,
|
'regex' => $regexp,
|
||||||
'tokens' => array_reverse($tokens),
|
'tokens' => array_reverse($tokens),
|
||||||
'variables' => $variables,
|
'variables' => $variables,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,7 +23,7 @@ class UrlGeneratorTest extends TestCase
|
|||||||
public function testAbsoluteUrlWithPort80()
|
public function testAbsoluteUrlWithPort80()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||||
$url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
|
$url = $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||||
|
|
||||||
$this->assertEquals('http://localhost/app.php/testing', $url);
|
$this->assertEquals('http://localhost/app.php/testing', $url);
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ class UrlGeneratorTest extends TestCase
|
|||||||
public function testAbsoluteSecureUrlWithPort443()
|
public function testAbsoluteSecureUrlWithPort443()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||||
$url = $this->getGenerator($routes, array('scheme' => 'https'))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
|
$url = $this->getGenerator($routes, ['scheme' => 'https'])->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||||
|
|
||||||
$this->assertEquals('https://localhost/app.php/testing', $url);
|
$this->assertEquals('https://localhost/app.php/testing', $url);
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ class UrlGeneratorTest extends TestCase
|
|||||||
public function testAbsoluteUrlWithNonStandardPort()
|
public function testAbsoluteUrlWithNonStandardPort()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||||
$url = $this->getGenerator($routes, array('httpPort' => 8080))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
|
$url = $this->getGenerator($routes, ['httpPort' => 8080])->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||||
|
|
||||||
$this->assertEquals('http://localhost:8080/app.php/testing', $url);
|
$this->assertEquals('http://localhost:8080/app.php/testing', $url);
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ class UrlGeneratorTest extends TestCase
|
|||||||
public function testAbsoluteSecureUrlWithNonStandardPort()
|
public function testAbsoluteSecureUrlWithNonStandardPort()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||||
$url = $this->getGenerator($routes, array('httpsPort' => 8080, 'scheme' => 'https'))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
|
$url = $this->getGenerator($routes, ['httpsPort' => 8080, 'scheme' => 'https'])->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||||
|
|
||||||
$this->assertEquals('https://localhost:8080/app.php/testing', $url);
|
$this->assertEquals('https://localhost:8080/app.php/testing', $url);
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ class UrlGeneratorTest extends TestCase
|
|||||||
public function testRelativeUrlWithoutParameters()
|
public function testRelativeUrlWithoutParameters()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||||
$url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
|
$url = $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_PATH);
|
||||||
|
|
||||||
$this->assertEquals('/app.php/testing', $url);
|
$this->assertEquals('/app.php/testing', $url);
|
||||||
}
|
}
|
||||||
@ -63,15 +63,15 @@ class UrlGeneratorTest extends TestCase
|
|||||||
public function testRelativeUrlWithParameter()
|
public function testRelativeUrlWithParameter()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}'));
|
$routes = $this->getRoutes('test', new Route('/testing/{foo}'));
|
||||||
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH);
|
$url = $this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_PATH);
|
||||||
|
|
||||||
$this->assertEquals('/app.php/testing/bar', $url);
|
$this->assertEquals('/app.php/testing/bar', $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRelativeUrlWithNullParameter()
|
public function testRelativeUrlWithNullParameter()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing.{format}', array('format' => null)));
|
$routes = $this->getRoutes('test', new Route('/testing.{format}', ['format' => null]));
|
||||||
$url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
|
$url = $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_PATH);
|
||||||
|
|
||||||
$this->assertEquals('/app.php/testing', $url);
|
$this->assertEquals('/app.php/testing', $url);
|
||||||
}
|
}
|
||||||
@ -81,31 +81,31 @@ class UrlGeneratorTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testRelativeUrlWithNullParameterButNotOptional()
|
public function testRelativeUrlWithNullParameterButNotOptional()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', array('foo' => null)));
|
$routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', ['foo' => null]));
|
||||||
// This must raise an exception because the default requirement for "foo" is "[^/]+" which is not met with these params.
|
// This must raise an exception because the default requirement for "foo" is "[^/]+" which is not met with these params.
|
||||||
// Generating path "/testing//bar" would be wrong as matching this route would fail.
|
// Generating path "/testing//bar" would be wrong as matching this route would fail.
|
||||||
$this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
|
$this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRelativeUrlWithOptionalZeroParameter()
|
public function testRelativeUrlWithOptionalZeroParameter()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing/{page}'));
|
$routes = $this->getRoutes('test', new Route('/testing/{page}'));
|
||||||
$url = $this->getGenerator($routes)->generate('test', array('page' => 0), UrlGeneratorInterface::ABSOLUTE_PATH);
|
$url = $this->getGenerator($routes)->generate('test', ['page' => 0], UrlGeneratorInterface::ABSOLUTE_PATH);
|
||||||
|
|
||||||
$this->assertEquals('/app.php/testing/0', $url);
|
$this->assertEquals('/app.php/testing/0', $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotPassedOptionalParameterInBetween()
|
public function testNotPassedOptionalParameterInBetween()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/{slug}/{page}', array('slug' => 'index', 'page' => 0)));
|
$routes = $this->getRoutes('test', new Route('/{slug}/{page}', ['slug' => 'index', 'page' => 0]));
|
||||||
$this->assertSame('/app.php/index/1', $this->getGenerator($routes)->generate('test', array('page' => 1)));
|
$this->assertSame('/app.php/index/1', $this->getGenerator($routes)->generate('test', ['page' => 1]));
|
||||||
$this->assertSame('/app.php/', $this->getGenerator($routes)->generate('test'));
|
$this->assertSame('/app.php/', $this->getGenerator($routes)->generate('test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRelativeUrlWithExtraParameters()
|
public function testRelativeUrlWithExtraParameters()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||||
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH);
|
$url = $this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_PATH);
|
||||||
|
|
||||||
$this->assertEquals('/app.php/testing?foo=bar', $url);
|
$this->assertEquals('/app.php/testing?foo=bar', $url);
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ class UrlGeneratorTest extends TestCase
|
|||||||
public function testAbsoluteUrlWithExtraParameters()
|
public function testAbsoluteUrlWithExtraParameters()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||||
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
|
$url = $this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||||
|
|
||||||
$this->assertEquals('http://localhost/app.php/testing?foo=bar', $url);
|
$this->assertEquals('http://localhost/app.php/testing?foo=bar', $url);
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ class UrlGeneratorTest extends TestCase
|
|||||||
public function testUrlWithNullExtraParameters()
|
public function testUrlWithNullExtraParameters()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||||
$url = $this->getGenerator($routes)->generate('test', array('foo' => null), UrlGeneratorInterface::ABSOLUTE_URL);
|
$url = $this->getGenerator($routes)->generate('test', ['foo' => null], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||||
|
|
||||||
$this->assertEquals('http://localhost/app.php/testing', $url);
|
$this->assertEquals('http://localhost/app.php/testing', $url);
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ class UrlGeneratorTest extends TestCase
|
|||||||
$context = new RequestContext('/app.php');
|
$context = new RequestContext('/app.php');
|
||||||
$context->setParameter('bar', 'bar');
|
$context->setParameter('bar', 'bar');
|
||||||
$generator->setContext($context);
|
$generator->setContext($context);
|
||||||
$url = $generator->generate('test', array('foo' => 'bar'));
|
$url = $generator->generate('test', ['foo' => 'bar']);
|
||||||
|
|
||||||
$this->assertEquals('/app.php/testing?foo=bar', $url);
|
$this->assertEquals('/app.php/testing?foo=bar', $url);
|
||||||
}
|
}
|
||||||
@ -145,19 +145,19 @@ class UrlGeneratorTest extends TestCase
|
|||||||
$context = new RequestContext('/app.php');
|
$context = new RequestContext('/app.php');
|
||||||
$context->setParameter('foo', 'bar');
|
$context->setParameter('foo', 'bar');
|
||||||
$generator->setContext($context);
|
$generator->setContext($context);
|
||||||
$url = $generator->generate('test', array());
|
$url = $generator->generate('test', []);
|
||||||
|
|
||||||
$this->assertEquals('/app.php/testing/bar', $url);
|
$this->assertEquals('/app.php/testing/bar', $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGlobalParameterHasHigherPriorityThanDefault()
|
public function testGlobalParameterHasHigherPriorityThanDefault()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/{_locale}', array('_locale' => 'en')));
|
$routes = $this->getRoutes('test', new Route('/{_locale}', ['_locale' => 'en']));
|
||||||
$generator = $this->getGenerator($routes);
|
$generator = $this->getGenerator($routes);
|
||||||
$context = new RequestContext('/app.php');
|
$context = new RequestContext('/app.php');
|
||||||
$context->setParameter('_locale', 'de');
|
$context->setParameter('_locale', 'de');
|
||||||
$generator->setContext($context);
|
$generator->setContext($context);
|
||||||
$url = $generator->generate('test', array());
|
$url = $generator->generate('test', []);
|
||||||
|
|
||||||
$this->assertSame('/app.php/de', $url);
|
$this->assertSame('/app.php/de', $url);
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ class UrlGeneratorTest extends TestCase
|
|||||||
public function testGenerateWithoutRoutes()
|
public function testGenerateWithoutRoutes()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('foo', new Route('/testing/{foo}'));
|
$routes = $this->getRoutes('foo', new Route('/testing/{foo}'));
|
||||||
$this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
|
$this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -177,7 +177,7 @@ class UrlGeneratorTest extends TestCase
|
|||||||
public function testGenerateForRouteWithoutMandatoryParameter()
|
public function testGenerateForRouteWithoutMandatoryParameter()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}'));
|
$routes = $this->getRoutes('test', new Route('/testing/{foo}'));
|
||||||
$this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
|
$this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -185,8 +185,8 @@ class UrlGeneratorTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testGenerateForRouteWithInvalidOptionalParameter()
|
public function testGenerateForRouteWithInvalidOptionalParameter()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')));
|
$routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));
|
||||||
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
|
$this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -194,35 +194,35 @@ class UrlGeneratorTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testGenerateForRouteWithInvalidParameter()
|
public function testGenerateForRouteWithInvalidParameter()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => '1|2')));
|
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => '1|2']));
|
||||||
$this->getGenerator($routes)->generate('test', array('foo' => '0'), UrlGeneratorInterface::ABSOLUTE_URL);
|
$this->getGenerator($routes)->generate('test', ['foo' => '0'], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGenerateForRouteWithInvalidOptionalParameterNonStrict()
|
public function testGenerateForRouteWithInvalidOptionalParameterNonStrict()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')));
|
$routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));
|
||||||
$generator = $this->getGenerator($routes);
|
$generator = $this->getGenerator($routes);
|
||||||
$generator->setStrictRequirements(false);
|
$generator->setStrictRequirements(false);
|
||||||
$this->assertNull($generator->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL));
|
$this->assertNull($generator->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLogger()
|
public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLogger()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')));
|
$routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));
|
||||||
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
|
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
|
||||||
$logger->expects($this->once())
|
$logger->expects($this->once())
|
||||||
->method('error');
|
->method('error');
|
||||||
$generator = $this->getGenerator($routes, array(), $logger);
|
$generator = $this->getGenerator($routes, [], $logger);
|
||||||
$generator->setStrictRequirements(false);
|
$generator->setStrictRequirements(false);
|
||||||
$this->assertNull($generator->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL));
|
$this->assertNull($generator->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsCheck()
|
public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsCheck()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')));
|
$routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));
|
||||||
$generator = $this->getGenerator($routes);
|
$generator = $this->getGenerator($routes);
|
||||||
$generator->setStrictRequirements(null);
|
$generator->setStrictRequirements(null);
|
||||||
$this->assertSame('/app.php/testing/bar', $generator->generate('test', array('foo' => 'bar')));
|
$this->assertSame('/app.php/testing/bar', $generator->generate('test', ['foo' => 'bar']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -230,8 +230,8 @@ class UrlGeneratorTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testGenerateForRouteWithInvalidMandatoryParameter()
|
public function testGenerateForRouteWithInvalidMandatoryParameter()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => 'd+')));
|
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => 'd+']));
|
||||||
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
|
$this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -239,8 +239,8 @@ class UrlGeneratorTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testGenerateForRouteWithInvalidUtf8Parameter()
|
public function testGenerateForRouteWithInvalidUtf8Parameter()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => '\pL+'), array('utf8' => true)));
|
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => '\pL+'], ['utf8' => true]));
|
||||||
$this->getGenerator($routes)->generate('test', array('foo' => 'abc123'), UrlGeneratorInterface::ABSOLUTE_URL);
|
$this->getGenerator($routes)->generate('test', ['foo' => 'abc123'], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -248,31 +248,31 @@ class UrlGeneratorTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testRequiredParamAndEmptyPassed()
|
public function testRequiredParamAndEmptyPassed()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/{slug}', array(), array('slug' => '.+')));
|
$routes = $this->getRoutes('test', new Route('/{slug}', [], ['slug' => '.+']));
|
||||||
$this->getGenerator($routes)->generate('test', array('slug' => ''));
|
$this->getGenerator($routes)->generate('test', ['slug' => '']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSchemeRequirementDoesNothingIfSameCurrentScheme()
|
public function testSchemeRequirementDoesNothingIfSameCurrentScheme()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('http')));
|
$routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['http']));
|
||||||
$this->assertEquals('/app.php/', $this->getGenerator($routes)->generate('test'));
|
$this->assertEquals('/app.php/', $this->getGenerator($routes)->generate('test'));
|
||||||
|
|
||||||
$routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('https')));
|
$routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['https']));
|
||||||
$this->assertEquals('/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test'));
|
$this->assertEquals('/app.php/', $this->getGenerator($routes, ['scheme' => 'https'])->generate('test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSchemeRequirementForcesAbsoluteUrl()
|
public function testSchemeRequirementForcesAbsoluteUrl()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('https')));
|
$routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['https']));
|
||||||
$this->assertEquals('https://localhost/app.php/', $this->getGenerator($routes)->generate('test'));
|
$this->assertEquals('https://localhost/app.php/', $this->getGenerator($routes)->generate('test'));
|
||||||
|
|
||||||
$routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('http')));
|
$routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['http']));
|
||||||
$this->assertEquals('http://localhost/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test'));
|
$this->assertEquals('http://localhost/app.php/', $this->getGenerator($routes, ['scheme' => 'https'])->generate('test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSchemeRequirementCreatesUrlForFirstRequiredScheme()
|
public function testSchemeRequirementCreatesUrlForFirstRequiredScheme()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('Ftp', 'https')));
|
$routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['Ftp', 'https']));
|
||||||
$this->assertEquals('ftp://localhost/app.php/', $this->getGenerator($routes)->generate('test'));
|
$this->assertEquals('ftp://localhost/app.php/', $this->getGenerator($routes)->generate('test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,48 +281,48 @@ class UrlGeneratorTest extends TestCase
|
|||||||
$routes = $this->getRoutes('test', new Route('//path-and-not-domain'));
|
$routes = $this->getRoutes('test', new Route('//path-and-not-domain'));
|
||||||
|
|
||||||
// this must not generate '//path-and-not-domain' because that would be a network path
|
// this must not generate '//path-and-not-domain' because that would be a network path
|
||||||
$this->assertSame('/path-and-not-domain', $this->getGenerator($routes, array('BaseUrl' => ''))->generate('test'));
|
$this->assertSame('/path-and-not-domain', $this->getGenerator($routes, ['BaseUrl' => ''])->generate('test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNoTrailingSlashForMultipleOptionalParameters()
|
public function testNoTrailingSlashForMultipleOptionalParameters()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/category/{slug1}/{slug2}/{slug3}', array('slug2' => null, 'slug3' => null)));
|
$routes = $this->getRoutes('test', new Route('/category/{slug1}/{slug2}/{slug3}', ['slug2' => null, 'slug3' => null]));
|
||||||
|
|
||||||
$this->assertEquals('/app.php/category/foo', $this->getGenerator($routes)->generate('test', array('slug1' => 'foo')));
|
$this->assertEquals('/app.php/category/foo', $this->getGenerator($routes)->generate('test', ['slug1' => 'foo']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithAnIntegerAsADefaultValue()
|
public function testWithAnIntegerAsADefaultValue()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/{default}', array('default' => 0)));
|
$routes = $this->getRoutes('test', new Route('/{default}', ['default' => 0]));
|
||||||
|
|
||||||
$this->assertEquals('/app.php/foo', $this->getGenerator($routes)->generate('test', array('default' => 'foo')));
|
$this->assertEquals('/app.php/foo', $this->getGenerator($routes)->generate('test', ['default' => 'foo']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNullForOptionalParameterIsIgnored()
|
public function testNullForOptionalParameterIsIgnored()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/test/{default}', array('default' => 0)));
|
$routes = $this->getRoutes('test', new Route('/test/{default}', ['default' => 0]));
|
||||||
|
|
||||||
$this->assertEquals('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => null)));
|
$this->assertEquals('/app.php/test', $this->getGenerator($routes)->generate('test', ['default' => null]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testQueryParamSameAsDefault()
|
public function testQueryParamSameAsDefault()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/test', array('page' => 1)));
|
$routes = $this->getRoutes('test', new Route('/test', ['page' => 1]));
|
||||||
|
|
||||||
$this->assertSame('/app.php/test?page=2', $this->getGenerator($routes)->generate('test', array('page' => 2)));
|
$this->assertSame('/app.php/test?page=2', $this->getGenerator($routes)->generate('test', ['page' => 2]));
|
||||||
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('page' => 1)));
|
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', ['page' => 1]));
|
||||||
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('page' => '1')));
|
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', ['page' => '1']));
|
||||||
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
|
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testArrayQueryParamSameAsDefault()
|
public function testArrayQueryParamSameAsDefault()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/test', array('array' => array('foo', 'bar'))));
|
$routes = $this->getRoutes('test', new Route('/test', ['array' => ['foo', 'bar']]));
|
||||||
|
|
||||||
$this->assertSame('/app.php/test?array%5B0%5D=bar&array%5B1%5D=foo', $this->getGenerator($routes)->generate('test', array('array' => array('bar', 'foo'))));
|
$this->assertSame('/app.php/test?array%5B0%5D=bar&array%5B1%5D=foo', $this->getGenerator($routes)->generate('test', ['array' => ['bar', 'foo']]));
|
||||||
$this->assertSame('/app.php/test?array%5Ba%5D=foo&array%5Bb%5D=bar', $this->getGenerator($routes)->generate('test', array('array' => array('a' => 'foo', 'b' => 'bar'))));
|
$this->assertSame('/app.php/test?array%5Ba%5D=foo&array%5Bb%5D=bar', $this->getGenerator($routes)->generate('test', ['array' => ['a' => 'foo', 'b' => 'bar']]));
|
||||||
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('array' => array('foo', 'bar'))));
|
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', ['array' => ['foo', 'bar']]));
|
||||||
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('array' => array(1 => 'bar', 0 => 'foo'))));
|
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', ['array' => [1 => 'bar', 0 => 'foo']]));
|
||||||
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
|
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,11 +342,11 @@ class UrlGeneratorTest extends TestCase
|
|||||||
// This tests the encoding of reserved characters that are used for delimiting of URI components (defined in RFC 3986)
|
// This tests the encoding of reserved characters that are used for delimiting of URI components (defined in RFC 3986)
|
||||||
// and other special ASCII chars. These chars are tested as static text path, variable path and query param.
|
// and other special ASCII chars. These chars are tested as static text path, variable path and query param.
|
||||||
$chars = '@:[]/()*\'" +,;-._~&$<>|{}%\\^`!?foo=bar#id';
|
$chars = '@:[]/()*\'" +,;-._~&$<>|{}%\\^`!?foo=bar#id';
|
||||||
$routes = $this->getRoutes('test', new Route("/$chars/{varpath}", array(), array('varpath' => '.+')));
|
$routes = $this->getRoutes('test', new Route("/$chars/{varpath}", [], ['varpath' => '.+']));
|
||||||
$this->assertSame($expectedPath, $this->getGenerator($routes)->generate('test', array(
|
$this->assertSame($expectedPath, $this->getGenerator($routes)->generate('test', [
|
||||||
'varpath' => $chars,
|
'varpath' => $chars,
|
||||||
'query' => $chars,
|
'query' => $chars,
|
||||||
)));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEncodingOfRelativePathSegments()
|
public function testEncodingOfRelativePathSegments()
|
||||||
@ -361,24 +361,24 @@ class UrlGeneratorTest extends TestCase
|
|||||||
|
|
||||||
public function testAdjacentVariables()
|
public function testAdjacentVariables()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/{x}{y}{z}.{_format}', array('z' => 'default-z', '_format' => 'html'), array('y' => '\d+')));
|
$routes = $this->getRoutes('test', new Route('/{x}{y}{z}.{_format}', ['z' => 'default-z', '_format' => 'html'], ['y' => '\d+']));
|
||||||
$generator = $this->getGenerator($routes);
|
$generator = $this->getGenerator($routes);
|
||||||
$this->assertSame('/app.php/foo123', $generator->generate('test', array('x' => 'foo', 'y' => '123')));
|
$this->assertSame('/app.php/foo123', $generator->generate('test', ['x' => 'foo', 'y' => '123']));
|
||||||
$this->assertSame('/app.php/foo123bar.xml', $generator->generate('test', array('x' => 'foo', 'y' => '123', 'z' => 'bar', '_format' => 'xml')));
|
$this->assertSame('/app.php/foo123bar.xml', $generator->generate('test', ['x' => 'foo', 'y' => '123', 'z' => 'bar', '_format' => 'xml']));
|
||||||
|
|
||||||
// The default requirement for 'x' should not allow the separator '.' in this case because it would otherwise match everything
|
// The default requirement for 'x' should not allow the separator '.' in this case because it would otherwise match everything
|
||||||
// and following optional variables like _format could never match.
|
// and following optional variables like _format could never match.
|
||||||
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
|
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
|
||||||
$generator->generate('test', array('x' => 'do.t', 'y' => '123', 'z' => 'bar', '_format' => 'xml'));
|
$generator->generate('test', ['x' => 'do.t', 'y' => '123', 'z' => 'bar', '_format' => 'xml']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOptionalVariableWithNoRealSeparator()
|
public function testOptionalVariableWithNoRealSeparator()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/get{what}', array('what' => 'All')));
|
$routes = $this->getRoutes('test', new Route('/get{what}', ['what' => 'All']));
|
||||||
$generator = $this->getGenerator($routes);
|
$generator = $this->getGenerator($routes);
|
||||||
|
|
||||||
$this->assertSame('/app.php/get', $generator->generate('test'));
|
$this->assertSame('/app.php/get', $generator->generate('test'));
|
||||||
$this->assertSame('/app.php/getSites', $generator->generate('test', array('what' => 'Sites')));
|
$this->assertSame('/app.php/getSites', $generator->generate('test', ['what' => 'Sites']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRequiredVariableWithNoRealSeparator()
|
public function testRequiredVariableWithNoRealSeparator()
|
||||||
@ -386,7 +386,7 @@ class UrlGeneratorTest extends TestCase
|
|||||||
$routes = $this->getRoutes('test', new Route('/get{what}Suffix'));
|
$routes = $this->getRoutes('test', new Route('/get{what}Suffix'));
|
||||||
$generator = $this->getGenerator($routes);
|
$generator = $this->getGenerator($routes);
|
||||||
|
|
||||||
$this->assertSame('/app.php/getSitesSuffix', $generator->generate('test', array('what' => 'Sites')));
|
$this->assertSame('/app.php/getSitesSuffix', $generator->generate('test', ['what' => 'Sites']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefaultRequirementOfVariable()
|
public function testDefaultRequirementOfVariable()
|
||||||
@ -394,17 +394,17 @@ class UrlGeneratorTest extends TestCase
|
|||||||
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
|
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
|
||||||
$generator = $this->getGenerator($routes);
|
$generator = $this->getGenerator($routes);
|
||||||
|
|
||||||
$this->assertSame('/app.php/index.mobile.html', $generator->generate('test', array('page' => 'index', '_format' => 'mobile.html')));
|
$this->assertSame('/app.php/index.mobile.html', $generator->generate('test', ['page' => 'index', '_format' => 'mobile.html']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testImportantVariable()
|
public function testImportantVariable()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', (new Route('/{page}.{!_format}'))->addDefaults(array('_format' => 'mobile.html')));
|
$routes = $this->getRoutes('test', (new Route('/{page}.{!_format}'))->addDefaults(['_format' => 'mobile.html']));
|
||||||
$generator = $this->getGenerator($routes);
|
$generator = $this->getGenerator($routes);
|
||||||
|
|
||||||
$this->assertSame('/app.php/index.xml', $generator->generate('test', array('page' => 'index', '_format' => 'xml')));
|
$this->assertSame('/app.php/index.xml', $generator->generate('test', ['page' => 'index', '_format' => 'xml']));
|
||||||
$this->assertSame('/app.php/index.mobile.html', $generator->generate('test', array('page' => 'index', '_format' => 'mobile.html')));
|
$this->assertSame('/app.php/index.mobile.html', $generator->generate('test', ['page' => 'index', '_format' => 'mobile.html']));
|
||||||
$this->assertSame('/app.php/index.mobile.html', $generator->generate('test', array('page' => 'index')));
|
$this->assertSame('/app.php/index.mobile.html', $generator->generate('test', ['page' => 'index']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -415,7 +415,7 @@ class UrlGeneratorTest extends TestCase
|
|||||||
$routes = $this->getRoutes('test', new Route('/{page}.{!_format}'));
|
$routes = $this->getRoutes('test', new Route('/{page}.{!_format}'));
|
||||||
$generator = $this->getGenerator($routes);
|
$generator = $this->getGenerator($routes);
|
||||||
|
|
||||||
$generator->generate('test', array('page' => 'index'));
|
$generator->generate('test', ['page' => 'index']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -424,7 +424,7 @@ class UrlGeneratorTest extends TestCase
|
|||||||
public function testDefaultRequirementOfVariableDisallowsSlash()
|
public function testDefaultRequirementOfVariableDisallowsSlash()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
|
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
|
||||||
$this->getGenerator($routes)->generate('test', array('page' => 'index', '_format' => 'sl/ash'));
|
$this->getGenerator($routes)->generate('test', ['page' => 'index', '_format' => 'sl/ash']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -433,28 +433,28 @@ class UrlGeneratorTest extends TestCase
|
|||||||
public function testDefaultRequirementOfVariableDisallowsNextSeparator()
|
public function testDefaultRequirementOfVariableDisallowsNextSeparator()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
|
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
|
||||||
$this->getGenerator($routes)->generate('test', array('page' => 'do.t', '_format' => 'html'));
|
$this->getGenerator($routes)->generate('test', ['page' => 'do.t', '_format' => 'html']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithHostDifferentFromContext()
|
public function testWithHostDifferentFromContext()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com'));
|
$routes = $this->getRoutes('test', new Route('/{name}', [], [], [], '{locale}.example.com'));
|
||||||
|
|
||||||
$this->assertEquals('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test', array('name' => 'Fabien', 'locale' => 'fr')));
|
$this->assertEquals('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test', ['name' => 'Fabien', 'locale' => 'fr']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithHostSameAsContext()
|
public function testWithHostSameAsContext()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com'));
|
$routes = $this->getRoutes('test', new Route('/{name}', [], [], [], '{locale}.example.com'));
|
||||||
|
|
||||||
$this->assertEquals('/app.php/Fabien', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', array('name' => 'Fabien', 'locale' => 'fr')));
|
$this->assertEquals('/app.php/Fabien', $this->getGenerator($routes, ['host' => 'fr.example.com'])->generate('test', ['name' => 'Fabien', 'locale' => 'fr']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithHostSameAsContextAndAbsolute()
|
public function testWithHostSameAsContextAndAbsolute()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com'));
|
$routes = $this->getRoutes('test', new Route('/{name}', [], [], [], '{locale}.example.com'));
|
||||||
|
|
||||||
$this->assertEquals('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', array('name' => 'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::ABSOLUTE_URL));
|
$this->assertEquals('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, ['host' => 'fr.example.com'])->generate('test', ['name' => 'Fabien', 'locale' => 'fr'], UrlGeneratorInterface::ABSOLUTE_URL));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -462,8 +462,8 @@ class UrlGeneratorTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUrlWithInvalidParameterInHost()
|
public function testUrlWithInvalidParameterInHost()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/', array(), array('foo' => 'bar'), array(), '{foo}.example.com'));
|
$routes = $this->getRoutes('test', new Route('/', [], ['foo' => 'bar'], [], '{foo}.example.com'));
|
||||||
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH);
|
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -471,8 +471,8 @@ class UrlGeneratorTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUrlWithInvalidParameterInHostWhenParamHasADefaultValue()
|
public function testUrlWithInvalidParameterInHostWhenParamHasADefaultValue()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/', array('foo' => 'bar'), array('foo' => 'bar'), array(), '{foo}.example.com'));
|
$routes = $this->getRoutes('test', new Route('/', ['foo' => 'bar'], ['foo' => 'bar'], [], '{foo}.example.com'));
|
||||||
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH);
|
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -480,72 +480,72 @@ class UrlGeneratorTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUrlWithInvalidParameterEqualsDefaultValueInHost()
|
public function testUrlWithInvalidParameterEqualsDefaultValueInHost()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/', array('foo' => 'baz'), array('foo' => 'bar'), array(), '{foo}.example.com'));
|
$routes = $this->getRoutes('test', new Route('/', ['foo' => 'baz'], ['foo' => 'bar'], [], '{foo}.example.com'));
|
||||||
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH);
|
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUrlWithInvalidParameterInHostInNonStrictMode()
|
public function testUrlWithInvalidParameterInHostInNonStrictMode()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/', array(), array('foo' => 'bar'), array(), '{foo}.example.com'));
|
$routes = $this->getRoutes('test', new Route('/', [], ['foo' => 'bar'], [], '{foo}.example.com'));
|
||||||
$generator = $this->getGenerator($routes);
|
$generator = $this->getGenerator($routes);
|
||||||
$generator->setStrictRequirements(false);
|
$generator->setStrictRequirements(false);
|
||||||
$this->assertNull($generator->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH));
|
$this->assertNull($generator->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHostIsCaseInsensitive()
|
public function testHostIsCaseInsensitive()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/', array(), array('locale' => 'en|de|fr'), array(), '{locale}.FooBar.com'));
|
$routes = $this->getRoutes('test', new Route('/', [], ['locale' => 'en|de|fr'], [], '{locale}.FooBar.com'));
|
||||||
$generator = $this->getGenerator($routes);
|
$generator = $this->getGenerator($routes);
|
||||||
$this->assertSame('//EN.FooBar.com/app.php/', $generator->generate('test', array('locale' => 'EN'), UrlGeneratorInterface::NETWORK_PATH));
|
$this->assertSame('//EN.FooBar.com/app.php/', $generator->generate('test', ['locale' => 'EN'], UrlGeneratorInterface::NETWORK_PATH));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefaultHostIsUsedWhenContextHostIsEmpty()
|
public function testDefaultHostIsUsedWhenContextHostIsEmpty()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/route', array('domain' => 'my.fallback.host'), array('domain' => '.+'), array(), '{domain}', array('http')));
|
$routes = $this->getRoutes('test', new Route('/route', ['domain' => 'my.fallback.host'], ['domain' => '.+'], [], '{domain}', ['http']));
|
||||||
|
|
||||||
$generator = $this->getGenerator($routes);
|
$generator = $this->getGenerator($routes);
|
||||||
$generator->getContext()->setHost('');
|
$generator->getContext()->setHost('');
|
||||||
|
|
||||||
$this->assertSame('http://my.fallback.host/app.php/route', $generator->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL));
|
$this->assertSame('http://my.fallback.host/app.php/route', $generator->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefaultHostIsUsedWhenContextHostIsEmptyAndSchemeIsNot()
|
public function testDefaultHostIsUsedWhenContextHostIsEmptyAndSchemeIsNot()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/route', array('domain' => 'my.fallback.host'), array('domain' => '.+'), array(), '{domain}', array('http', 'https')));
|
$routes = $this->getRoutes('test', new Route('/route', ['domain' => 'my.fallback.host'], ['domain' => '.+'], [], '{domain}', ['http', 'https']));
|
||||||
|
|
||||||
$generator = $this->getGenerator($routes);
|
$generator = $this->getGenerator($routes);
|
||||||
$generator->getContext()->setHost('');
|
$generator->getContext()->setHost('');
|
||||||
$generator->getContext()->setScheme('https');
|
$generator->getContext()->setScheme('https');
|
||||||
|
|
||||||
$this->assertSame('https://my.fallback.host/app.php/route', $generator->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL));
|
$this->assertSame('https://my.fallback.host/app.php/route', $generator->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAbsoluteUrlFallbackToRelativeIfHostIsEmptyAndSchemeIsNot()
|
public function testAbsoluteUrlFallbackToRelativeIfHostIsEmptyAndSchemeIsNot()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/route', array(), array(), array(), '', array('http', 'https')));
|
$routes = $this->getRoutes('test', new Route('/route', [], [], [], '', ['http', 'https']));
|
||||||
|
|
||||||
$generator = $this->getGenerator($routes);
|
$generator = $this->getGenerator($routes);
|
||||||
$generator->getContext()->setHost('');
|
$generator->getContext()->setHost('');
|
||||||
$generator->getContext()->setScheme('https');
|
$generator->getContext()->setScheme('https');
|
||||||
|
|
||||||
$this->assertSame('/app.php/route', $generator->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL));
|
$this->assertSame('/app.php/route', $generator->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGenerateNetworkPath()
|
public function testGenerateNetworkPath()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com', array('http')));
|
$routes = $this->getRoutes('test', new Route('/{name}', [], [], [], '{locale}.example.com', ['http']));
|
||||||
|
|
||||||
$this->assertSame('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test',
|
$this->assertSame('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test',
|
||||||
array('name' => 'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::NETWORK_PATH), 'network path with different host'
|
['name' => 'Fabien', 'locale' => 'fr'], UrlGeneratorInterface::NETWORK_PATH), 'network path with different host'
|
||||||
);
|
);
|
||||||
$this->assertSame('//fr.example.com/app.php/Fabien?query=string', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test',
|
$this->assertSame('//fr.example.com/app.php/Fabien?query=string', $this->getGenerator($routes, ['host' => 'fr.example.com'])->generate('test',
|
||||||
array('name' => 'Fabien', 'locale' => 'fr', 'query' => 'string'), UrlGeneratorInterface::NETWORK_PATH), 'network path although host same as context'
|
['name' => 'Fabien', 'locale' => 'fr', 'query' => 'string'], UrlGeneratorInterface::NETWORK_PATH), 'network path although host same as context'
|
||||||
);
|
);
|
||||||
$this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test',
|
$this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, ['scheme' => 'https'])->generate('test',
|
||||||
array('name' => 'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::NETWORK_PATH), 'absolute URL because scheme requirement does not match context'
|
['name' => 'Fabien', 'locale' => 'fr'], UrlGeneratorInterface::NETWORK_PATH), 'absolute URL because scheme requirement does not match context'
|
||||||
);
|
);
|
||||||
$this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test',
|
$this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test',
|
||||||
array('name' => 'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::ABSOLUTE_URL), 'absolute URL with same scheme because it is requested'
|
['name' => 'Fabien', 'locale' => 'fr'], UrlGeneratorInterface::ABSOLUTE_URL), 'absolute URL with same scheme because it is requested'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -554,32 +554,32 @@ class UrlGeneratorTest extends TestCase
|
|||||||
$routes = new RouteCollection();
|
$routes = new RouteCollection();
|
||||||
$routes->add('article', new Route('/{author}/{article}/'));
|
$routes->add('article', new Route('/{author}/{article}/'));
|
||||||
$routes->add('comments', new Route('/{author}/{article}/comments'));
|
$routes->add('comments', new Route('/{author}/{article}/comments'));
|
||||||
$routes->add('host', new Route('/{article}', array(), array(), array(), '{author}.example.com'));
|
$routes->add('host', new Route('/{article}', [], [], [], '{author}.example.com'));
|
||||||
$routes->add('scheme', new Route('/{author}/blog', array(), array(), array(), '', array('https')));
|
$routes->add('scheme', new Route('/{author}/blog', [], [], [], '', ['https']));
|
||||||
$routes->add('unrelated', new Route('/about'));
|
$routes->add('unrelated', new Route('/about'));
|
||||||
|
|
||||||
$generator = $this->getGenerator($routes, array('host' => 'example.com', 'pathInfo' => '/fabien/symfony-is-great/'));
|
$generator = $this->getGenerator($routes, ['host' => 'example.com', 'pathInfo' => '/fabien/symfony-is-great/']);
|
||||||
|
|
||||||
$this->assertSame('comments', $generator->generate('comments',
|
$this->assertSame('comments', $generator->generate('comments',
|
||||||
array('author' => 'fabien', 'article' => 'symfony-is-great'), UrlGeneratorInterface::RELATIVE_PATH)
|
['author' => 'fabien', 'article' => 'symfony-is-great'], UrlGeneratorInterface::RELATIVE_PATH)
|
||||||
);
|
);
|
||||||
$this->assertSame('comments?page=2', $generator->generate('comments',
|
$this->assertSame('comments?page=2', $generator->generate('comments',
|
||||||
array('author' => 'fabien', 'article' => 'symfony-is-great', 'page' => 2), UrlGeneratorInterface::RELATIVE_PATH)
|
['author' => 'fabien', 'article' => 'symfony-is-great', 'page' => 2], UrlGeneratorInterface::RELATIVE_PATH)
|
||||||
);
|
);
|
||||||
$this->assertSame('../twig-is-great/', $generator->generate('article',
|
$this->assertSame('../twig-is-great/', $generator->generate('article',
|
||||||
array('author' => 'fabien', 'article' => 'twig-is-great'), UrlGeneratorInterface::RELATIVE_PATH)
|
['author' => 'fabien', 'article' => 'twig-is-great'], UrlGeneratorInterface::RELATIVE_PATH)
|
||||||
);
|
);
|
||||||
$this->assertSame('../../bernhard/forms-are-great/', $generator->generate('article',
|
$this->assertSame('../../bernhard/forms-are-great/', $generator->generate('article',
|
||||||
array('author' => 'bernhard', 'article' => 'forms-are-great'), UrlGeneratorInterface::RELATIVE_PATH)
|
['author' => 'bernhard', 'article' => 'forms-are-great'], UrlGeneratorInterface::RELATIVE_PATH)
|
||||||
);
|
);
|
||||||
$this->assertSame('//bernhard.example.com/app.php/forms-are-great', $generator->generate('host',
|
$this->assertSame('//bernhard.example.com/app.php/forms-are-great', $generator->generate('host',
|
||||||
array('author' => 'bernhard', 'article' => 'forms-are-great'), UrlGeneratorInterface::RELATIVE_PATH)
|
['author' => 'bernhard', 'article' => 'forms-are-great'], UrlGeneratorInterface::RELATIVE_PATH)
|
||||||
);
|
);
|
||||||
$this->assertSame('https://example.com/app.php/bernhard/blog', $generator->generate('scheme',
|
$this->assertSame('https://example.com/app.php/bernhard/blog', $generator->generate('scheme',
|
||||||
array('author' => 'bernhard'), UrlGeneratorInterface::RELATIVE_PATH)
|
['author' => 'bernhard'], UrlGeneratorInterface::RELATIVE_PATH)
|
||||||
);
|
);
|
||||||
$this->assertSame('../../about', $generator->generate('unrelated',
|
$this->assertSame('../../about', $generator->generate('unrelated',
|
||||||
array(), UrlGeneratorInterface::RELATIVE_PATH)
|
[], UrlGeneratorInterface::RELATIVE_PATH)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,138 +593,138 @@ class UrlGeneratorTest extends TestCase
|
|||||||
|
|
||||||
public function provideRelativePaths()
|
public function provideRelativePaths()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array(
|
[
|
||||||
'/same/dir/',
|
'/same/dir/',
|
||||||
'/same/dir/',
|
'/same/dir/',
|
||||||
'',
|
'',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'/same/file',
|
'/same/file',
|
||||||
'/same/file',
|
'/same/file',
|
||||||
'',
|
'',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'/',
|
'/',
|
||||||
'/file',
|
'/file',
|
||||||
'file',
|
'file',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'/',
|
'/',
|
||||||
'/dir/file',
|
'/dir/file',
|
||||||
'dir/file',
|
'dir/file',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'/dir/file.html',
|
'/dir/file.html',
|
||||||
'/dir/different-file.html',
|
'/dir/different-file.html',
|
||||||
'different-file.html',
|
'different-file.html',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'/same/dir/extra-file',
|
'/same/dir/extra-file',
|
||||||
'/same/dir/',
|
'/same/dir/',
|
||||||
'./',
|
'./',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'/parent/dir/',
|
'/parent/dir/',
|
||||||
'/parent/',
|
'/parent/',
|
||||||
'../',
|
'../',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'/parent/dir/extra-file',
|
'/parent/dir/extra-file',
|
||||||
'/parent/',
|
'/parent/',
|
||||||
'../',
|
'../',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'/a/b/',
|
'/a/b/',
|
||||||
'/x/y/z/',
|
'/x/y/z/',
|
||||||
'../../x/y/z/',
|
'../../x/y/z/',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'/a/b/c/d/e',
|
'/a/b/c/d/e',
|
||||||
'/a/c/d',
|
'/a/c/d',
|
||||||
'../../../c/d',
|
'../../../c/d',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'/a/b/c//',
|
'/a/b/c//',
|
||||||
'/a/b/c/',
|
'/a/b/c/',
|
||||||
'../',
|
'../',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'/a/b/c/',
|
'/a/b/c/',
|
||||||
'/a/b/c//',
|
'/a/b/c//',
|
||||||
'.//',
|
'.//',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'/root/a/b/c/',
|
'/root/a/b/c/',
|
||||||
'/root/x/b/c/',
|
'/root/x/b/c/',
|
||||||
'../../../x/b/c/',
|
'../../../x/b/c/',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'/a/b/c/d/',
|
'/a/b/c/d/',
|
||||||
'/a',
|
'/a',
|
||||||
'../../../../a',
|
'../../../../a',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'/special-chars/sp%20ce/1€/mäh/e=mc²',
|
'/special-chars/sp%20ce/1€/mäh/e=mc²',
|
||||||
'/special-chars/sp%20ce/1€/<µ>/e=mc²',
|
'/special-chars/sp%20ce/1€/<µ>/e=mc²',
|
||||||
'../<µ>/e=mc²',
|
'../<µ>/e=mc²',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'not-rooted',
|
'not-rooted',
|
||||||
'dir/file',
|
'dir/file',
|
||||||
'dir/file',
|
'dir/file',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'//dir/',
|
'//dir/',
|
||||||
'',
|
'',
|
||||||
'../../',
|
'../../',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'/dir/',
|
'/dir/',
|
||||||
'/dir/file:with-colon',
|
'/dir/file:with-colon',
|
||||||
'./file:with-colon',
|
'./file:with-colon',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'/dir/',
|
'/dir/',
|
||||||
'/dir/subdir/file:with-colon',
|
'/dir/subdir/file:with-colon',
|
||||||
'subdir/file:with-colon',
|
'subdir/file:with-colon',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'/dir/',
|
'/dir/',
|
||||||
'/dir/:subdir/',
|
'/dir/:subdir/',
|
||||||
'./:subdir/',
|
'./:subdir/',
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFragmentsCanBeAppendedToUrls()
|
public function testFragmentsCanBeAppendedToUrls()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||||
|
|
||||||
$url = $this->getGenerator($routes)->generate('test', array('_fragment' => 'frag ment'), UrlGeneratorInterface::ABSOLUTE_PATH);
|
$url = $this->getGenerator($routes)->generate('test', ['_fragment' => 'frag ment'], UrlGeneratorInterface::ABSOLUTE_PATH);
|
||||||
$this->assertEquals('/app.php/testing#frag%20ment', $url);
|
$this->assertEquals('/app.php/testing#frag%20ment', $url);
|
||||||
|
|
||||||
$url = $this->getGenerator($routes)->generate('test', array('_fragment' => '0'), UrlGeneratorInterface::ABSOLUTE_PATH);
|
$url = $this->getGenerator($routes)->generate('test', ['_fragment' => '0'], UrlGeneratorInterface::ABSOLUTE_PATH);
|
||||||
$this->assertEquals('/app.php/testing#0', $url);
|
$this->assertEquals('/app.php/testing#0', $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFragmentsDoNotEscapeValidCharacters()
|
public function testFragmentsDoNotEscapeValidCharacters()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||||
$url = $this->getGenerator($routes)->generate('test', array('_fragment' => '?/'), UrlGeneratorInterface::ABSOLUTE_PATH);
|
$url = $this->getGenerator($routes)->generate('test', ['_fragment' => '?/'], UrlGeneratorInterface::ABSOLUTE_PATH);
|
||||||
|
|
||||||
$this->assertEquals('/app.php/testing#?/', $url);
|
$this->assertEquals('/app.php/testing#?/', $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFragmentsCanBeDefinedAsDefaults()
|
public function testFragmentsCanBeDefinedAsDefaults()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing', array('_fragment' => 'fragment')));
|
$routes = $this->getRoutes('test', new Route('/testing', ['_fragment' => 'fragment']));
|
||||||
$url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
|
$url = $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_PATH);
|
||||||
|
|
||||||
$this->assertEquals('/app.php/testing#fragment', $url);
|
$this->assertEquals('/app.php/testing#fragment', $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getGenerator(RouteCollection $routes, array $parameters = array(), $logger = null)
|
protected function getGenerator(RouteCollection $routes, array $parameters = [], $logger = null)
|
||||||
{
|
{
|
||||||
$context = new RequestContext('/app.php');
|
$context = new RequestContext('/app.php');
|
||||||
foreach ($parameters as $key => $value) {
|
foreach ($parameters as $key => $value) {
|
||||||
|
@ -33,7 +33,7 @@ class UrlMatcherTest extends TestCase
|
|||||||
public function testMethodNotAllowed()
|
public function testMethodNotAllowed()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array(), array('post')));
|
$coll->add('foo', new Route('/foo', [], [], [], '', [], ['post']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
|
|
||||||
@ -41,14 +41,14 @@ class UrlMatcherTest extends TestCase
|
|||||||
$matcher->match('/foo');
|
$matcher->match('/foo');
|
||||||
$this->fail();
|
$this->fail();
|
||||||
} catch (MethodNotAllowedException $e) {
|
} catch (MethodNotAllowedException $e) {
|
||||||
$this->assertEquals(array('POST'), $e->getAllowedMethods());
|
$this->assertEquals(['POST'], $e->getAllowedMethods());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMethodNotAllowedOnRoot()
|
public function testMethodNotAllowedOnRoot()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('foo', new Route('/', array(), array(), array(), '', array(), array('GET')));
|
$coll->add('foo', new Route('/', [], [], [], '', [], ['GET']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'POST'));
|
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'POST'));
|
||||||
|
|
||||||
@ -56,14 +56,14 @@ class UrlMatcherTest extends TestCase
|
|||||||
$matcher->match('/');
|
$matcher->match('/');
|
||||||
$this->fail();
|
$this->fail();
|
||||||
} catch (MethodNotAllowedException $e) {
|
} catch (MethodNotAllowedException $e) {
|
||||||
$this->assertEquals(array('GET'), $e->getAllowedMethods());
|
$this->assertEquals(['GET'], $e->getAllowedMethods());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHeadAllowedWhenRequirementContainsGet()
|
public function testHeadAllowedWhenRequirementContainsGet()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array(), array('get')));
|
$coll->add('foo', new Route('/foo', [], [], [], '', [], ['get']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'head'));
|
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'head'));
|
||||||
$this->assertInternalType('array', $matcher->match('/foo'));
|
$this->assertInternalType('array', $matcher->match('/foo'));
|
||||||
@ -72,8 +72,8 @@ class UrlMatcherTest extends TestCase
|
|||||||
public function testMethodNotAllowedAggregatesAllowedMethods()
|
public function testMethodNotAllowedAggregatesAllowedMethods()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('foo1', new Route('/foo', array(), array(), array(), '', array(), array('post')));
|
$coll->add('foo1', new Route('/foo', [], [], [], '', [], ['post']));
|
||||||
$coll->add('foo2', new Route('/foo', array(), array(), array(), '', array(), array('put', 'delete')));
|
$coll->add('foo2', new Route('/foo', [], [], [], '', [], ['put', 'delete']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ class UrlMatcherTest extends TestCase
|
|||||||
$matcher->match('/foo');
|
$matcher->match('/foo');
|
||||||
$this->fail();
|
$this->fail();
|
||||||
} catch (MethodNotAllowedException $e) {
|
} catch (MethodNotAllowedException $e) {
|
||||||
$this->assertEquals(array('POST', 'PUT', 'DELETE'), $e->getAllowedMethods());
|
$this->assertEquals(['POST', 'PUT', 'DELETE'], $e->getAllowedMethods());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,17 +96,17 @@ class UrlMatcherTest extends TestCase
|
|||||||
$this->fail();
|
$this->fail();
|
||||||
} catch (ResourceNotFoundException $e) {
|
} catch (ResourceNotFoundException $e) {
|
||||||
}
|
}
|
||||||
$this->assertEquals(array('_route' => 'foo', 'bar' => 'baz'), $matcher->match('/foo/baz'));
|
$this->assertEquals(['_route' => 'foo', 'bar' => 'baz'], $matcher->match('/foo/baz'));
|
||||||
|
|
||||||
// test that defaults are merged
|
// test that defaults are merged
|
||||||
$collection = new RouteCollection();
|
$collection = new RouteCollection();
|
||||||
$collection->add('foo', new Route('/foo/{bar}', array('def' => 'test')));
|
$collection->add('foo', new Route('/foo/{bar}', ['def' => 'test']));
|
||||||
$matcher = $this->getUrlMatcher($collection);
|
$matcher = $this->getUrlMatcher($collection);
|
||||||
$this->assertEquals(array('_route' => 'foo', 'bar' => 'baz', 'def' => 'test'), $matcher->match('/foo/baz'));
|
$this->assertEquals(['_route' => 'foo', 'bar' => 'baz', 'def' => 'test'], $matcher->match('/foo/baz'));
|
||||||
|
|
||||||
// test that route "method" is ignored if no method is given in the context
|
// test that route "method" is ignored if no method is given in the context
|
||||||
$collection = new RouteCollection();
|
$collection = new RouteCollection();
|
||||||
$collection->add('foo', new Route('/foo', array(), array(), array(), '', array(), array('get', 'head')));
|
$collection->add('foo', new Route('/foo', [], [], [], '', [], ['get', 'head']));
|
||||||
$matcher = $this->getUrlMatcher($collection);
|
$matcher = $this->getUrlMatcher($collection);
|
||||||
$this->assertInternalType('array', $matcher->match('/foo'));
|
$this->assertInternalType('array', $matcher->match('/foo'));
|
||||||
|
|
||||||
@ -126,24 +126,24 @@ class UrlMatcherTest extends TestCase
|
|||||||
|
|
||||||
// route with an optional variable as the first segment
|
// route with an optional variable as the first segment
|
||||||
$collection = new RouteCollection();
|
$collection = new RouteCollection();
|
||||||
$collection->add('bar', new Route('/{bar}/foo', array('bar' => 'bar'), array('bar' => 'foo|bar')));
|
$collection->add('bar', new Route('/{bar}/foo', ['bar' => 'bar'], ['bar' => 'foo|bar']));
|
||||||
$matcher = $this->getUrlMatcher($collection);
|
$matcher = $this->getUrlMatcher($collection);
|
||||||
$this->assertEquals(array('_route' => 'bar', 'bar' => 'bar'), $matcher->match('/bar/foo'));
|
$this->assertEquals(['_route' => 'bar', 'bar' => 'bar'], $matcher->match('/bar/foo'));
|
||||||
$this->assertEquals(array('_route' => 'bar', 'bar' => 'foo'), $matcher->match('/foo/foo'));
|
$this->assertEquals(['_route' => 'bar', 'bar' => 'foo'], $matcher->match('/foo/foo'));
|
||||||
|
|
||||||
$collection = new RouteCollection();
|
$collection = new RouteCollection();
|
||||||
$collection->add('bar', new Route('/{bar}', array('bar' => 'bar'), array('bar' => 'foo|bar')));
|
$collection->add('bar', new Route('/{bar}', ['bar' => 'bar'], ['bar' => 'foo|bar']));
|
||||||
$matcher = $this->getUrlMatcher($collection);
|
$matcher = $this->getUrlMatcher($collection);
|
||||||
$this->assertEquals(array('_route' => 'bar', 'bar' => 'foo'), $matcher->match('/foo'));
|
$this->assertEquals(['_route' => 'bar', 'bar' => 'foo'], $matcher->match('/foo'));
|
||||||
$this->assertEquals(array('_route' => 'bar', 'bar' => 'bar'), $matcher->match('/'));
|
$this->assertEquals(['_route' => 'bar', 'bar' => 'bar'], $matcher->match('/'));
|
||||||
|
|
||||||
// route with only optional variables
|
// route with only optional variables
|
||||||
$collection = new RouteCollection();
|
$collection = new RouteCollection();
|
||||||
$collection->add('bar', new Route('/{foo}/{bar}', array('foo' => 'foo', 'bar' => 'bar'), array()));
|
$collection->add('bar', new Route('/{foo}/{bar}', ['foo' => 'foo', 'bar' => 'bar'], []));
|
||||||
$matcher = $this->getUrlMatcher($collection);
|
$matcher = $this->getUrlMatcher($collection);
|
||||||
$this->assertEquals(array('_route' => 'bar', 'foo' => 'foo', 'bar' => 'bar'), $matcher->match('/'));
|
$this->assertEquals(['_route' => 'bar', 'foo' => 'foo', 'bar' => 'bar'], $matcher->match('/'));
|
||||||
$this->assertEquals(array('_route' => 'bar', 'foo' => 'a', 'bar' => 'bar'), $matcher->match('/a'));
|
$this->assertEquals(['_route' => 'bar', 'foo' => 'a', 'bar' => 'bar'], $matcher->match('/a'));
|
||||||
$this->assertEquals(array('_route' => 'bar', 'foo' => 'a', 'bar' => 'b'), $matcher->match('/a/b'));
|
$this->assertEquals(['_route' => 'bar', 'foo' => 'a', 'bar' => 'b'], $matcher->match('/a/b'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMatchWithPrefixes()
|
public function testMatchWithPrefixes()
|
||||||
@ -154,7 +154,7 @@ class UrlMatcherTest extends TestCase
|
|||||||
$collection->addPrefix('/a');
|
$collection->addPrefix('/a');
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($collection);
|
$matcher = $this->getUrlMatcher($collection);
|
||||||
$this->assertEquals(array('_route' => 'foo', 'foo' => 'foo'), $matcher->match('/a/b/foo'));
|
$this->assertEquals(['_route' => 'foo', 'foo' => 'foo'], $matcher->match('/a/b/foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMatchWithDynamicPrefix()
|
public function testMatchWithDynamicPrefix()
|
||||||
@ -165,7 +165,7 @@ class UrlMatcherTest extends TestCase
|
|||||||
$collection->addPrefix('/{_locale}');
|
$collection->addPrefix('/{_locale}');
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($collection);
|
$matcher = $this->getUrlMatcher($collection);
|
||||||
$this->assertEquals(array('_locale' => 'fr', '_route' => 'foo', 'foo' => 'foo'), $matcher->match('/fr/b/foo'));
|
$this->assertEquals(['_locale' => 'fr', '_route' => 'foo', 'foo' => 'foo'], $matcher->match('/fr/b/foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMatchSpecialRouteName()
|
public function testMatchSpecialRouteName()
|
||||||
@ -174,16 +174,16 @@ class UrlMatcherTest extends TestCase
|
|||||||
$collection->add('$péß^a|', new Route('/bar'));
|
$collection->add('$péß^a|', new Route('/bar'));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($collection);
|
$matcher = $this->getUrlMatcher($collection);
|
||||||
$this->assertEquals(array('_route' => '$péß^a|'), $matcher->match('/bar'));
|
$this->assertEquals(['_route' => '$péß^a|'], $matcher->match('/bar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMatchImportantVariable()
|
public function testMatchImportantVariable()
|
||||||
{
|
{
|
||||||
$collection = new RouteCollection();
|
$collection = new RouteCollection();
|
||||||
$collection->add('index', new Route('/index.{!_format}', array('_format' => 'xml')));
|
$collection->add('index', new Route('/index.{!_format}', ['_format' => 'xml']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($collection);
|
$matcher = $this->getUrlMatcher($collection);
|
||||||
$this->assertEquals(array('_route' => 'index', '_format' => 'xml'), $matcher->match('/index.xml'));
|
$this->assertEquals(['_route' => 'index', '_format' => 'xml'], $matcher->match('/index.xml'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -202,20 +202,20 @@ class UrlMatcherTest extends TestCase
|
|||||||
{
|
{
|
||||||
$collection = new RouteCollection();
|
$collection = new RouteCollection();
|
||||||
$chars = '!"$%éà &\'()*+,./:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\[]^_`abcdefghijklmnopqrstuvwxyz{|}~-';
|
$chars = '!"$%éà &\'()*+,./:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\[]^_`abcdefghijklmnopqrstuvwxyz{|}~-';
|
||||||
$collection->add('foo', new Route('/{foo}/bar', array(), array('foo' => '['.preg_quote($chars).']+'), array('utf8' => true)));
|
$collection->add('foo', new Route('/{foo}/bar', [], ['foo' => '['.preg_quote($chars).']+'], ['utf8' => true]));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($collection);
|
$matcher = $this->getUrlMatcher($collection);
|
||||||
$this->assertEquals(array('_route' => 'foo', 'foo' => $chars), $matcher->match('/'.rawurlencode($chars).'/bar'));
|
$this->assertEquals(['_route' => 'foo', 'foo' => $chars], $matcher->match('/'.rawurlencode($chars).'/bar'));
|
||||||
$this->assertEquals(array('_route' => 'foo', 'foo' => $chars), $matcher->match('/'.strtr($chars, array('%' => '%25')).'/bar'));
|
$this->assertEquals(['_route' => 'foo', 'foo' => $chars], $matcher->match('/'.strtr($chars, ['%' => '%25']).'/bar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMatchWithDotMetacharacterInRequirements()
|
public function testMatchWithDotMetacharacterInRequirements()
|
||||||
{
|
{
|
||||||
$collection = new RouteCollection();
|
$collection = new RouteCollection();
|
||||||
$collection->add('foo', new Route('/{foo}/bar', array(), array('foo' => '.+')));
|
$collection->add('foo', new Route('/{foo}/bar', [], ['foo' => '.+']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($collection);
|
$matcher = $this->getUrlMatcher($collection);
|
||||||
$this->assertEquals(array('_route' => 'foo', 'foo' => "\n"), $matcher->match('/'.urlencode("\n").'/bar'), 'linefeed character is matched');
|
$this->assertEquals(['_route' => 'foo', 'foo' => "\n"], $matcher->match('/'.urlencode("\n").'/bar'), 'linefeed character is matched');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMatchOverriddenRoute()
|
public function testMatchOverriddenRoute()
|
||||||
@ -230,9 +230,9 @@ class UrlMatcherTest extends TestCase
|
|||||||
|
|
||||||
$matcher = $this->getUrlMatcher($collection);
|
$matcher = $this->getUrlMatcher($collection);
|
||||||
|
|
||||||
$this->assertEquals(array('_route' => 'foo'), $matcher->match('/foo1'));
|
$this->assertEquals(['_route' => 'foo'], $matcher->match('/foo1'));
|
||||||
$this->expectException('Symfony\Component\Routing\Exception\ResourceNotFoundException');
|
$this->expectException('Symfony\Component\Routing\Exception\ResourceNotFoundException');
|
||||||
$this->assertEquals(array(), $matcher->match('/foo'));
|
$this->assertEquals([], $matcher->match('/foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMatchRegression()
|
public function testMatchRegression()
|
||||||
@ -242,7 +242,7 @@ class UrlMatcherTest extends TestCase
|
|||||||
$coll->add('bar', new Route('/foo/bar/{foo}'));
|
$coll->add('bar', new Route('/foo/bar/{foo}'));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$this->assertEquals(array('foo' => 'bar', '_route' => 'bar'), $matcher->match('/foo/bar/bar'));
|
$this->assertEquals(['foo' => 'bar', '_route' => 'bar'], $matcher->match('/foo/bar/bar'));
|
||||||
|
|
||||||
$collection = new RouteCollection();
|
$collection = new RouteCollection();
|
||||||
$collection->add('foo', new Route('/{bar}'));
|
$collection->add('foo', new Route('/{bar}'));
|
||||||
@ -269,36 +269,36 @@ class UrlMatcherTest extends TestCase
|
|||||||
public function testDefaultRequirementForOptionalVariables()
|
public function testDefaultRequirementForOptionalVariables()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('test', new Route('/{page}.{_format}', array('page' => 'index', '_format' => 'html')));
|
$coll->add('test', new Route('/{page}.{_format}', ['page' => 'index', '_format' => 'html']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$this->assertEquals(array('page' => 'my-page', '_format' => 'xml', '_route' => 'test'), $matcher->match('/my-page.xml'));
|
$this->assertEquals(['page' => 'my-page', '_format' => 'xml', '_route' => 'test'], $matcher->match('/my-page.xml'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMatchingIsEager()
|
public function testMatchingIsEager()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('test', new Route('/{foo}-{bar}-', array(), array('foo' => '.+', 'bar' => '.+')));
|
$coll->add('test', new Route('/{foo}-{bar}-', [], ['foo' => '.+', 'bar' => '.+']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$this->assertEquals(array('foo' => 'text1-text2-text3', 'bar' => 'text4', '_route' => 'test'), $matcher->match('/text1-text2-text3-text4-'));
|
$this->assertEquals(['foo' => 'text1-text2-text3', 'bar' => 'text4', '_route' => 'test'], $matcher->match('/text1-text2-text3-text4-'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAdjacentVariables()
|
public function testAdjacentVariables()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('test', new Route('/{w}{x}{y}{z}.{_format}', array('z' => 'default-z', '_format' => 'html'), array('y' => 'y|Y')));
|
$coll->add('test', new Route('/{w}{x}{y}{z}.{_format}', ['z' => 'default-z', '_format' => 'html'], ['y' => 'y|Y']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
// 'w' eagerly matches as much as possible and the other variables match the remaining chars.
|
// 'w' eagerly matches as much as possible and the other variables match the remaining chars.
|
||||||
// This also shows that the variables w-z must all exclude the separating char (the dot '.' in this case) by default requirement.
|
// This also shows that the variables w-z must all exclude the separating char (the dot '.' in this case) by default requirement.
|
||||||
// Otherwise they would also consume '.xml' and _format would never match as it's an optional variable.
|
// Otherwise they would also consume '.xml' and _format would never match as it's an optional variable.
|
||||||
$this->assertEquals(array('w' => 'wwwww', 'x' => 'x', 'y' => 'Y', 'z' => 'Z', '_format' => 'xml', '_route' => 'test'), $matcher->match('/wwwwwxYZ.xml'));
|
$this->assertEquals(['w' => 'wwwww', 'x' => 'x', 'y' => 'Y', 'z' => 'Z', '_format' => 'xml', '_route' => 'test'], $matcher->match('/wwwwwxYZ.xml'));
|
||||||
// As 'y' has custom requirement and can only be of value 'y|Y', it will leave 'ZZZ' to variable z.
|
// As 'y' has custom requirement and can only be of value 'y|Y', it will leave 'ZZZ' to variable z.
|
||||||
// So with carefully chosen requirements adjacent variables, can be useful.
|
// So with carefully chosen requirements adjacent variables, can be useful.
|
||||||
$this->assertEquals(array('w' => 'wwwww', 'x' => 'x', 'y' => 'y', 'z' => 'ZZZ', '_format' => 'html', '_route' => 'test'), $matcher->match('/wwwwwxyZZZ'));
|
$this->assertEquals(['w' => 'wwwww', 'x' => 'x', 'y' => 'y', 'z' => 'ZZZ', '_format' => 'html', '_route' => 'test'], $matcher->match('/wwwwwxyZZZ'));
|
||||||
// z and _format are optional.
|
// z and _format are optional.
|
||||||
$this->assertEquals(array('w' => 'wwwww', 'x' => 'x', 'y' => 'y', 'z' => 'default-z', '_format' => 'html', '_route' => 'test'), $matcher->match('/wwwwwxy'));
|
$this->assertEquals(['w' => 'wwwww', 'x' => 'x', 'y' => 'y', 'z' => 'default-z', '_format' => 'html', '_route' => 'test'], $matcher->match('/wwwwwxy'));
|
||||||
|
|
||||||
$this->expectException('Symfony\Component\Routing\Exception\ResourceNotFoundException');
|
$this->expectException('Symfony\Component\Routing\Exception\ResourceNotFoundException');
|
||||||
$matcher->match('/wxy.html');
|
$matcher->match('/wxy.html');
|
||||||
@ -307,11 +307,11 @@ class UrlMatcherTest extends TestCase
|
|||||||
public function testOptionalVariableWithNoRealSeparator()
|
public function testOptionalVariableWithNoRealSeparator()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('test', new Route('/get{what}', array('what' => 'All')));
|
$coll->add('test', new Route('/get{what}', ['what' => 'All']));
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
|
|
||||||
$this->assertEquals(array('what' => 'All', '_route' => 'test'), $matcher->match('/get'));
|
$this->assertEquals(['what' => 'All', '_route' => 'test'], $matcher->match('/get'));
|
||||||
$this->assertEquals(array('what' => 'Sites', '_route' => 'test'), $matcher->match('/getSites'));
|
$this->assertEquals(['what' => 'Sites', '_route' => 'test'], $matcher->match('/getSites'));
|
||||||
|
|
||||||
// Usually the character in front of an optional parameter can be left out, e.g. with pattern '/get/{what}' just '/get' would match.
|
// Usually the character in front of an optional parameter can be left out, e.g. with pattern '/get/{what}' just '/get' would match.
|
||||||
// But here the 't' in 'get' is not a separating character, so it makes no sense to match without it.
|
// But here the 't' in 'get' is not a separating character, so it makes no sense to match without it.
|
||||||
@ -325,7 +325,7 @@ class UrlMatcherTest extends TestCase
|
|||||||
$coll->add('test', new Route('/get{what}Suffix'));
|
$coll->add('test', new Route('/get{what}Suffix'));
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
|
|
||||||
$this->assertEquals(array('what' => 'Sites', '_route' => 'test'), $matcher->match('/getSitesSuffix'));
|
$this->assertEquals(['what' => 'Sites', '_route' => 'test'], $matcher->match('/getSitesSuffix'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefaultRequirementOfVariable()
|
public function testDefaultRequirementOfVariable()
|
||||||
@ -334,7 +334,7 @@ class UrlMatcherTest extends TestCase
|
|||||||
$coll->add('test', new Route('/{page}.{_format}'));
|
$coll->add('test', new Route('/{page}.{_format}'));
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
|
|
||||||
$this->assertEquals(array('page' => 'index', '_format' => 'mobile.html', '_route' => 'test'), $matcher->match('/index.mobile.html'));
|
$this->assertEquals(['page' => 'index', '_format' => 'mobile.html', '_route' => 'test'], $matcher->match('/index.mobile.html'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -355,7 +355,7 @@ class UrlMatcherTest extends TestCase
|
|||||||
public function testDefaultRequirementOfVariableDisallowsNextSeparator()
|
public function testDefaultRequirementOfVariableDisallowsNextSeparator()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('test', new Route('/{page}.{_format}', array(), array('_format' => 'html|xml')));
|
$coll->add('test', new Route('/{page}.{_format}', [], ['_format' => 'html|xml']));
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
|
|
||||||
$matcher->match('/do.t.html');
|
$matcher->match('/do.t.html');
|
||||||
@ -419,7 +419,7 @@ class UrlMatcherTest extends TestCase
|
|||||||
public function testSchemeRequirement()
|
public function testSchemeRequirement()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array('https')));
|
$coll->add('foo', new Route('/foo', [], [], [], '', ['https']));
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$matcher->match('/foo');
|
$matcher->match('/foo');
|
||||||
}
|
}
|
||||||
@ -430,7 +430,7 @@ class UrlMatcherTest extends TestCase
|
|||||||
public function testSchemeRequirementForNonSafeMethod()
|
public function testSchemeRequirementForNonSafeMethod()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array('https')));
|
$coll->add('foo', new Route('/foo', [], [], [], '', ['https']));
|
||||||
|
|
||||||
$context = new RequestContext();
|
$context = new RequestContext();
|
||||||
$context->setMethod('POST');
|
$context->setMethod('POST');
|
||||||
@ -441,10 +441,10 @@ class UrlMatcherTest extends TestCase
|
|||||||
public function testSamePathWithDifferentScheme()
|
public function testSamePathWithDifferentScheme()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('https_route', new Route('/', array(), array(), array(), '', array('https')));
|
$coll->add('https_route', new Route('/', [], [], [], '', ['https']));
|
||||||
$coll->add('http_route', new Route('/', array(), array(), array(), '', array('http')));
|
$coll->add('http_route', new Route('/', [], [], [], '', ['http']));
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$this->assertEquals(array('_route' => 'http_route'), $matcher->match('/'));
|
$this->assertEquals(['_route' => 'http_route'], $matcher->match('/'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -470,7 +470,7 @@ class UrlMatcherTest extends TestCase
|
|||||||
$route->setCondition('request.getBaseUrl() == "/sub/front.php" and request.getPathInfo() == "/foo/bar"');
|
$route->setCondition('request.getBaseUrl() == "/sub/front.php" and request.getPathInfo() == "/foo/bar"');
|
||||||
$coll->add('foo', $route);
|
$coll->add('foo', $route);
|
||||||
$matcher = $this->getUrlMatcher($coll, new RequestContext('/sub/front.php'));
|
$matcher = $this->getUrlMatcher($coll, new RequestContext('/sub/front.php'));
|
||||||
$this->assertEquals(array('bar' => 'bar', '_route' => 'foo'), $matcher->match('/foo/bar'));
|
$this->assertEquals(['bar' => 'bar', '_route' => 'foo'], $matcher->match('/foo/bar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDecodeOnce()
|
public function testDecodeOnce()
|
||||||
@ -479,7 +479,7 @@ class UrlMatcherTest extends TestCase
|
|||||||
$coll->add('foo', new Route('/foo/{foo}'));
|
$coll->add('foo', new Route('/foo/{foo}'));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$this->assertEquals(array('foo' => 'bar%23', '_route' => 'foo'), $matcher->match('/foo/bar%2523'));
|
$this->assertEquals(['foo' => 'bar%23', '_route' => 'foo'], $matcher->match('/foo/bar%2523'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCannotRelyOnPrefix()
|
public function testCannotRelyOnPrefix()
|
||||||
@ -495,30 +495,30 @@ class UrlMatcherTest extends TestCase
|
|||||||
$coll->addCollection($subColl);
|
$coll->addCollection($subColl);
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$this->assertEquals(array('_route' => 'bar'), $matcher->match('/new'));
|
$this->assertEquals(['_route' => 'bar'], $matcher->match('/new'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithHost()
|
public function testWithHost()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('foo', new Route('/foo/{foo}', array(), array(), array(), '{locale}.example.com'));
|
$coll->add('foo', new Route('/foo/{foo}', [], [], [], '{locale}.example.com'));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
|
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
|
||||||
$this->assertEquals(array('foo' => 'bar', '_route' => 'foo', 'locale' => 'en'), $matcher->match('/foo/bar'));
|
$this->assertEquals(['foo' => 'bar', '_route' => 'foo', 'locale' => 'en'], $matcher->match('/foo/bar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithHostOnRouteCollection()
|
public function testWithHostOnRouteCollection()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('foo', new Route('/foo/{foo}'));
|
$coll->add('foo', new Route('/foo/{foo}'));
|
||||||
$coll->add('bar', new Route('/bar/{foo}', array(), array(), array(), '{locale}.example.net'));
|
$coll->add('bar', new Route('/bar/{foo}', [], [], [], '{locale}.example.net'));
|
||||||
$coll->setHost('{locale}.example.com');
|
$coll->setHost('{locale}.example.com');
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
|
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
|
||||||
$this->assertEquals(array('foo' => 'bar', '_route' => 'foo', 'locale' => 'en'), $matcher->match('/foo/bar'));
|
$this->assertEquals(['foo' => 'bar', '_route' => 'foo', 'locale' => 'en'], $matcher->match('/foo/bar'));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
|
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
|
||||||
$this->assertEquals(array('foo' => 'bar', '_route' => 'bar', 'locale' => 'en'), $matcher->match('/bar/bar'));
|
$this->assertEquals(['foo' => 'bar', '_route' => 'bar', 'locale' => 'en'], $matcher->match('/bar/bar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -527,7 +527,7 @@ class UrlMatcherTest extends TestCase
|
|||||||
public function testWithOutHostHostDoesNotMatch()
|
public function testWithOutHostHostDoesNotMatch()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('foo', new Route('/foo/{foo}', array(), array(), array(), '{locale}.example.com'));
|
$coll->add('foo', new Route('/foo/{foo}', [], [], [], '{locale}.example.com'));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'example.com'));
|
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'example.com'));
|
||||||
$matcher->match('/foo/bar');
|
$matcher->match('/foo/bar');
|
||||||
@ -539,7 +539,7 @@ class UrlMatcherTest extends TestCase
|
|||||||
public function testPathIsCaseSensitive()
|
public function testPathIsCaseSensitive()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('foo', new Route('/locale', array(), array('locale' => 'EN|FR|DE')));
|
$coll->add('foo', new Route('/locale', [], ['locale' => 'EN|FR|DE']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$matcher->match('/en');
|
$matcher->match('/en');
|
||||||
@ -548,10 +548,10 @@ class UrlMatcherTest extends TestCase
|
|||||||
public function testHostIsCaseInsensitive()
|
public function testHostIsCaseInsensitive()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('foo', new Route('/', array(), array('locale' => 'EN|FR|DE'), array(), '{locale}.example.com'));
|
$coll->add('foo', new Route('/', [], ['locale' => 'EN|FR|DE'], [], '{locale}.example.com'));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
|
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
|
||||||
$this->assertEquals(array('_route' => 'foo', 'locale' => 'en'), $matcher->match('/'));
|
$this->assertEquals(['_route' => 'foo', 'locale' => 'en'], $matcher->match('/'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -584,9 +584,9 @@ class UrlMatcherTest extends TestCase
|
|||||||
$coll->addCollection($subColl);
|
$coll->addCollection($subColl);
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$this->assertEquals(array('_route' => 'a'), $matcher->match('/p/a'));
|
$this->assertEquals(['_route' => 'a'], $matcher->match('/p/a'));
|
||||||
$this->assertEquals(array('_route' => 'baz', 'baz' => 'p'), $matcher->match('/p'));
|
$this->assertEquals(['_route' => 'baz', 'baz' => 'p'], $matcher->match('/p'));
|
||||||
$this->assertEquals(array('_route' => 'buz'), $matcher->match('/prefix/buz'));
|
$this->assertEquals(['_route' => 'buz'], $matcher->match('/prefix/buz'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -595,7 +595,7 @@ class UrlMatcherTest extends TestCase
|
|||||||
public function testSchemeAndMethodMismatch()
|
public function testSchemeAndMethodMismatch()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('foo', new Route('/', array(), array(), array(), null, array('https'), array('POST')));
|
$coll->add('foo', new Route('/', [], [], [], null, ['https'], ['POST']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$matcher->match('/');
|
$matcher->match('/');
|
||||||
@ -609,54 +609,54 @@ class UrlMatcherTest extends TestCase
|
|||||||
$coll->add('c', new Route('/a{a}'));
|
$coll->add('c', new Route('/a{a}'));
|
||||||
$coll->add('d', (new Route('/b{a}'))->setCondition('false'));
|
$coll->add('d', (new Route('/b{a}'))->setCondition('false'));
|
||||||
$coll->add('e', (new Route('/{b}{a}'))->setCondition('false'));
|
$coll->add('e', (new Route('/{b}{a}'))->setCondition('false'));
|
||||||
$coll->add('f', (new Route('/{b}{a}'))->setRequirements(array('b' => 'b')));
|
$coll->add('f', (new Route('/{b}{a}'))->setRequirements(['b' => 'b']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$this->assertEquals(array('_route' => 'c', 'a' => 'a'), $matcher->match('/aa'));
|
$this->assertEquals(['_route' => 'c', 'a' => 'a'], $matcher->match('/aa'));
|
||||||
$this->assertEquals(array('_route' => 'f', 'b' => 'b', 'a' => 'a'), $matcher->match('/ba'));
|
$this->assertEquals(['_route' => 'f', 'b' => 'b', 'a' => 'a'], $matcher->match('/ba'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUnicodeRoute()
|
public function testUnicodeRoute()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('a', new Route('/{a}', array(), array('a' => '.'), array('utf8' => false)));
|
$coll->add('a', new Route('/{a}', [], ['a' => '.'], ['utf8' => false]));
|
||||||
$coll->add('b', new Route('/{a}', array(), array('a' => '.'), array('utf8' => true)));
|
$coll->add('b', new Route('/{a}', [], ['a' => '.'], ['utf8' => true]));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$this->assertEquals(array('_route' => 'b', 'a' => 'é'), $matcher->match('/é'));
|
$this->assertEquals(['_route' => 'b', 'a' => 'é'], $matcher->match('/é'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRequirementWithCapturingGroup()
|
public function testRequirementWithCapturingGroup()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('a', new Route('/{a}/{b}', array(), array('a' => '(a|b)')));
|
$coll->add('a', new Route('/{a}/{b}', [], ['a' => '(a|b)']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$this->assertEquals(array('_route' => 'a', 'a' => 'a', 'b' => 'b'), $matcher->match('/a/b'));
|
$this->assertEquals(['_route' => 'a', 'a' => 'a', 'b' => 'b'], $matcher->match('/a/b'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDotAllWithCatchAll()
|
public function testDotAllWithCatchAll()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('a', new Route('/{id}.html', array(), array('id' => '.+')));
|
$coll->add('a', new Route('/{id}.html', [], ['id' => '.+']));
|
||||||
$coll->add('b', new Route('/{all}', array(), array('all' => '.+')));
|
$coll->add('b', new Route('/{all}', [], ['all' => '.+']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$this->assertEquals(array('_route' => 'a', 'id' => 'foo/bar'), $matcher->match('/foo/bar.html'));
|
$this->assertEquals(['_route' => 'a', 'id' => 'foo/bar'], $matcher->match('/foo/bar.html'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHostPattern()
|
public function testHostPattern()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('a', new Route('/{app}/{action}/{unused}', array(), array(), array(), '{host}'));
|
$coll->add('a', new Route('/{app}/{action}/{unused}', [], [], [], '{host}'));
|
||||||
|
|
||||||
$expected = array(
|
$expected = [
|
||||||
'_route' => 'a',
|
'_route' => 'a',
|
||||||
'app' => 'an_app',
|
'app' => 'an_app',
|
||||||
'action' => 'an_action',
|
'action' => 'an_action',
|
||||||
'unused' => 'unused',
|
'unused' => 'unused',
|
||||||
'host' => 'foo',
|
'host' => 'foo',
|
||||||
);
|
];
|
||||||
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'foo'));
|
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'foo'));
|
||||||
$this->assertEquals($expected, $matcher->match('/an_app/an_action/unused'));
|
$this->assertEquals($expected, $matcher->match('/an_app/an_action/unused'));
|
||||||
}
|
}
|
||||||
@ -664,8 +664,8 @@ class UrlMatcherTest extends TestCase
|
|||||||
public function testUtf8Prefix()
|
public function testUtf8Prefix()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('a', new Route('/é{foo}', array(), array(), array('utf8' => true)));
|
$coll->add('a', new Route('/é{foo}', [], [], ['utf8' => true]));
|
||||||
$coll->add('b', new Route('/è{bar}', array(), array(), array('utf8' => true)));
|
$coll->add('b', new Route('/è{bar}', [], [], ['utf8' => true]));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$this->assertEquals('a', $matcher->match('/éo')['_route']);
|
$this->assertEquals('a', $matcher->match('/éo')['_route']);
|
||||||
@ -674,9 +674,9 @@ class UrlMatcherTest extends TestCase
|
|||||||
public function testUtf8AndMethodMatching()
|
public function testUtf8AndMethodMatching()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('a', new Route('/admin/api/list/{shortClassName}/{id}.{_format}', array(), array(), array('utf8' => true), '', array(), array('PUT')));
|
$coll->add('a', new Route('/admin/api/list/{shortClassName}/{id}.{_format}', [], [], ['utf8' => true], '', [], ['PUT']));
|
||||||
$coll->add('b', new Route('/admin/api/package.{_format}', array(), array(), array(), '', array(), array('POST')));
|
$coll->add('b', new Route('/admin/api/package.{_format}', [], [], [], '', [], ['POST']));
|
||||||
$coll->add('c', new Route('/admin/api/package.{_format}', array('_format' => 'json'), array(), array(), '', array(), array('GET')));
|
$coll->add('c', new Route('/admin/api/package.{_format}', ['_format' => 'json'], [], [], '', [], ['GET']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$this->assertEquals('c', $matcher->match('/admin/api/package.json')['_route']);
|
$this->assertEquals('c', $matcher->match('/admin/api/package.json')['_route']);
|
||||||
@ -685,7 +685,7 @@ class UrlMatcherTest extends TestCase
|
|||||||
public function testHostWithDot()
|
public function testHostWithDot()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('a', new Route('/foo', array(), array(), array(), 'foo.example.com'));
|
$coll->add('a', new Route('/foo', [], [], [], 'foo.example.com'));
|
||||||
$coll->add('b', new Route('/bar/{baz}'));
|
$coll->add('b', new Route('/bar/{baz}'));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
@ -695,7 +695,7 @@ class UrlMatcherTest extends TestCase
|
|||||||
public function testSlashVariant()
|
public function testSlashVariant()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('a', new Route('/foo/{bar}', array(), array('bar' => '.*')));
|
$coll->add('a', new Route('/foo/{bar}', [], ['bar' => '.*']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$this->assertEquals('a', $matcher->match('/foo/')['_route']);
|
$this->assertEquals('a', $matcher->match('/foo/')['_route']);
|
||||||
@ -704,54 +704,54 @@ class UrlMatcherTest extends TestCase
|
|||||||
public function testSlashVariant2()
|
public function testSlashVariant2()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('a', new Route('/foo/{bar}/', array(), array('bar' => '.*')));
|
$coll->add('a', new Route('/foo/{bar}/', [], ['bar' => '.*']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$this->assertEquals(array('_route' => 'a', 'bar' => 'bar'), $matcher->match('/foo/bar/'));
|
$this->assertEquals(['_route' => 'a', 'bar' => 'bar'], $matcher->match('/foo/bar/'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSlashWithVerb()
|
public function testSlashWithVerb()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('a', new Route('/{foo}', array(), array(), array(), '', array(), array('put', 'delete')));
|
$coll->add('a', new Route('/{foo}', [], [], [], '', [], ['put', 'delete']));
|
||||||
$coll->add('b', new Route('/bar/'));
|
$coll->add('b', new Route('/bar/'));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$this->assertSame(array('_route' => 'b'), $matcher->match('/bar/'));
|
$this->assertSame(['_route' => 'b'], $matcher->match('/bar/'));
|
||||||
|
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('a', new Route('/dav/{foo<.*>?}', array(), array(), array(), '', array(), array('GET', 'OPTIONS')));
|
$coll->add('a', new Route('/dav/{foo<.*>?}', [], [], [], '', [], ['GET', 'OPTIONS']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'OPTIONS'));
|
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'OPTIONS'));
|
||||||
$expected = array(
|
$expected = [
|
||||||
'_route' => 'a',
|
'_route' => 'a',
|
||||||
'foo' => 'files/bar',
|
'foo' => 'files/bar',
|
||||||
);
|
];
|
||||||
$this->assertEquals($expected, $matcher->match('/dav/files/bar/'));
|
$this->assertEquals($expected, $matcher->match('/dav/files/bar/'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSlashAndVerbPrecedence()
|
public function testSlashAndVerbPrecedence()
|
||||||
{
|
{
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('a', new Route('/api/customers/{customerId}/contactpersons/', array(), array(), array(), '', array(), array('post')));
|
$coll->add('a', new Route('/api/customers/{customerId}/contactpersons/', [], [], [], '', [], ['post']));
|
||||||
$coll->add('b', new Route('/api/customers/{customerId}/contactpersons', array(), array(), array(), '', array(), array('get')));
|
$coll->add('b', new Route('/api/customers/{customerId}/contactpersons', [], [], [], '', [], ['get']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll);
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
$expected = array(
|
$expected = [
|
||||||
'_route' => 'b',
|
'_route' => 'b',
|
||||||
'customerId' => '123',
|
'customerId' => '123',
|
||||||
);
|
];
|
||||||
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons'));
|
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons'));
|
||||||
|
|
||||||
$coll = new RouteCollection();
|
$coll = new RouteCollection();
|
||||||
$coll->add('a', new Route('/api/customers/{customerId}/contactpersons/', array(), array(), array(), '', array(), array('get')));
|
$coll->add('a', new Route('/api/customers/{customerId}/contactpersons/', [], [], [], '', [], ['get']));
|
||||||
$coll->add('b', new Route('/api/customers/{customerId}/contactpersons', array(), array(), array(), '', array(), array('post')));
|
$coll->add('b', new Route('/api/customers/{customerId}/contactpersons', [], [], [], '', [], ['post']));
|
||||||
|
|
||||||
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'POST'));
|
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'POST'));
|
||||||
$expected = array(
|
$expected = [
|
||||||
'_route' => 'b',
|
'_route' => 'b',
|
||||||
'customerId' => '123',
|
'customerId' => '123',
|
||||||
);
|
];
|
||||||
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons'));
|
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,32 +31,32 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
|||||||
const AS_COLLECTION_KEY = 'as_collection';
|
const AS_COLLECTION_KEY = 'as_collection';
|
||||||
const NO_HEADERS_KEY = 'no_headers';
|
const NO_HEADERS_KEY = 'no_headers';
|
||||||
|
|
||||||
private $formulasStartCharacters = array('=', '-', '+', '@');
|
private $formulasStartCharacters = ['=', '-', '+', '@'];
|
||||||
private $defaultContext = array(
|
private $defaultContext = [
|
||||||
self::DELIMITER_KEY => ',',
|
self::DELIMITER_KEY => ',',
|
||||||
self::ENCLOSURE_KEY => '"',
|
self::ENCLOSURE_KEY => '"',
|
||||||
self::ESCAPE_CHAR_KEY => '\\',
|
self::ESCAPE_CHAR_KEY => '\\',
|
||||||
self::ESCAPE_FORMULAS_KEY => false,
|
self::ESCAPE_FORMULAS_KEY => false,
|
||||||
self::HEADERS_KEY => array(),
|
self::HEADERS_KEY => [],
|
||||||
self::KEY_SEPARATOR_KEY => '.',
|
self::KEY_SEPARATOR_KEY => '.',
|
||||||
self::NO_HEADERS_KEY => false,
|
self::NO_HEADERS_KEY => false,
|
||||||
);
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $defaultContext
|
* @param array $defaultContext
|
||||||
*/
|
*/
|
||||||
public function __construct($defaultContext = array(), string $enclosure = '"', string $escapeChar = '\\', string $keySeparator = '.', bool $escapeFormulas = false)
|
public function __construct($defaultContext = [], string $enclosure = '"', string $escapeChar = '\\', string $keySeparator = '.', bool $escapeFormulas = false)
|
||||||
{
|
{
|
||||||
if (!\is_array($defaultContext)) {
|
if (!\is_array($defaultContext)) {
|
||||||
@trigger_error('Passing configuration options directly to the constructor is deprecated since Symfony 4.2, use the default context instead.', E_USER_DEPRECATED);
|
@trigger_error('Passing configuration options directly to the constructor is deprecated since Symfony 4.2, use the default context instead.', E_USER_DEPRECATED);
|
||||||
|
|
||||||
$defaultContext = array(
|
$defaultContext = [
|
||||||
self::DELIMITER_KEY => (string) $defaultContext,
|
self::DELIMITER_KEY => (string) $defaultContext,
|
||||||
self::ENCLOSURE_KEY => $enclosure,
|
self::ENCLOSURE_KEY => $enclosure,
|
||||||
self::ESCAPE_CHAR_KEY => $escapeChar,
|
self::ESCAPE_CHAR_KEY => $escapeChar,
|
||||||
self::KEY_SEPARATOR_KEY => $keySeparator,
|
self::KEY_SEPARATOR_KEY => $keySeparator,
|
||||||
self::ESCAPE_FORMULAS_KEY => $escapeFormulas,
|
self::ESCAPE_FORMULAS_KEY => $escapeFormulas,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->defaultContext = array_merge($this->defaultContext, $defaultContext);
|
$this->defaultContext = array_merge($this->defaultContext, $defaultContext);
|
||||||
@ -65,20 +65,20 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function encode($data, $format, array $context = array())
|
public function encode($data, $format, array $context = [])
|
||||||
{
|
{
|
||||||
$handle = fopen('php://temp,', 'w+');
|
$handle = fopen('php://temp,', 'w+');
|
||||||
|
|
||||||
if (!\is_array($data)) {
|
if (!\is_array($data)) {
|
||||||
$data = array(array($data));
|
$data = [[$data]];
|
||||||
} elseif (empty($data)) {
|
} elseif (empty($data)) {
|
||||||
$data = array(array());
|
$data = [[]];
|
||||||
} else {
|
} else {
|
||||||
// Sequential arrays of arrays are considered as collections
|
// Sequential arrays of arrays are considered as collections
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
if ($i !== $key || !\is_array($value)) {
|
if ($i !== $key || !\is_array($value)) {
|
||||||
$data = array($data);
|
$data = [$data];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
|||||||
list($delimiter, $enclosure, $escapeChar, $keySeparator, $headers, $escapeFormulas) = $this->getCsvOptions($context);
|
list($delimiter, $enclosure, $escapeChar, $keySeparator, $headers, $escapeFormulas) = $this->getCsvOptions($context);
|
||||||
|
|
||||||
foreach ($data as &$value) {
|
foreach ($data as &$value) {
|
||||||
$flattened = array();
|
$flattened = [];
|
||||||
$this->flatten($value, $flattened, $keySeparator, '', $escapeFormulas);
|
$this->flatten($value, $flattened, $keySeparator, '', $escapeFormulas);
|
||||||
$value = $flattened;
|
$value = $flattened;
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function decode($data, $format, array $context = array())
|
public function decode($data, $format, array $context = [])
|
||||||
{
|
{
|
||||||
$handle = fopen('php://temp', 'r+');
|
$handle = fopen('php://temp', 'r+');
|
||||||
fwrite($handle, $data);
|
fwrite($handle, $data);
|
||||||
@ -132,8 +132,8 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
|||||||
|
|
||||||
$headers = null;
|
$headers = null;
|
||||||
$nbHeaders = 0;
|
$nbHeaders = 0;
|
||||||
$headerCount = array();
|
$headerCount = [];
|
||||||
$result = array();
|
$result = [];
|
||||||
|
|
||||||
list($delimiter, $enclosure, $escapeChar, $keySeparator) = $this->getCsvOptions($context);
|
list($delimiter, $enclosure, $escapeChar, $keySeparator) = $this->getCsvOptions($context);
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
|||||||
|
|
||||||
if ($context[self::NO_HEADERS_KEY] ?? false) {
|
if ($context[self::NO_HEADERS_KEY] ?? false) {
|
||||||
for ($i = 0; $i < $nbCols; ++$i) {
|
for ($i = 0; $i < $nbCols; ++$i) {
|
||||||
$headers[] = array($i);
|
$headers[] = [$i];
|
||||||
}
|
}
|
||||||
$headerCount = array_fill(0, $nbCols, 1);
|
$headerCount = array_fill(0, $nbCols, 1);
|
||||||
} else {
|
} else {
|
||||||
@ -159,7 +159,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$item = array();
|
$item = [];
|
||||||
for ($i = 0; ($i < $nbCols) && ($i < $nbHeaders); ++$i) {
|
for ($i = 0; ($i < $nbCols) && ($i < $nbHeaders); ++$i) {
|
||||||
$depth = $headerCount[$i];
|
$depth = $headerCount[$i];
|
||||||
$arr = &$item;
|
$arr = &$item;
|
||||||
@ -172,7 +172,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($arr[$headers[$i][$j]])) {
|
if (!isset($arr[$headers[$i][$j]])) {
|
||||||
$arr[$headers[$i][$j]] = array();
|
$arr[$headers[$i][$j]] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$arr = &$arr[$headers[$i][$j]];
|
$arr = &$arr[$headers[$i][$j]];
|
||||||
@ -238,7 +238,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
|||||||
throw new InvalidArgumentException(sprintf('The "%s" context variable must be an array or null, given "%s".', self::HEADERS_KEY, \gettype($headers)));
|
throw new InvalidArgumentException(sprintf('The "%s" context variable must be an array or null, given "%s".', self::HEADERS_KEY, \gettype($headers)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return array($delimiter, $enclosure, $escapeChar, $keySeparator, $headers, $escapeFormulas);
|
return [$delimiter, $enclosure, $escapeChar, $keySeparator, $headers, $escapeFormulas];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -246,8 +246,8 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
|||||||
*/
|
*/
|
||||||
private function extractHeaders(array $data)
|
private function extractHeaders(array $data)
|
||||||
{
|
{
|
||||||
$headers = array();
|
$headers = [];
|
||||||
$flippedHeaders = array();
|
$flippedHeaders = [];
|
||||||
|
|
||||||
foreach ($data as $row) {
|
foreach ($data as $row) {
|
||||||
$previousHeader = null;
|
$previousHeader = null;
|
||||||
|
@ -316,9 +316,9 @@ a,b
|
|||||||
c,d
|
c,d
|
||||||
|
|
||||||
CSV
|
CSV
|
||||||
, $this->encoder->encode(array(array('a', 'b'), array('c', 'd')), 'csv', array(
|
, $this->encoder->encode([['a', 'b'], ['c', 'd']], 'csv', [
|
||||||
CsvEncoder::NO_HEADERS_KEY => true,
|
CsvEncoder::NO_HEADERS_KEY => true,
|
||||||
)));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSupportsDecoding()
|
public function testSupportsDecoding()
|
||||||
@ -495,13 +495,13 @@ CSV
|
|||||||
|
|
||||||
public function testDecodeWithoutHeader()
|
public function testDecodeWithoutHeader()
|
||||||
{
|
{
|
||||||
$this->assertEquals(array(array('a', 'b'), array('c', 'd')), $this->encoder->decode(<<<'CSV'
|
$this->assertEquals([['a', 'b'], ['c', 'd']], $this->encoder->decode(<<<'CSV'
|
||||||
a,b
|
a,b
|
||||||
c,d
|
c,d
|
||||||
|
|
||||||
CSV
|
CSV
|
||||||
, 'csv', array(
|
, 'csv', [
|
||||||
CsvEncoder::NO_HEADERS_KEY => true,
|
CsvEncoder::NO_HEADERS_KEY => true,
|
||||||
)));
|
]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,17 +104,17 @@ class XliffFileLoader implements LoaderInterface
|
|||||||
|
|
||||||
$catalogue->set((string) $source, $target, $domain);
|
$catalogue->set((string) $source, $target, $domain);
|
||||||
|
|
||||||
$metadata = array(
|
$metadata = [
|
||||||
'file' => array(
|
'file' => [
|
||||||
'original' => (string) $fileAttributes['original'],
|
'original' => (string) $fileAttributes['original'],
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
if ($notes = $this->parseNotesMetadata($translation->note, $encoding)) {
|
if ($notes = $this->parseNotesMetadata($translation->note, $encoding)) {
|
||||||
$metadata['notes'] = $notes;
|
$metadata['notes'] = $notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($translation->target) && $translation->target->attributes()) {
|
if (isset($translation->target) && $translation->target->attributes()) {
|
||||||
$metadata['target-attributes'] = array();
|
$metadata['target-attributes'] = [];
|
||||||
foreach ($translation->target->attributes() as $key => $value) {
|
foreach ($translation->target->attributes() as $key => $value) {
|
||||||
$metadata['target-attributes'][$key] = (string) $value;
|
$metadata['target-attributes'][$key] = (string) $value;
|
||||||
}
|
}
|
||||||
@ -146,18 +146,18 @@ class XliffFileLoader implements LoaderInterface
|
|||||||
|
|
||||||
$catalogue->set((string) $source, $target, $domain);
|
$catalogue->set((string) $source, $target, $domain);
|
||||||
|
|
||||||
$metadata = array();
|
$metadata = [];
|
||||||
if (isset($segment->target) && $segment->target->attributes()) {
|
if (isset($segment->target) && $segment->target->attributes()) {
|
||||||
$metadata['target-attributes'] = array();
|
$metadata['target-attributes'] = [];
|
||||||
foreach ($segment->target->attributes() as $key => $value) {
|
foreach ($segment->target->attributes() as $key => $value) {
|
||||||
$metadata['target-attributes'][$key] = (string) $value;
|
$metadata['target-attributes'][$key] = (string) $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($unit->notes)) {
|
if (isset($unit->notes)) {
|
||||||
$metadata['notes'] = array();
|
$metadata['notes'] = [];
|
||||||
foreach ($unit->notes->note as $noteNode) {
|
foreach ($unit->notes->note as $noteNode) {
|
||||||
$note = array();
|
$note = [];
|
||||||
foreach ($noteNode->attributes() as $key => $value) {
|
foreach ($noteNode->attributes() as $key => $value) {
|
||||||
$note[$key] = (string) $value;
|
$note[$key] = (string) $value;
|
||||||
}
|
}
|
||||||
@ -185,7 +185,7 @@ class XliffFileLoader implements LoaderInterface
|
|||||||
|
|
||||||
private function parseNotesMetadata(\SimpleXMLElement $noteElement = null, string $encoding = null): array
|
private function parseNotesMetadata(\SimpleXMLElement $noteElement = null, string $encoding = null): array
|
||||||
{
|
{
|
||||||
$notes = array();
|
$notes = [];
|
||||||
|
|
||||||
if (null === $noteElement) {
|
if (null === $noteElement) {
|
||||||
return $notes;
|
return $notes;
|
||||||
@ -194,7 +194,7 @@ class XliffFileLoader implements LoaderInterface
|
|||||||
/** @var \SimpleXMLElement $xmlNote */
|
/** @var \SimpleXMLElement $xmlNote */
|
||||||
foreach ($noteElement as $xmlNote) {
|
foreach ($noteElement as $xmlNote) {
|
||||||
$noteAttributes = $xmlNote->attributes();
|
$noteAttributes = $xmlNote->attributes();
|
||||||
$note = array('content' => $this->utf8ToCharset((string) $xmlNote, $encoding));
|
$note = ['content' => $this->utf8ToCharset((string) $xmlNote, $encoding)];
|
||||||
if (isset($noteAttributes['priority'])) {
|
if (isset($noteAttributes['priority'])) {
|
||||||
$note['priority'] = (int) $noteAttributes['priority'];
|
$note['priority'] = (int) $noteAttributes['priority'];
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,8 @@ class XliffFileLoaderTest extends TestCase
|
|||||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||||
|
|
||||||
$this->assertEquals('en', $catalogue->getLocale());
|
$this->assertEquals('en', $catalogue->getLocale());
|
||||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||||
$this->assertSame(array(), libxml_get_errors());
|
$this->assertSame([], libxml_get_errors());
|
||||||
$this->assertContainsOnly('string', $catalogue->all('domain1'));
|
$this->assertContainsOnly('string', $catalogue->all('domain1'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,15 +33,15 @@ class XliffFileLoaderTest extends TestCase
|
|||||||
{
|
{
|
||||||
$internalErrors = libxml_use_internal_errors(true);
|
$internalErrors = libxml_use_internal_errors(true);
|
||||||
|
|
||||||
$this->assertSame(array(), libxml_get_errors());
|
$this->assertSame([], libxml_get_errors());
|
||||||
|
|
||||||
$loader = new XliffFileLoader();
|
$loader = new XliffFileLoader();
|
||||||
$resource = __DIR__.'/../fixtures/resources.xlf';
|
$resource = __DIR__.'/../fixtures/resources.xlf';
|
||||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||||
|
|
||||||
$this->assertEquals('en', $catalogue->getLocale());
|
$this->assertEquals('en', $catalogue->getLocale());
|
||||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||||
$this->assertSame(array(), libxml_get_errors());
|
$this->assertSame([], libxml_get_errors());
|
||||||
|
|
||||||
libxml_clear_errors();
|
libxml_clear_errors();
|
||||||
libxml_use_internal_errors($internalErrors);
|
libxml_use_internal_errors($internalErrors);
|
||||||
@ -58,7 +58,7 @@ class XliffFileLoaderTest extends TestCase
|
|||||||
libxml_disable_entity_loader($disableEntities);
|
libxml_disable_entity_loader($disableEntities);
|
||||||
|
|
||||||
$this->assertEquals('en', $catalogue->getLocale());
|
$this->assertEquals('en', $catalogue->getLocale());
|
||||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadWithResname()
|
public function testLoadWithResname()
|
||||||
@ -66,7 +66,7 @@ class XliffFileLoaderTest extends TestCase
|
|||||||
$loader = new XliffFileLoader();
|
$loader = new XliffFileLoader();
|
||||||
$catalogue = $loader->load(__DIR__.'/../fixtures/resname.xlf', 'en', 'domain1');
|
$catalogue = $loader->load(__DIR__.'/../fixtures/resname.xlf', 'en', 'domain1');
|
||||||
|
|
||||||
$this->assertEquals(array('foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo', 'qux' => 'qux source'), $catalogue->all('domain1'));
|
$this->assertEquals(['foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo', 'qux' => 'qux source'], $catalogue->all('domain1'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIncompleteResource()
|
public function testIncompleteResource()
|
||||||
@ -74,7 +74,7 @@ class XliffFileLoaderTest extends TestCase
|
|||||||
$loader = new XliffFileLoader();
|
$loader = new XliffFileLoader();
|
||||||
$catalogue = $loader->load(__DIR__.'/../fixtures/resources.xlf', 'en', 'domain1');
|
$catalogue = $loader->load(__DIR__.'/../fixtures/resources.xlf', 'en', 'domain1');
|
||||||
|
|
||||||
$this->assertEquals(array('foo' => 'bar', 'extra' => 'extra', 'key' => '', 'test' => 'with'), $catalogue->all('domain1'));
|
$this->assertEquals(['foo' => 'bar', 'extra' => 'extra', 'key' => '', 'test' => 'with'], $catalogue->all('domain1'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEncoding()
|
public function testEncoding()
|
||||||
@ -85,13 +85,13 @@ class XliffFileLoaderTest extends TestCase
|
|||||||
$this->assertEquals(utf8_decode('föö'), $catalogue->get('bar', 'domain1'));
|
$this->assertEquals(utf8_decode('föö'), $catalogue->get('bar', 'domain1'));
|
||||||
$this->assertEquals(utf8_decode('bär'), $catalogue->get('foo', 'domain1'));
|
$this->assertEquals(utf8_decode('bär'), $catalogue->get('foo', 'domain1'));
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
[
|
||||||
'notes' => array(array('content' => utf8_decode('bäz'))),
|
'notes' => [['content' => utf8_decode('bäz')]],
|
||||||
'id' => '1',
|
'id' => '1',
|
||||||
'file' => array(
|
'file' => [
|
||||||
'original' => 'file.ext',
|
'original' => 'file.ext',
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
$catalogue->getMetadata('foo', 'domain1')
|
$catalogue->getMetadata('foo', 'domain1')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -174,38 +174,38 @@ class XliffFileLoaderTest extends TestCase
|
|||||||
$catalogue = $loader->load(__DIR__.'/../fixtures/withnote.xlf', 'en', 'domain1');
|
$catalogue = $loader->load(__DIR__.'/../fixtures/withnote.xlf', 'en', 'domain1');
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
[
|
||||||
'notes' => array(array('priority' => 1, 'content' => 'foo')),
|
'notes' => [['priority' => 1, 'content' => 'foo']],
|
||||||
'id' => '1',
|
'id' => '1',
|
||||||
'file' => array(
|
'file' => [
|
||||||
'original' => 'file.ext',
|
'original' => 'file.ext',
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
$catalogue->getMetadata('foo', 'domain1')
|
$catalogue->getMetadata('foo', 'domain1')
|
||||||
);
|
);
|
||||||
// message without target
|
// message without target
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
[
|
||||||
'notes' => array(array('content' => 'bar', 'from' => 'foo')),
|
'notes' => [['content' => 'bar', 'from' => 'foo']],
|
||||||
'id' => '2',
|
'id' => '2',
|
||||||
'file' => array(
|
'file' => [
|
||||||
'original' => 'file.ext',
|
'original' => 'file.ext',
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
$catalogue->getMetadata('extra', 'domain1')
|
$catalogue->getMetadata('extra', 'domain1')
|
||||||
);
|
);
|
||||||
// message with empty target
|
// message with empty target
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
[
|
||||||
'notes' => array(
|
'notes' => [
|
||||||
array('content' => 'baz'),
|
['content' => 'baz'],
|
||||||
array('priority' => 2, 'from' => 'bar', 'content' => 'qux'),
|
['priority' => 2, 'from' => 'bar', 'content' => 'qux'],
|
||||||
),
|
],
|
||||||
'id' => '123',
|
'id' => '123',
|
||||||
'file' => array(
|
'file' => [
|
||||||
'original' => 'file.ext',
|
'original' => 'file.ext',
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
$catalogue->getMetadata('key', 'domain1')
|
$catalogue->getMetadata('key', 'domain1')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -217,15 +217,15 @@ class XliffFileLoaderTest extends TestCase
|
|||||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||||
|
|
||||||
$this->assertEquals('en', $catalogue->getLocale());
|
$this->assertEquals('en', $catalogue->getLocale());
|
||||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||||
$this->assertSame(array(), libxml_get_errors());
|
$this->assertSame([], libxml_get_errors());
|
||||||
|
|
||||||
$domains = $catalogue->all();
|
$domains = $catalogue->all();
|
||||||
$this->assertCount(3, $domains['domain1']);
|
$this->assertCount(3, $domains['domain1']);
|
||||||
$this->assertContainsOnly('string', $catalogue->all('domain1'));
|
$this->assertContainsOnly('string', $catalogue->all('domain1'));
|
||||||
|
|
||||||
// target attributes
|
// target attributes
|
||||||
$this->assertEquals(array('target-attributes' => array('order' => 1)), $catalogue->getMetadata('bar', 'domain1'));
|
$this->assertEquals(['target-attributes' => ['order' => 1]], $catalogue->getMetadata('bar', 'domain1'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadVersion2WithNoteMeta()
|
public function testLoadVersion2WithNoteMeta()
|
||||||
@ -235,8 +235,8 @@ class XliffFileLoaderTest extends TestCase
|
|||||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||||
|
|
||||||
$this->assertEquals('en', $catalogue->getLocale());
|
$this->assertEquals('en', $catalogue->getLocale());
|
||||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||||
$this->assertSame(array(), libxml_get_errors());
|
$this->assertSame([], libxml_get_errors());
|
||||||
|
|
||||||
// test for "foo" metadata
|
// test for "foo" metadata
|
||||||
$this->assertTrue($catalogue->defines('foo', 'domain1'));
|
$this->assertTrue($catalogue->defines('foo', 'domain1'));
|
||||||
@ -275,7 +275,7 @@ class XliffFileLoaderTest extends TestCase
|
|||||||
$catalog = $loader->load($resource, 'en', 'domain1');
|
$catalog = $loader->load($resource, 'en', 'domain1');
|
||||||
|
|
||||||
$this->assertSame('en', $catalog->getLocale());
|
$this->assertSame('en', $catalog->getLocale());
|
||||||
$this->assertEquals(array(new FileResource($resource)), $catalog->getResources());
|
$this->assertEquals([new FileResource($resource)], $catalog->getResources());
|
||||||
$this->assertFalse(libxml_get_last_error());
|
$this->assertFalse(libxml_get_last_error());
|
||||||
|
|
||||||
// test for "foo" metadata
|
// test for "foo" metadata
|
||||||
@ -303,22 +303,22 @@ class XliffFileLoaderTest extends TestCase
|
|||||||
$catalogue = $loader->load(__DIR__.'/../fixtures/resources-multi-files.xlf', 'en', 'domain1');
|
$catalogue = $loader->load(__DIR__.'/../fixtures/resources-multi-files.xlf', 'en', 'domain1');
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
[
|
||||||
'id' => '1',
|
'id' => '1',
|
||||||
'file' => array(
|
'file' => [
|
||||||
'original' => 'file.ext',
|
'original' => 'file.ext',
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
$catalogue->getMetadata('foo', 'domain1')
|
$catalogue->getMetadata('foo', 'domain1')
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
[
|
||||||
'notes' => array(array('content' => 'note')),
|
'notes' => [['content' => 'note']],
|
||||||
'id' => '4',
|
'id' => '4',
|
||||||
'file' => array(
|
'file' => [
|
||||||
'original' => 'otherfile.ext',
|
'original' => 'otherfile.ext',
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
$catalogue->getMetadata('test', 'domain1')
|
$catalogue->getMetadata('test', 'domain1')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ use Symfony\Component\Validator\Exception\UnexpectedValueException;
|
|||||||
*/
|
*/
|
||||||
class BicValidator extends ConstraintValidator
|
class BicValidator extends ConstraintValidator
|
||||||
{
|
{
|
||||||
private const BIC_COUNTRY_TO_IBAN_COUNTRY_MAP = array(
|
private const BIC_COUNTRY_TO_IBAN_COUNTRY_MAP = [
|
||||||
// Reference: https://www.ecbs.org/iban/france-bank-account-number.html
|
// Reference: https://www.ecbs.org/iban/france-bank-account-number.html
|
||||||
'GF' => 'FR', // French Guiana
|
'GF' => 'FR', // French Guiana
|
||||||
'PF' => 'FR', // French Polynesia
|
'PF' => 'FR', // French Polynesia
|
||||||
@ -46,7 +46,7 @@ class BicValidator extends ConstraintValidator
|
|||||||
'IM' => 'GB', // Isle of Man
|
'IM' => 'GB', // Isle of Man
|
||||||
'GG' => 'GB', // Guernsey
|
'GG' => 'GB', // Guernsey
|
||||||
'VG' => 'GB', // British Virgin Islands
|
'VG' => 'GB', // British Virgin Islands
|
||||||
);
|
];
|
||||||
|
|
||||||
private $propertyAccessor;
|
private $propertyAccessor;
|
||||||
|
|
||||||
|
@ -27,66 +27,66 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
|||||||
*/
|
*/
|
||||||
class CardSchemeValidator extends ConstraintValidator
|
class CardSchemeValidator extends ConstraintValidator
|
||||||
{
|
{
|
||||||
protected $schemes = array(
|
protected $schemes = [
|
||||||
// American Express card numbers start with 34 or 37 and have 15 digits.
|
// American Express card numbers start with 34 or 37 and have 15 digits.
|
||||||
'AMEX' => array(
|
'AMEX' => [
|
||||||
'/^3[47][0-9]{13}$/',
|
'/^3[47][0-9]{13}$/',
|
||||||
),
|
],
|
||||||
// China UnionPay cards start with 62 and have between 16 and 19 digits.
|
// China UnionPay cards start with 62 and have between 16 and 19 digits.
|
||||||
// Please note that these cards do not follow Luhn Algorithm as a checksum.
|
// Please note that these cards do not follow Luhn Algorithm as a checksum.
|
||||||
'CHINA_UNIONPAY' => array(
|
'CHINA_UNIONPAY' => [
|
||||||
'/^62[0-9]{14,17}$/',
|
'/^62[0-9]{14,17}$/',
|
||||||
),
|
],
|
||||||
// Diners Club card numbers begin with 300 through 305, 36 or 38. All have 14 digits.
|
// Diners Club card numbers begin with 300 through 305, 36 or 38. All have 14 digits.
|
||||||
// There are Diners Club cards that begin with 5 and have 16 digits.
|
// There are Diners Club cards that begin with 5 and have 16 digits.
|
||||||
// These are a joint venture between Diners Club and MasterCard, and should be processed like a MasterCard.
|
// These are a joint venture between Diners Club and MasterCard, and should be processed like a MasterCard.
|
||||||
'DINERS' => array(
|
'DINERS' => [
|
||||||
'/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/',
|
'/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/',
|
||||||
),
|
],
|
||||||
// Discover card numbers begin with 6011, 622126 through 622925, 644 through 649 or 65.
|
// Discover card numbers begin with 6011, 622126 through 622925, 644 through 649 or 65.
|
||||||
// All have 16 digits.
|
// All have 16 digits.
|
||||||
'DISCOVER' => array(
|
'DISCOVER' => [
|
||||||
'/^6011[0-9]{12}$/',
|
'/^6011[0-9]{12}$/',
|
||||||
'/^64[4-9][0-9]{13}$/',
|
'/^64[4-9][0-9]{13}$/',
|
||||||
'/^65[0-9]{14}$/',
|
'/^65[0-9]{14}$/',
|
||||||
'/^622(12[6-9]|1[3-9][0-9]|[2-8][0-9][0-9]|91[0-9]|92[0-5])[0-9]{10}$/',
|
'/^622(12[6-9]|1[3-9][0-9]|[2-8][0-9][0-9]|91[0-9]|92[0-5])[0-9]{10}$/',
|
||||||
),
|
],
|
||||||
// InstaPayment cards begin with 637 through 639 and have 16 digits.
|
// InstaPayment cards begin with 637 through 639 and have 16 digits.
|
||||||
'INSTAPAYMENT' => array(
|
'INSTAPAYMENT' => [
|
||||||
'/^63[7-9][0-9]{13}$/',
|
'/^63[7-9][0-9]{13}$/',
|
||||||
),
|
],
|
||||||
// JCB cards beginning with 2131 or 1800 have 15 digits.
|
// JCB cards beginning with 2131 or 1800 have 15 digits.
|
||||||
// JCB cards beginning with 35 have 16 digits.
|
// JCB cards beginning with 35 have 16 digits.
|
||||||
'JCB' => array(
|
'JCB' => [
|
||||||
'/^(?:2131|1800|35[0-9]{3})[0-9]{11}$/',
|
'/^(?:2131|1800|35[0-9]{3})[0-9]{11}$/',
|
||||||
),
|
],
|
||||||
// Laser cards begin with either 6304, 6706, 6709 or 6771 and have between 16 and 19 digits.
|
// Laser cards begin with either 6304, 6706, 6709 or 6771 and have between 16 and 19 digits.
|
||||||
'LASER' => array(
|
'LASER' => [
|
||||||
'/^(6304|670[69]|6771)[0-9]{12,15}$/',
|
'/^(6304|670[69]|6771)[0-9]{12,15}$/',
|
||||||
),
|
],
|
||||||
// Maestro international cards begin with 675900..675999 and have between 12 and 19 digits.
|
// Maestro international cards begin with 675900..675999 and have between 12 and 19 digits.
|
||||||
// Maestro UK cards begin with either 500000..509999 or 560000..699999 and have between 12 and 19 digits.
|
// Maestro UK cards begin with either 500000..509999 or 560000..699999 and have between 12 and 19 digits.
|
||||||
'MAESTRO' => array(
|
'MAESTRO' => [
|
||||||
'/^(6759[0-9]{2})[0-9]{6,13}$/',
|
'/^(6759[0-9]{2})[0-9]{6,13}$/',
|
||||||
'/^(50[0-9]{4})[0-9]{6,13}$/',
|
'/^(50[0-9]{4})[0-9]{6,13}$/',
|
||||||
'/^5[6-9][0-9]{10,17}$/',
|
'/^5[6-9][0-9]{10,17}$/',
|
||||||
'/^6[0-9]{11,18}$/',
|
'/^6[0-9]{11,18}$/',
|
||||||
),
|
],
|
||||||
// All MasterCard numbers start with the numbers 51 through 55. All have 16 digits.
|
// All MasterCard numbers start with the numbers 51 through 55. All have 16 digits.
|
||||||
// October 2016 MasterCard numbers can also start with 222100 through 272099.
|
// October 2016 MasterCard numbers can also start with 222100 through 272099.
|
||||||
'MASTERCARD' => array(
|
'MASTERCARD' => [
|
||||||
'/^5[1-5][0-9]{14}$/',
|
'/^5[1-5][0-9]{14}$/',
|
||||||
'/^2(22[1-9][0-9]{12}|2[3-9][0-9]{13}|[3-6][0-9]{14}|7[0-1][0-9]{13}|720[0-9]{12})$/',
|
'/^2(22[1-9][0-9]{12}|2[3-9][0-9]{13}|[3-6][0-9]{14}|7[0-1][0-9]{13}|720[0-9]{12})$/',
|
||||||
),
|
],
|
||||||
// All UATP card numbers start with a 1 and have a length of 15 digits.
|
// All UATP card numbers start with a 1 and have a length of 15 digits.
|
||||||
'UATP' => array(
|
'UATP' => [
|
||||||
'/^1[0-9]{14}$/',
|
'/^1[0-9]{14}$/',
|
||||||
),
|
],
|
||||||
// All Visa card numbers start with a 4 and have a length of 13, 16, or 19 digits.
|
// All Visa card numbers start with a 4 and have a length of 13, 16, or 19 digits.
|
||||||
'VISA' => array(
|
'VISA' => [
|
||||||
'/^4([0-9]{12}|[0-9]{15}|[0-9]{18})$/',
|
'/^4([0-9]{12}|[0-9]{15}|[0-9]{18})$/',
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates a creditcard belongs to a specified scheme.
|
* Validates a creditcard belongs to a specified scheme.
|
||||||
|
@ -39,7 +39,7 @@ class BicValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
public function testValidComparisonToPropertyPath()
|
public function testValidComparisonToPropertyPath()
|
||||||
{
|
{
|
||||||
$constraint = new Bic(array('ibanPropertyPath' => 'value'));
|
$constraint = new Bic(['ibanPropertyPath' => 'value']);
|
||||||
|
|
||||||
$object = new BicComparisonTestClass('FR14 2004 1010 0505 0001 3M02 606');
|
$object = new BicComparisonTestClass('FR14 2004 1010 0505 0001 3M02 606');
|
||||||
|
|
||||||
@ -52,9 +52,9 @@ class BicValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
public function testValidComparisonToPropertyPathOnArray()
|
public function testValidComparisonToPropertyPathOnArray()
|
||||||
{
|
{
|
||||||
$constraint = new Bic(array('ibanPropertyPath' => '[root][value]'));
|
$constraint = new Bic(['ibanPropertyPath' => '[root][value]']);
|
||||||
|
|
||||||
$this->setObject(array('root' => array('value' => 'FR14 2004 1010 0505 0001 3M02 606')));
|
$this->setObject(['root' => ['value' => 'FR14 2004 1010 0505 0001 3M02 606']]);
|
||||||
|
|
||||||
$this->validator->validate('SOGEFRPP', $constraint);
|
$this->validator->validate('SOGEFRPP', $constraint);
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ class BicValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
public function testInvalidComparisonToPropertyPath()
|
public function testInvalidComparisonToPropertyPath()
|
||||||
{
|
{
|
||||||
$constraint = new Bic(array('ibanPropertyPath' => 'value'));
|
$constraint = new Bic(['ibanPropertyPath' => 'value']);
|
||||||
$constraint->ibanMessage = 'Constraint Message';
|
$constraint->ibanMessage = 'Constraint Message';
|
||||||
|
|
||||||
$object = new BicComparisonTestClass('FR14 2004 1010 0505 0001 3M02 606');
|
$object = new BicComparisonTestClass('FR14 2004 1010 0505 0001 3M02 606');
|
||||||
@ -81,7 +81,7 @@ class BicValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
public function testValidComparisonToValue()
|
public function testValidComparisonToValue()
|
||||||
{
|
{
|
||||||
$constraint = new Bic(array('iban' => 'FR14 2004 1010 0505 0001 3M02 606'));
|
$constraint = new Bic(['iban' => 'FR14 2004 1010 0505 0001 3M02 606']);
|
||||||
$constraint->ibanMessage = 'Constraint Message';
|
$constraint->ibanMessage = 'Constraint Message';
|
||||||
|
|
||||||
$this->validator->validate('SOGEFRPP', $constraint);
|
$this->validator->validate('SOGEFRPP', $constraint);
|
||||||
@ -91,7 +91,7 @@ class BicValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
public function testInvalidComparisonToValue()
|
public function testInvalidComparisonToValue()
|
||||||
{
|
{
|
||||||
$constraint = new Bic(array('iban' => 'FR14 2004 1010 0505 0001 3M02 606'));
|
$constraint = new Bic(['iban' => 'FR14 2004 1010 0505 0001 3M02 606']);
|
||||||
$constraint->ibanMessage = 'Constraint Message';
|
$constraint->ibanMessage = 'Constraint Message';
|
||||||
|
|
||||||
$this->validator->validate('UNCRIT2B912', $constraint);
|
$this->validator->validate('UNCRIT2B912', $constraint);
|
||||||
@ -105,7 +105,7 @@ class BicValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
public function testNoViolationOnNullObjectWithPropertyPath()
|
public function testNoViolationOnNullObjectWithPropertyPath()
|
||||||
{
|
{
|
||||||
$constraint = new Bic(array('ibanPropertyPath' => 'propertyPath'));
|
$constraint = new Bic(['ibanPropertyPath' => 'propertyPath']);
|
||||||
|
|
||||||
$this->setObject(null);
|
$this->setObject(null);
|
||||||
|
|
||||||
@ -120,15 +120,15 @@ class BicValidatorTest extends ConstraintValidatorTestCase
|
|||||||
*/
|
*/
|
||||||
public function testThrowsConstraintExceptionIfBothValueAndPropertyPath()
|
public function testThrowsConstraintExceptionIfBothValueAndPropertyPath()
|
||||||
{
|
{
|
||||||
new Bic(array(
|
new Bic([
|
||||||
'iban' => 'value',
|
'iban' => 'value',
|
||||||
'ibanPropertyPath' => 'propertyPath',
|
'ibanPropertyPath' => 'propertyPath',
|
||||||
));
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInvalidValuePath()
|
public function testInvalidValuePath()
|
||||||
{
|
{
|
||||||
$constraint = new Bic(array('ibanPropertyPath' => 'foo'));
|
$constraint = new Bic(['ibanPropertyPath' => 'foo']);
|
||||||
|
|
||||||
if (method_exists($this, 'expectException')) {
|
if (method_exists($this, 'expectException')) {
|
||||||
$this->expectException(ConstraintDefinitionException::class);
|
$this->expectException(ConstraintDefinitionException::class);
|
||||||
@ -230,7 +230,7 @@ class BicValidatorTest extends ConstraintValidatorTestCase
|
|||||||
*/
|
*/
|
||||||
public function testValidBicSpecialCases(string $bic, string $iban)
|
public function testValidBicSpecialCases(string $bic, string $iban)
|
||||||
{
|
{
|
||||||
$constraint = new Bic(array('iban' => $iban));
|
$constraint = new Bic(['iban' => $iban]);
|
||||||
$this->validator->validate($bic, $constraint);
|
$this->validator->validate($bic, $constraint);
|
||||||
|
|
||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
@ -239,22 +239,22 @@ class BicValidatorTest extends ConstraintValidatorTestCase
|
|||||||
public function getValidBicSpecialCases()
|
public function getValidBicSpecialCases()
|
||||||
{
|
{
|
||||||
// FR related special cases
|
// FR related special cases
|
||||||
yield array('BNPAGFGX', 'FR14 2004 1010 0505 0001 3M02 606');
|
yield ['BNPAGFGX', 'FR14 2004 1010 0505 0001 3M02 606'];
|
||||||
yield array('BNPAPFGX', 'FR14 2004 1010 0505 0001 3M02 606');
|
yield ['BNPAPFGX', 'FR14 2004 1010 0505 0001 3M02 606'];
|
||||||
yield array('BNPATFGX', 'FR14 2004 1010 0505 0001 3M02 606');
|
yield ['BNPATFGX', 'FR14 2004 1010 0505 0001 3M02 606'];
|
||||||
yield array('BNPAGPGX', 'FR14 2004 1010 0505 0001 3M02 606');
|
yield ['BNPAGPGX', 'FR14 2004 1010 0505 0001 3M02 606'];
|
||||||
yield array('BNPAMQGX', 'FR14 2004 1010 0505 0001 3M02 606');
|
yield ['BNPAMQGX', 'FR14 2004 1010 0505 0001 3M02 606'];
|
||||||
yield array('BNPAYTGX', 'FR14 2004 1010 0505 0001 3M02 606');
|
yield ['BNPAYTGX', 'FR14 2004 1010 0505 0001 3M02 606'];
|
||||||
yield array('BNPANCGX', 'FR14 2004 1010 0505 0001 3M02 606');
|
yield ['BNPANCGX', 'FR14 2004 1010 0505 0001 3M02 606'];
|
||||||
yield array('BNPAREGX', 'FR14 2004 1010 0505 0001 3M02 606');
|
yield ['BNPAREGX', 'FR14 2004 1010 0505 0001 3M02 606'];
|
||||||
yield array('BNPAPMGX', 'FR14 2004 1010 0505 0001 3M02 606');
|
yield ['BNPAPMGX', 'FR14 2004 1010 0505 0001 3M02 606'];
|
||||||
yield array('BNPAWFGX', 'FR14 2004 1010 0505 0001 3M02 606');
|
yield ['BNPAWFGX', 'FR14 2004 1010 0505 0001 3M02 606'];
|
||||||
|
|
||||||
// GB related special cases
|
// GB related special cases
|
||||||
yield array('BARCJESA', 'GB12 CPBK 0892 9965 0449 911');
|
yield ['BARCJESA', 'GB12 CPBK 0892 9965 0449 911'];
|
||||||
yield array('BARCIMSA', 'GB12 CPBK 0892 9965 0449 911');
|
yield ['BARCIMSA', 'GB12 CPBK 0892 9965 0449 911'];
|
||||||
yield array('BARCGGSA', 'GB12 CPBK 0892 9965 0449 911');
|
yield ['BARCGGSA', 'GB12 CPBK 0892 9965 0449 911'];
|
||||||
yield array('BARCVGSA', 'GB12 CPBK 0892 9965 0449 911');
|
yield ['BARCVGSA', 'GB12 CPBK 0892 9965 0449 911'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,14 +24,14 @@ class CardSchemeValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
public function testNullIsValid()
|
public function testNullIsValid()
|
||||||
{
|
{
|
||||||
$this->validator->validate(null, new CardScheme(array('schemes' => array())));
|
$this->validator->validate(null, new CardScheme(['schemes' => []]));
|
||||||
|
|
||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEmptyStringIsValid()
|
public function testEmptyStringIsValid()
|
||||||
{
|
{
|
||||||
$this->validator->validate('', new CardScheme(array('schemes' => array())));
|
$this->validator->validate('', new CardScheme(['schemes' => []]));
|
||||||
|
|
||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ class CardSchemeValidatorTest extends ConstraintValidatorTestCase
|
|||||||
*/
|
*/
|
||||||
public function testValidNumbers($scheme, $number)
|
public function testValidNumbers($scheme, $number)
|
||||||
{
|
{
|
||||||
$this->validator->validate($number, new CardScheme(array('schemes' => $scheme)));
|
$this->validator->validate($number, new CardScheme(['schemes' => $scheme]));
|
||||||
|
|
||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
@ -51,10 +51,10 @@ class CardSchemeValidatorTest extends ConstraintValidatorTestCase
|
|||||||
*/
|
*/
|
||||||
public function testInvalidNumbers($scheme, $number, $code)
|
public function testInvalidNumbers($scheme, $number, $code)
|
||||||
{
|
{
|
||||||
$constraint = new CardScheme(array(
|
$constraint = new CardScheme([
|
||||||
'schemes' => $scheme,
|
'schemes' => $scheme,
|
||||||
'message' => 'myMessage',
|
'message' => 'myMessage',
|
||||||
));
|
]);
|
||||||
|
|
||||||
$this->validator->validate($number, $constraint);
|
$this->validator->validate($number, $constraint);
|
||||||
|
|
||||||
@ -66,75 +66,75 @@ class CardSchemeValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
public function getValidNumbers()
|
public function getValidNumbers()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array('AMEX', '378282246310005'),
|
['AMEX', '378282246310005'],
|
||||||
array('AMEX', '371449635398431'),
|
['AMEX', '371449635398431'],
|
||||||
array('AMEX', '378734493671000'),
|
['AMEX', '378734493671000'],
|
||||||
array('AMEX', '347298508610146'),
|
['AMEX', '347298508610146'],
|
||||||
array('CHINA_UNIONPAY', '6228888888888888'),
|
['CHINA_UNIONPAY', '6228888888888888'],
|
||||||
array('CHINA_UNIONPAY', '62288888888888888'),
|
['CHINA_UNIONPAY', '62288888888888888'],
|
||||||
array('CHINA_UNIONPAY', '622888888888888888'),
|
['CHINA_UNIONPAY', '622888888888888888'],
|
||||||
array('CHINA_UNIONPAY', '6228888888888888888'),
|
['CHINA_UNIONPAY', '6228888888888888888'],
|
||||||
array('DINERS', '30569309025904'),
|
['DINERS', '30569309025904'],
|
||||||
array('DINERS', '36088894118515'),
|
['DINERS', '36088894118515'],
|
||||||
array('DINERS', '38520000023237'),
|
['DINERS', '38520000023237'],
|
||||||
array('DISCOVER', '6011111111111117'),
|
['DISCOVER', '6011111111111117'],
|
||||||
array('DISCOVER', '6011000990139424'),
|
['DISCOVER', '6011000990139424'],
|
||||||
array('INSTAPAYMENT', '6372476031350068'),
|
['INSTAPAYMENT', '6372476031350068'],
|
||||||
array('INSTAPAYMENT', '6385537775789749'),
|
['INSTAPAYMENT', '6385537775789749'],
|
||||||
array('INSTAPAYMENT', '6393440808445746'),
|
['INSTAPAYMENT', '6393440808445746'],
|
||||||
array('JCB', '3530111333300000'),
|
['JCB', '3530111333300000'],
|
||||||
array('JCB', '3566002020360505'),
|
['JCB', '3566002020360505'],
|
||||||
array('JCB', '213112345678901'),
|
['JCB', '213112345678901'],
|
||||||
array('JCB', '180012345678901'),
|
['JCB', '180012345678901'],
|
||||||
array('LASER', '6304678107004080'),
|
['LASER', '6304678107004080'],
|
||||||
array('LASER', '6706440607428128629'),
|
['LASER', '6706440607428128629'],
|
||||||
array('LASER', '6771656738314582216'),
|
['LASER', '6771656738314582216'],
|
||||||
array('MAESTRO', '6759744069209'),
|
['MAESTRO', '6759744069209'],
|
||||||
array('MAESTRO', '5020507657408074712'),
|
['MAESTRO', '5020507657408074712'],
|
||||||
array('MAESTRO', '5612559223580173965'),
|
['MAESTRO', '5612559223580173965'],
|
||||||
array('MAESTRO', '6759744069209'),
|
['MAESTRO', '6759744069209'],
|
||||||
array('MAESTRO', '6594371785970435599'),
|
['MAESTRO', '6594371785970435599'],
|
||||||
array('MASTERCARD', '5555555555554444'),
|
['MASTERCARD', '5555555555554444'],
|
||||||
array('MASTERCARD', '5105105105105100'),
|
['MASTERCARD', '5105105105105100'],
|
||||||
array('MASTERCARD', '2221005555554444'),
|
['MASTERCARD', '2221005555554444'],
|
||||||
array('MASTERCARD', '2230000000000000'),
|
['MASTERCARD', '2230000000000000'],
|
||||||
array('MASTERCARD', '2300000000000000'),
|
['MASTERCARD', '2300000000000000'],
|
||||||
array('MASTERCARD', '2699999999999999'),
|
['MASTERCARD', '2699999999999999'],
|
||||||
array('MASTERCARD', '2709999999999999'),
|
['MASTERCARD', '2709999999999999'],
|
||||||
array('MASTERCARD', '2720995105105100'),
|
['MASTERCARD', '2720995105105100'],
|
||||||
array('UATP', '110165309696173'),
|
['UATP', '110165309696173'],
|
||||||
array('VISA', '4111111111111111'),
|
['VISA', '4111111111111111'],
|
||||||
array('VISA', '4012888888881881'),
|
['VISA', '4012888888881881'],
|
||||||
array('VISA', '4222222222222'),
|
['VISA', '4222222222222'],
|
||||||
array('VISA', '4917610000000000003'),
|
['VISA', '4917610000000000003'],
|
||||||
array(array('AMEX', 'VISA'), '4111111111111111'),
|
[['AMEX', 'VISA'], '4111111111111111'],
|
||||||
array(array('AMEX', 'VISA'), '378282246310005'),
|
[['AMEX', 'VISA'], '378282246310005'],
|
||||||
array(array('JCB', 'MASTERCARD'), '5105105105105100'),
|
[['JCB', 'MASTERCARD'], '5105105105105100'],
|
||||||
array(array('VISA', 'MASTERCARD'), '5105105105105100'),
|
[['VISA', 'MASTERCARD'], '5105105105105100'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInvalidNumbers()
|
public function getInvalidNumbers()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array('VISA', '42424242424242424242', CardScheme::INVALID_FORMAT_ERROR),
|
['VISA', '42424242424242424242', CardScheme::INVALID_FORMAT_ERROR],
|
||||||
array('AMEX', '357298508610146', CardScheme::INVALID_FORMAT_ERROR),
|
['AMEX', '357298508610146', CardScheme::INVALID_FORMAT_ERROR],
|
||||||
array('DINERS', '31569309025904', CardScheme::INVALID_FORMAT_ERROR),
|
['DINERS', '31569309025904', CardScheme::INVALID_FORMAT_ERROR],
|
||||||
array('DINERS', '37088894118515', CardScheme::INVALID_FORMAT_ERROR),
|
['DINERS', '37088894118515', CardScheme::INVALID_FORMAT_ERROR],
|
||||||
array('INSTAPAYMENT', '6313440808445746', CardScheme::INVALID_FORMAT_ERROR),
|
['INSTAPAYMENT', '6313440808445746', CardScheme::INVALID_FORMAT_ERROR],
|
||||||
array('CHINA_UNIONPAY', '622888888888888', CardScheme::INVALID_FORMAT_ERROR),
|
['CHINA_UNIONPAY', '622888888888888', CardScheme::INVALID_FORMAT_ERROR],
|
||||||
array('CHINA_UNIONPAY', '62288888888888888888', CardScheme::INVALID_FORMAT_ERROR),
|
['CHINA_UNIONPAY', '62288888888888888888', CardScheme::INVALID_FORMAT_ERROR],
|
||||||
array('AMEX', '30569309025904', CardScheme::INVALID_FORMAT_ERROR), // DINERS number
|
['AMEX', '30569309025904', CardScheme::INVALID_FORMAT_ERROR], // DINERS number
|
||||||
array('AMEX', 'invalid', CardScheme::NOT_NUMERIC_ERROR), // A string
|
['AMEX', 'invalid', CardScheme::NOT_NUMERIC_ERROR], // A string
|
||||||
array('AMEX', 0, CardScheme::INVALID_FORMAT_ERROR), // a lone number
|
['AMEX', 0, CardScheme::INVALID_FORMAT_ERROR], // a lone number
|
||||||
array('AMEX', '0', CardScheme::INVALID_FORMAT_ERROR), // a lone number
|
['AMEX', '0', CardScheme::INVALID_FORMAT_ERROR], // a lone number
|
||||||
array('AMEX', '000000000000', CardScheme::INVALID_FORMAT_ERROR), // a lone number
|
['AMEX', '000000000000', CardScheme::INVALID_FORMAT_ERROR], // a lone number
|
||||||
array('DINERS', '3056930', CardScheme::INVALID_FORMAT_ERROR), // only first part of the number
|
['DINERS', '3056930', CardScheme::INVALID_FORMAT_ERROR], // only first part of the number
|
||||||
array('DISCOVER', '1117', CardScheme::INVALID_FORMAT_ERROR), // only last 4 digits
|
['DISCOVER', '1117', CardScheme::INVALID_FORMAT_ERROR], // only last 4 digits
|
||||||
array('MASTERCARD', '2721001234567890', CardScheme::INVALID_FORMAT_ERROR), // Not assigned yet
|
['MASTERCARD', '2721001234567890', CardScheme::INVALID_FORMAT_ERROR], // Not assigned yet
|
||||||
array('MASTERCARD', '2220991234567890', CardScheme::INVALID_FORMAT_ERROR), // Not assigned yet
|
['MASTERCARD', '2220991234567890', CardScheme::INVALID_FORMAT_ERROR], // Not assigned yet
|
||||||
array('UATP', '11016530969617', CardScheme::INVALID_FORMAT_ERROR), // invalid length
|
['UATP', '11016530969617', CardScheme::INVALID_FORMAT_ERROR], // invalid length
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,14 +24,14 @@ class RegexValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
public function testNullIsValid()
|
public function testNullIsValid()
|
||||||
{
|
{
|
||||||
$this->validator->validate(null, new Regex(array('pattern' => '/^[0-9]+$/')));
|
$this->validator->validate(null, new Regex(['pattern' => '/^[0-9]+$/']));
|
||||||
|
|
||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEmptyStringIsValid()
|
public function testEmptyStringIsValid()
|
||||||
{
|
{
|
||||||
$this->validator->validate('', new Regex(array('pattern' => '/^[0-9]+$/')));
|
$this->validator->validate('', new Regex(['pattern' => '/^[0-9]+$/']));
|
||||||
|
|
||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ class RegexValidatorTest extends ConstraintValidatorTestCase
|
|||||||
*/
|
*/
|
||||||
public function testExpectsStringCompatibleType()
|
public function testExpectsStringCompatibleType()
|
||||||
{
|
{
|
||||||
$this->validator->validate(new \stdClass(), new Regex(array('pattern' => '/^[0-9]+$/')));
|
$this->validator->validate(new \stdClass(), new Regex(['pattern' => '/^[0-9]+$/']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,7 +49,7 @@ class RegexValidatorTest extends ConstraintValidatorTestCase
|
|||||||
*/
|
*/
|
||||||
public function testValidValues($value)
|
public function testValidValues($value)
|
||||||
{
|
{
|
||||||
$constraint = new Regex(array('pattern' => '/^[0-9]+$/'));
|
$constraint = new Regex(['pattern' => '/^[0-9]+$/']);
|
||||||
$this->validator->validate($value, $constraint);
|
$this->validator->validate($value, $constraint);
|
||||||
|
|
||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
@ -57,18 +57,18 @@ class RegexValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
public function getValidValues()
|
public function getValidValues()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array(0),
|
[0],
|
||||||
array('0'),
|
['0'],
|
||||||
array('090909'),
|
['090909'],
|
||||||
array(90909),
|
[90909],
|
||||||
array(new class() {
|
[new class() {
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
return '090909';
|
return '090909';
|
||||||
}
|
}
|
||||||
}),
|
}],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,10 +76,10 @@ class RegexValidatorTest extends ConstraintValidatorTestCase
|
|||||||
*/
|
*/
|
||||||
public function testInvalidValues($value)
|
public function testInvalidValues($value)
|
||||||
{
|
{
|
||||||
$constraint = new Regex(array(
|
$constraint = new Regex([
|
||||||
'pattern' => '/^[0-9]+$/',
|
'pattern' => '/^[0-9]+$/',
|
||||||
'message' => 'myMessage',
|
'message' => 'myMessage',
|
||||||
));
|
]);
|
||||||
|
|
||||||
$this->validator->validate($value, $constraint);
|
$this->validator->validate($value, $constraint);
|
||||||
|
|
||||||
@ -91,15 +91,15 @@ class RegexValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
public function getInvalidValues()
|
public function getInvalidValues()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array('abcd'),
|
['abcd'],
|
||||||
array('090foo'),
|
['090foo'],
|
||||||
array(new class() {
|
[new class() {
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
return 'abcd';
|
return 'abcd';
|
||||||
}
|
}
|
||||||
}),
|
}],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,17 +81,17 @@ class ResourceCaster
|
|||||||
$pin = base64_decode(implode('', $pin));
|
$pin = base64_decode(implode('', $pin));
|
||||||
$pin = base64_encode(hash('sha256', $pin, true));
|
$pin = base64_encode(hash('sha256', $pin, true));
|
||||||
|
|
||||||
$a += array(
|
$a += [
|
||||||
'subject' => new EnumStub(array_intersect_key($info['subject'], array('organizationName' => true, 'commonName' => true))),
|
'subject' => new EnumStub(array_intersect_key($info['subject'], ['organizationName' => true, 'commonName' => true])),
|
||||||
'issuer' => new EnumStub(array_intersect_key($info['issuer'], array('organizationName' => true, 'commonName' => true))),
|
'issuer' => new EnumStub(array_intersect_key($info['issuer'], ['organizationName' => true, 'commonName' => true])),
|
||||||
'expiry' => new ConstStub(date(\DateTime::ISO8601, $info['validTo_time_t']), $info['validTo_time_t']),
|
'expiry' => new ConstStub(date(\DateTime::ISO8601, $info['validTo_time_t']), $info['validTo_time_t']),
|
||||||
'fingerprint' => new EnumStub(array(
|
'fingerprint' => new EnumStub([
|
||||||
'md5' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'md5')), 2, ':', true)),
|
'md5' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'md5')), 2, ':', true)),
|
||||||
'sha1' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha1')), 2, ':', true)),
|
'sha1' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha1')), 2, ':', true)),
|
||||||
'sha256' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha256')), 2, ':', true)),
|
'sha256' => new ConstStub(wordwrap(strtoupper(openssl_x509_fingerprint($h, 'sha256')), 2, ':', true)),
|
||||||
'pin-sha256' => new ConstStub($pin),
|
'pin-sha256' => new ConstStub($pin),
|
||||||
)),
|
]),
|
||||||
);
|
];
|
||||||
|
|
||||||
return $a;
|
return $a;
|
||||||
}
|
}
|
||||||
|
@ -21,134 +21,134 @@ use Symfony\Component\VarDumper\Exception\ThrowingCasterException;
|
|||||||
*/
|
*/
|
||||||
abstract class AbstractCloner implements ClonerInterface
|
abstract class AbstractCloner implements ClonerInterface
|
||||||
{
|
{
|
||||||
public static $defaultCasters = array(
|
public static $defaultCasters = [
|
||||||
'__PHP_Incomplete_Class' => array('Symfony\Component\VarDumper\Caster\Caster', 'castPhpIncompleteClass'),
|
'__PHP_Incomplete_Class' => ['Symfony\Component\VarDumper\Caster\Caster', 'castPhpIncompleteClass'],
|
||||||
|
|
||||||
'Symfony\Component\VarDumper\Caster\CutStub' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'castStub'),
|
'Symfony\Component\VarDumper\Caster\CutStub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'castStub'],
|
||||||
'Symfony\Component\VarDumper\Caster\CutArrayStub' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'castCutArray'),
|
'Symfony\Component\VarDumper\Caster\CutArrayStub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'castCutArray'],
|
||||||
'Symfony\Component\VarDumper\Caster\ConstStub' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'castStub'),
|
'Symfony\Component\VarDumper\Caster\ConstStub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'castStub'],
|
||||||
'Symfony\Component\VarDumper\Caster\EnumStub' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'castEnum'),
|
'Symfony\Component\VarDumper\Caster\EnumStub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'castEnum'],
|
||||||
|
|
||||||
'Closure' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castClosure'),
|
'Closure' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castClosure'],
|
||||||
'Generator' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castGenerator'),
|
'Generator' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castGenerator'],
|
||||||
'ReflectionType' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castType'),
|
'ReflectionType' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castType'],
|
||||||
'ReflectionGenerator' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castReflectionGenerator'),
|
'ReflectionGenerator' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castReflectionGenerator'],
|
||||||
'ReflectionClass' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castClass'),
|
'ReflectionClass' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castClass'],
|
||||||
'ReflectionFunctionAbstract' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castFunctionAbstract'),
|
'ReflectionFunctionAbstract' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castFunctionAbstract'],
|
||||||
'ReflectionMethod' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castMethod'),
|
'ReflectionMethod' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castMethod'],
|
||||||
'ReflectionParameter' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castParameter'),
|
'ReflectionParameter' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castParameter'],
|
||||||
'ReflectionProperty' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castProperty'),
|
'ReflectionProperty' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castProperty'],
|
||||||
'ReflectionExtension' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castExtension'),
|
'ReflectionExtension' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castExtension'],
|
||||||
'ReflectionZendExtension' => array('Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castZendExtension'),
|
'ReflectionZendExtension' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castZendExtension'],
|
||||||
|
|
||||||
'Doctrine\Common\Persistence\ObjectManager' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'),
|
'Doctrine\Common\Persistence\ObjectManager' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
|
||||||
'Doctrine\Common\Proxy\Proxy' => array('Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castCommonProxy'),
|
'Doctrine\Common\Proxy\Proxy' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castCommonProxy'],
|
||||||
'Doctrine\ORM\Proxy\Proxy' => array('Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castOrmProxy'),
|
'Doctrine\ORM\Proxy\Proxy' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castOrmProxy'],
|
||||||
'Doctrine\ORM\PersistentCollection' => array('Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castPersistentCollection'),
|
'Doctrine\ORM\PersistentCollection' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castPersistentCollection'],
|
||||||
|
|
||||||
'DOMException' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castException'),
|
'DOMException' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castException'],
|
||||||
'DOMStringList' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'),
|
'DOMStringList' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'],
|
||||||
'DOMNameList' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'),
|
'DOMNameList' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'],
|
||||||
'DOMImplementation' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castImplementation'),
|
'DOMImplementation' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castImplementation'],
|
||||||
'DOMImplementationList' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'),
|
'DOMImplementationList' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'],
|
||||||
'DOMNode' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castNode'),
|
'DOMNode' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castNode'],
|
||||||
'DOMNameSpaceNode' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castNameSpaceNode'),
|
'DOMNameSpaceNode' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castNameSpaceNode'],
|
||||||
'DOMDocument' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castDocument'),
|
'DOMDocument' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castDocument'],
|
||||||
'DOMNodeList' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'),
|
'DOMNodeList' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'],
|
||||||
'DOMNamedNodeMap' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'),
|
'DOMNamedNodeMap' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'],
|
||||||
'DOMCharacterData' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castCharacterData'),
|
'DOMCharacterData' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castCharacterData'],
|
||||||
'DOMAttr' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castAttr'),
|
'DOMAttr' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castAttr'],
|
||||||
'DOMElement' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castElement'),
|
'DOMElement' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castElement'],
|
||||||
'DOMText' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castText'),
|
'DOMText' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castText'],
|
||||||
'DOMTypeinfo' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castTypeinfo'),
|
'DOMTypeinfo' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castTypeinfo'],
|
||||||
'DOMDomError' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castDomError'),
|
'DOMDomError' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castDomError'],
|
||||||
'DOMLocator' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castLocator'),
|
'DOMLocator' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLocator'],
|
||||||
'DOMDocumentType' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castDocumentType'),
|
'DOMDocumentType' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castDocumentType'],
|
||||||
'DOMNotation' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castNotation'),
|
'DOMNotation' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castNotation'],
|
||||||
'DOMEntity' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castEntity'),
|
'DOMEntity' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castEntity'],
|
||||||
'DOMProcessingInstruction' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castProcessingInstruction'),
|
'DOMProcessingInstruction' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castProcessingInstruction'],
|
||||||
'DOMXPath' => array('Symfony\Component\VarDumper\Caster\DOMCaster', 'castXPath'),
|
'DOMXPath' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castXPath'],
|
||||||
|
|
||||||
'XmlReader' => array('Symfony\Component\VarDumper\Caster\XmlReaderCaster', 'castXmlReader'),
|
'XmlReader' => ['Symfony\Component\VarDumper\Caster\XmlReaderCaster', 'castXmlReader'],
|
||||||
|
|
||||||
'ErrorException' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castErrorException'),
|
'ErrorException' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castErrorException'],
|
||||||
'Exception' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castException'),
|
'Exception' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castException'],
|
||||||
'Error' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castError'),
|
'Error' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castError'],
|
||||||
'Symfony\Component\DependencyInjection\ContainerInterface' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'),
|
'Symfony\Component\DependencyInjection\ContainerInterface' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
|
||||||
'Symfony\Component\HttpFoundation\Request' => array('Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castRequest'),
|
'Symfony\Component\HttpFoundation\Request' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castRequest'],
|
||||||
'Symfony\Component\VarDumper\Exception\ThrowingCasterException' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castThrowingCasterException'),
|
'Symfony\Component\VarDumper\Exception\ThrowingCasterException' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castThrowingCasterException'],
|
||||||
'Symfony\Component\VarDumper\Caster\TraceStub' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castTraceStub'),
|
'Symfony\Component\VarDumper\Caster\TraceStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castTraceStub'],
|
||||||
'Symfony\Component\VarDumper\Caster\FrameStub' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castFrameStub'),
|
'Symfony\Component\VarDumper\Caster\FrameStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castFrameStub'],
|
||||||
'Symfony\Component\Debug\Exception\SilencedErrorContext' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castSilencedErrorContext'),
|
'Symfony\Component\Debug\Exception\SilencedErrorContext' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castSilencedErrorContext'],
|
||||||
|
|
||||||
'ProxyManager\Proxy\ProxyInterface' => array('Symfony\Component\VarDumper\Caster\ProxyManagerCaster', 'castProxy'),
|
'ProxyManager\Proxy\ProxyInterface' => ['Symfony\Component\VarDumper\Caster\ProxyManagerCaster', 'castProxy'],
|
||||||
'PHPUnit_Framework_MockObject_MockObject' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'),
|
'PHPUnit_Framework_MockObject_MockObject' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
|
||||||
'Prophecy\Prophecy\ProphecySubjectInterface' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'),
|
'Prophecy\Prophecy\ProphecySubjectInterface' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
|
||||||
'Mockery\MockInterface' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'),
|
'Mockery\MockInterface' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
|
||||||
|
|
||||||
'PDO' => array('Symfony\Component\VarDumper\Caster\PdoCaster', 'castPdo'),
|
'PDO' => ['Symfony\Component\VarDumper\Caster\PdoCaster', 'castPdo'],
|
||||||
'PDOStatement' => array('Symfony\Component\VarDumper\Caster\PdoCaster', 'castPdoStatement'),
|
'PDOStatement' => ['Symfony\Component\VarDumper\Caster\PdoCaster', 'castPdoStatement'],
|
||||||
|
|
||||||
'AMQPConnection' => array('Symfony\Component\VarDumper\Caster\AmqpCaster', 'castConnection'),
|
'AMQPConnection' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castConnection'],
|
||||||
'AMQPChannel' => array('Symfony\Component\VarDumper\Caster\AmqpCaster', 'castChannel'),
|
'AMQPChannel' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castChannel'],
|
||||||
'AMQPQueue' => array('Symfony\Component\VarDumper\Caster\AmqpCaster', 'castQueue'),
|
'AMQPQueue' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castQueue'],
|
||||||
'AMQPExchange' => array('Symfony\Component\VarDumper\Caster\AmqpCaster', 'castExchange'),
|
'AMQPExchange' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castExchange'],
|
||||||
'AMQPEnvelope' => array('Symfony\Component\VarDumper\Caster\AmqpCaster', 'castEnvelope'),
|
'AMQPEnvelope' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castEnvelope'],
|
||||||
|
|
||||||
'ArrayObject' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castArrayObject'),
|
'ArrayObject' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castArrayObject'],
|
||||||
'ArrayIterator' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castArrayIterator'),
|
'ArrayIterator' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castArrayIterator'],
|
||||||
'SplDoublyLinkedList' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castDoublyLinkedList'),
|
'SplDoublyLinkedList' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castDoublyLinkedList'],
|
||||||
'SplFileInfo' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castFileInfo'),
|
'SplFileInfo' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castFileInfo'],
|
||||||
'SplFileObject' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castFileObject'),
|
'SplFileObject' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castFileObject'],
|
||||||
'SplFixedArray' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castFixedArray'),
|
'SplFixedArray' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castFixedArray'],
|
||||||
'SplHeap' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'),
|
'SplHeap' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'],
|
||||||
'SplObjectStorage' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castObjectStorage'),
|
'SplObjectStorage' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castObjectStorage'],
|
||||||
'SplPriorityQueue' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'),
|
'SplPriorityQueue' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'],
|
||||||
'OuterIterator' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castOuterIterator'),
|
'OuterIterator' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castOuterIterator'],
|
||||||
|
|
||||||
'Redis' => array('Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedis'),
|
'Redis' => ['Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedis'],
|
||||||
'RedisArray' => array('Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedisArray'),
|
'RedisArray' => ['Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedisArray'],
|
||||||
'RedisCluster' => array('Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedisCluster'),
|
'RedisCluster' => ['Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedisCluster'],
|
||||||
|
|
||||||
'DateTimeInterface' => array('Symfony\Component\VarDumper\Caster\DateCaster', 'castDateTime'),
|
'DateTimeInterface' => ['Symfony\Component\VarDumper\Caster\DateCaster', 'castDateTime'],
|
||||||
'DateInterval' => array('Symfony\Component\VarDumper\Caster\DateCaster', 'castInterval'),
|
'DateInterval' => ['Symfony\Component\VarDumper\Caster\DateCaster', 'castInterval'],
|
||||||
'DateTimeZone' => array('Symfony\Component\VarDumper\Caster\DateCaster', 'castTimeZone'),
|
'DateTimeZone' => ['Symfony\Component\VarDumper\Caster\DateCaster', 'castTimeZone'],
|
||||||
'DatePeriod' => array('Symfony\Component\VarDumper\Caster\DateCaster', 'castPeriod'),
|
'DatePeriod' => ['Symfony\Component\VarDumper\Caster\DateCaster', 'castPeriod'],
|
||||||
|
|
||||||
'GMP' => array('Symfony\Component\VarDumper\Caster\GmpCaster', 'castGmp'),
|
'GMP' => ['Symfony\Component\VarDumper\Caster\GmpCaster', 'castGmp'],
|
||||||
|
|
||||||
'MessageFormatter' => array('Symfony\Component\VarDumper\Caster\IntlCaster', 'castMessageFormatter'),
|
'MessageFormatter' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castMessageFormatter'],
|
||||||
'NumberFormatter' => array('Symfony\Component\VarDumper\Caster\IntlCaster', 'castNumberFormatter'),
|
'NumberFormatter' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castNumberFormatter'],
|
||||||
'IntlTimeZone' => array('Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlTimeZone'),
|
'IntlTimeZone' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlTimeZone'],
|
||||||
'IntlCalendar' => array('Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlCalendar'),
|
'IntlCalendar' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlCalendar'],
|
||||||
'IntlDateFormatter' => array('Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlDateFormatter'),
|
'IntlDateFormatter' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlDateFormatter'],
|
||||||
|
|
||||||
'Memcached' => array('Symfony\Component\VarDumper\Caster\MemcachedCaster', 'castMemcached'),
|
'Memcached' => ['Symfony\Component\VarDumper\Caster\MemcachedCaster', 'castMemcached'],
|
||||||
|
|
||||||
':curl' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'),
|
':curl' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'],
|
||||||
':dba' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'),
|
':dba' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'],
|
||||||
':dba persistent' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'),
|
':dba persistent' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'],
|
||||||
':gd' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castGd'),
|
':gd' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castGd'],
|
||||||
':mysql link' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castMysqlLink'),
|
':mysql link' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castMysqlLink'],
|
||||||
':pgsql large object' => array('Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLargeObject'),
|
':pgsql large object' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLargeObject'],
|
||||||
':pgsql link' => array('Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLink'),
|
':pgsql link' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLink'],
|
||||||
':pgsql link persistent' => array('Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLink'),
|
':pgsql link persistent' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLink'],
|
||||||
':pgsql result' => array('Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castResult'),
|
':pgsql result' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castResult'],
|
||||||
':process' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castProcess'),
|
':process' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castProcess'],
|
||||||
':stream' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'),
|
':stream' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'],
|
||||||
':OpenSSL X.509' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castOpensslX509'),
|
':OpenSSL X.509' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castOpensslX509'],
|
||||||
':persistent stream' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'),
|
':persistent stream' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'],
|
||||||
':stream-context' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStreamContext'),
|
':stream-context' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStreamContext'],
|
||||||
':xml' => array('Symfony\Component\VarDumper\Caster\XmlResourceCaster', 'castXml'),
|
':xml' => ['Symfony\Component\VarDumper\Caster\XmlResourceCaster', 'castXml'],
|
||||||
);
|
];
|
||||||
|
|
||||||
protected $maxItems = 2500;
|
protected $maxItems = 2500;
|
||||||
protected $maxString = -1;
|
protected $maxString = -1;
|
||||||
protected $minDepth = 1;
|
protected $minDepth = 1;
|
||||||
|
|
||||||
private $casters = array();
|
private $casters = [];
|
||||||
private $prevErrorHandler;
|
private $prevErrorHandler;
|
||||||
private $classInfo = array();
|
private $classInfo = [];
|
||||||
private $filter = 0;
|
private $filter = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -225,7 +225,7 @@ abstract class AbstractCloner implements ClonerInterface
|
|||||||
*/
|
*/
|
||||||
public function cloneVar($var, $filter = 0)
|
public function cloneVar($var, $filter = 0)
|
||||||
{
|
{
|
||||||
$this->prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = array()) {
|
$this->prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) {
|
||||||
if (E_RECOVERABLE_ERROR === $type || E_USER_ERROR === $type) {
|
if (E_RECOVERABLE_ERROR === $type || E_USER_ERROR === $type) {
|
||||||
// Cloner never dies
|
// Cloner never dies
|
||||||
throw new \ErrorException($msg, 0, $type, $file, $line);
|
throw new \ErrorException($msg, 0, $type, $file, $line);
|
||||||
@ -282,7 +282,7 @@ abstract class AbstractCloner implements ClonerInterface
|
|||||||
list($i, $parents, $hasDebugInfo) = $this->classInfo[$class];
|
list($i, $parents, $hasDebugInfo) = $this->classInfo[$class];
|
||||||
} else {
|
} else {
|
||||||
$i = 2;
|
$i = 2;
|
||||||
$parents = array(strtolower($class));
|
$parents = [strtolower($class)];
|
||||||
$hasDebugInfo = method_exists($class, '__debugInfo');
|
$hasDebugInfo = method_exists($class, '__debugInfo');
|
||||||
|
|
||||||
foreach (class_parents($class) as $p) {
|
foreach (class_parents($class) as $p) {
|
||||||
@ -295,7 +295,7 @@ abstract class AbstractCloner implements ClonerInterface
|
|||||||
}
|
}
|
||||||
$parents[] = '*';
|
$parents[] = '*';
|
||||||
|
|
||||||
$this->classInfo[$class] = array($i, $parents, $hasDebugInfo);
|
$this->classInfo[$class] = [$i, $parents, $hasDebugInfo];
|
||||||
}
|
}
|
||||||
|
|
||||||
$a = Caster::castObject($obj, $class, $hasDebugInfo);
|
$a = Caster::castObject($obj, $class, $hasDebugInfo);
|
||||||
@ -309,7 +309,7 @@ abstract class AbstractCloner implements ClonerInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$a = array((Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').'⚠' => new ThrowingCasterException($e)) + $a;
|
$a = [(Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').'⚠' => new ThrowingCasterException($e)] + $a;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $a;
|
return $a;
|
||||||
@ -325,7 +325,7 @@ abstract class AbstractCloner implements ClonerInterface
|
|||||||
*/
|
*/
|
||||||
protected function castResource(Stub $stub, $isNested)
|
protected function castResource(Stub $stub, $isNested)
|
||||||
{
|
{
|
||||||
$a = array();
|
$a = [];
|
||||||
$res = $stub->value;
|
$res = $stub->value;
|
||||||
$type = $stub->class;
|
$type = $stub->class;
|
||||||
|
|
||||||
@ -336,7 +336,7 @@ abstract class AbstractCloner implements ClonerInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$a = array((Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').'⚠' => new ThrowingCasterException($e)) + $a;
|
$a = [(Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').'⚠' => new ThrowingCasterException($e)] + $a;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $a;
|
return $a;
|
||||||
|
@ -39,10 +39,10 @@ class CliDescriptor implements DumpDescriptorInterface
|
|||||||
|
|
||||||
public function describe(OutputInterface $output, Data $data, array $context, int $clientId): void
|
public function describe(OutputInterface $output, Data $data, array $context, int $clientId): void
|
||||||
{
|
{
|
||||||
$io = $output instanceof SymfonyStyle ? $output : new SymfonyStyle(new ArrayInput(array()), $output);
|
$io = $output instanceof SymfonyStyle ? $output : new SymfonyStyle(new ArrayInput([]), $output);
|
||||||
$this->dumper->setColors($output->isDecorated());
|
$this->dumper->setColors($output->isDecorated());
|
||||||
|
|
||||||
$rows = array(array('date', date('r', $context['timestamp'])));
|
$rows = [['date', date('r', $context['timestamp'])]];
|
||||||
$lastIdentifier = $this->lastIdentifier;
|
$lastIdentifier = $this->lastIdentifier;
|
||||||
$this->lastIdentifier = $clientId;
|
$this->lastIdentifier = $clientId;
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ class CliDescriptor implements DumpDescriptorInterface
|
|||||||
$this->lastIdentifier = $request['identifier'];
|
$this->lastIdentifier = $request['identifier'];
|
||||||
$section = sprintf('%s %s', $request['method'], $request['uri']);
|
$section = sprintf('%s %s', $request['method'], $request['uri']);
|
||||||
if ($controller = $request['controller']) {
|
if ($controller = $request['controller']) {
|
||||||
$rows[] = array('controller', rtrim($this->dumper->dump($controller, true), "\n"));
|
$rows[] = ['controller', rtrim($this->dumper->dump($controller, true), "\n")];
|
||||||
}
|
}
|
||||||
} elseif (isset($context['cli'])) {
|
} elseif (isset($context['cli'])) {
|
||||||
$this->lastIdentifier = $context['cli']['identifier'];
|
$this->lastIdentifier = $context['cli']['identifier'];
|
||||||
@ -70,15 +70,15 @@ class CliDescriptor implements DumpDescriptorInterface
|
|||||||
if ($this->supportsHref && $fileLink) {
|
if ($this->supportsHref && $fileLink) {
|
||||||
$sourceInfo = sprintf('<href=%s>%s</>', $fileLink, $sourceInfo);
|
$sourceInfo = sprintf('<href=%s>%s</>', $fileLink, $sourceInfo);
|
||||||
}
|
}
|
||||||
$rows[] = array('source', $sourceInfo);
|
$rows[] = ['source', $sourceInfo];
|
||||||
$file = $source['file_relative'] ?? $source['file'];
|
$file = $source['file_relative'] ?? $source['file'];
|
||||||
$rows[] = array('file', $file);
|
$rows[] = ['file', $file];
|
||||||
}
|
}
|
||||||
|
|
||||||
$io->table(array(), $rows);
|
$io->table([], $rows);
|
||||||
|
|
||||||
if (!$this->supportsHref && isset($fileLink)) {
|
if (!$this->supportsHref && isset($fileLink)) {
|
||||||
$io->writeln(array('<info>Open source in your IDE/browser:</info>', $fileLink));
|
$io->writeln(['<info>Open source in your IDE/browser:</info>', $fileLink]);
|
||||||
$io->newLine();
|
$io->newLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,9 +55,9 @@ class CliDumper extends AbstractDumper
|
|||||||
protected $collapseNextHash = false;
|
protected $collapseNextHash = false;
|
||||||
protected $expandNextHash = false;
|
protected $expandNextHash = false;
|
||||||
|
|
||||||
private $displayOptions = array(
|
private $displayOptions = [
|
||||||
'fileLinkFormat' => null,
|
'fileLinkFormat' => null,
|
||||||
);
|
];
|
||||||
|
|
||||||
private $handlesHrefGracefully;
|
private $handlesHrefGracefully;
|
||||||
|
|
||||||
@ -632,7 +632,7 @@ class CliDumper extends AbstractDumper
|
|||||||
private function getSourceLink($file, $line)
|
private function getSourceLink($file, $line)
|
||||||
{
|
{
|
||||||
if ($fmt = $this->displayOptions['fileLinkFormat']) {
|
if ($fmt = $this->displayOptions['fileLinkFormat']) {
|
||||||
return \is_string($fmt) ? strtr($fmt, array('%f' => $file, '%l' => $line)) : $fmt->format($file, $line);
|
return \is_string($fmt) ? strtr($fmt, ['%f' => $file, '%l' => $line]) : $fmt->format($file, $line);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -49,21 +49,21 @@ class CliDescriptorTest extends TestCase
|
|||||||
return $s;
|
return $s;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
$descriptor->describe($output, new Data(array(array(123))), $context + array('timestamp' => 1544804268.3668), 1);
|
$descriptor->describe($output, new Data([[123]]), $context + ['timestamp' => 1544804268.3668], 1);
|
||||||
|
|
||||||
$this->assertStringMatchesFormat(trim($expectedOutput), str_replace(PHP_EOL, "\n", trim($output->fetch())));
|
$this->assertStringMatchesFormat(trim($expectedOutput), str_replace(PHP_EOL, "\n", trim($output->fetch())));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideContext()
|
public function provideContext()
|
||||||
{
|
{
|
||||||
yield 'source' => array(
|
yield 'source' => [
|
||||||
array(
|
[
|
||||||
'source' => array(
|
'source' => [
|
||||||
'name' => 'CliDescriptorTest.php',
|
'name' => 'CliDescriptorTest.php',
|
||||||
'line' => 30,
|
'line' => 30,
|
||||||
'file' => '/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php',
|
'file' => '/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php',
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
<<<TXT
|
<<<TXT
|
||||||
Received from client #1
|
Received from client #1
|
||||||
-----------------------
|
-----------------------
|
||||||
@ -74,18 +74,18 @@ Received from client #1
|
|||||||
file /Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php
|
file /Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php
|
||||||
-------- ---------------------------------------------------------------------------------------------------
|
-------- ---------------------------------------------------------------------------------------------------
|
||||||
TXT
|
TXT
|
||||||
);
|
];
|
||||||
|
|
||||||
yield 'source full' => array(
|
yield 'source full' => [
|
||||||
array(
|
[
|
||||||
'source' => array(
|
'source' => [
|
||||||
'name' => 'CliDescriptorTest.php',
|
'name' => 'CliDescriptorTest.php',
|
||||||
'line' => 30,
|
'line' => 30,
|
||||||
'file_relative' => 'src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php',
|
'file_relative' => 'src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php',
|
||||||
'file' => '/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php',
|
'file' => '/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php',
|
||||||
'file_link' => 'phpstorm://open?file=/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php&line=30',
|
'file_link' => 'phpstorm://open?file=/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php&line=30',
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
method_exists(OutputFormatterStyle::class, 'setHref') ?
|
method_exists(OutputFormatterStyle::class, 'setHref') ?
|
||||||
<<<TXT
|
<<<TXT
|
||||||
Received from client #1
|
Received from client #1
|
||||||
@ -112,34 +112,34 @@ Received from client #1
|
|||||||
Open source in your IDE/browser:
|
Open source in your IDE/browser:
|
||||||
phpstorm://open?file=/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php&line=30
|
phpstorm://open?file=/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php&line=30
|
||||||
TXT
|
TXT
|
||||||
);
|
];
|
||||||
|
|
||||||
if (method_exists(OutputFormatterStyle::class, 'setHref')) {
|
if (method_exists(OutputFormatterStyle::class, 'setHref')) {
|
||||||
yield 'source with hyperlink' => array(
|
yield 'source with hyperlink' => [
|
||||||
array(
|
[
|
||||||
'source' => array(
|
'source' => [
|
||||||
'name' => 'CliDescriptorTest.php',
|
'name' => 'CliDescriptorTest.php',
|
||||||
'line' => 30,
|
'line' => 30,
|
||||||
'file_relative' => 'src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php',
|
'file_relative' => 'src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php',
|
||||||
'file_link' => 'phpstorm://open?file=/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php&line=30',
|
'file_link' => 'phpstorm://open?file=/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php&line=30',
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
<<<TXT
|
<<<TXT
|
||||||
%A
|
%A
|
||||||
source \033]8;;phpstorm://open?file=/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php&line=30\033\CliDescriptorTest.php on line 30\033]8;;\033%A
|
source \033]8;;phpstorm://open?file=/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php&line=30\033\CliDescriptorTest.php on line 30\033]8;;\033%A
|
||||||
%A
|
%A
|
||||||
TXT
|
TXT
|
||||||
, true,
|
, true,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
yield 'cli' => array(
|
yield 'cli' => [
|
||||||
array(
|
[
|
||||||
'cli' => array(
|
'cli' => [
|
||||||
'identifier' => 'd8bece1c',
|
'identifier' => 'd8bece1c',
|
||||||
'command_line' => 'bin/phpunit',
|
'command_line' => 'bin/phpunit',
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
<<<TXT
|
<<<TXT
|
||||||
$ bin/phpunit
|
$ bin/phpunit
|
||||||
-------------
|
-------------
|
||||||
@ -148,17 +148,17 @@ $ bin/phpunit
|
|||||||
date Fri, 14 Dec 2018 16:17:48 +0000
|
date Fri, 14 Dec 2018 16:17:48 +0000
|
||||||
------ ---------------------------------
|
------ ---------------------------------
|
||||||
TXT
|
TXT
|
||||||
);
|
];
|
||||||
|
|
||||||
yield 'request' => array(
|
yield 'request' => [
|
||||||
array(
|
[
|
||||||
'request' => array(
|
'request' => [
|
||||||
'identifier' => 'd8bece1c',
|
'identifier' => 'd8bece1c',
|
||||||
'controller' => new Data(array(array('FooController.php'))),
|
'controller' => new Data([['FooController.php']]),
|
||||||
'method' => 'GET',
|
'method' => 'GET',
|
||||||
'uri' => 'http://localhost/foo',
|
'uri' => 'http://localhost/foo',
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
<<<TXT
|
<<<TXT
|
||||||
GET http://localhost/foo
|
GET http://localhost/foo
|
||||||
------------------------
|
------------------------
|
||||||
@ -168,6 +168,6 @@ GET http://localhost/foo
|
|||||||
controller "FooController.php"
|
controller "FooController.php"
|
||||||
------------ ---------------------------------
|
------------ ---------------------------------
|
||||||
TXT
|
TXT
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ class WorkflowTest extends TestCase
|
|||||||
{
|
{
|
||||||
$subject = new \stdClass();
|
$subject = new \stdClass();
|
||||||
$subject->marking = null;
|
$subject->marking = null;
|
||||||
$workflow = new Workflow(new Definition(array(), array()), $this->getMockBuilder(MarkingStoreInterface::class)->getMock());
|
$workflow = new Workflow(new Definition([], []), $this->getMockBuilder(MarkingStoreInterface::class)->getMock());
|
||||||
|
|
||||||
$workflow->getMarking($subject);
|
$workflow->getMarking($subject);
|
||||||
}
|
}
|
||||||
@ -40,7 +40,7 @@ class WorkflowTest extends TestCase
|
|||||||
{
|
{
|
||||||
$subject = new \stdClass();
|
$subject = new \stdClass();
|
||||||
$subject->marking = null;
|
$subject->marking = null;
|
||||||
$workflow = new Workflow(new Definition(array(), array()), new MultipleStateMarkingStore());
|
$workflow = new Workflow(new Definition([], []), new MultipleStateMarkingStore());
|
||||||
|
|
||||||
$workflow->getMarking($subject);
|
$workflow->getMarking($subject);
|
||||||
}
|
}
|
||||||
@ -52,8 +52,8 @@ class WorkflowTest extends TestCase
|
|||||||
public function testGetMarkingWithImpossiblePlace()
|
public function testGetMarkingWithImpossiblePlace()
|
||||||
{
|
{
|
||||||
$subject = new \stdClass();
|
$subject = new \stdClass();
|
||||||
$subject->marking = array('nope' => 1);
|
$subject->marking = ['nope' => 1];
|
||||||
$workflow = new Workflow(new Definition(array(), array()), new MultipleStateMarkingStore());
|
$workflow = new Workflow(new Definition([], []), new MultipleStateMarkingStore());
|
||||||
|
|
||||||
$workflow->getMarking($subject);
|
$workflow->getMarking($subject);
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ class WorkflowTest extends TestCase
|
|||||||
|
|
||||||
$this->assertInstanceOf(Marking::class, $marking);
|
$this->assertInstanceOf(Marking::class, $marking);
|
||||||
$this->assertTrue($marking->has('a'));
|
$this->assertTrue($marking->has('a'));
|
||||||
$this->assertSame(array('a' => 1), $subject->marking);
|
$this->assertSame(['a' => 1], $subject->marking);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetMarkingWithExistingMarking()
|
public function testGetMarkingWithExistingMarking()
|
||||||
@ -77,7 +77,7 @@ class WorkflowTest extends TestCase
|
|||||||
$definition = $this->createComplexWorkflowDefinition();
|
$definition = $this->createComplexWorkflowDefinition();
|
||||||
$subject = new \stdClass();
|
$subject = new \stdClass();
|
||||||
$subject->marking = null;
|
$subject->marking = null;
|
||||||
$subject->marking = array('b' => 1, 'c' => 1);
|
$subject->marking = ['b' => 1, 'c' => 1];
|
||||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
|
$workflow = new Workflow($definition, new MultipleStateMarkingStore());
|
||||||
|
|
||||||
$marking = $workflow->getMarking($subject);
|
$marking = $workflow->getMarking($subject);
|
||||||
@ -107,19 +107,19 @@ class WorkflowTest extends TestCase
|
|||||||
$this->assertTrue($workflow->can($subject, 't1'));
|
$this->assertTrue($workflow->can($subject, 't1'));
|
||||||
$this->assertFalse($workflow->can($subject, 't2'));
|
$this->assertFalse($workflow->can($subject, 't2'));
|
||||||
|
|
||||||
$subject->marking = array('b' => 1);
|
$subject->marking = ['b' => 1];
|
||||||
|
|
||||||
$this->assertFalse($workflow->can($subject, 't1'));
|
$this->assertFalse($workflow->can($subject, 't1'));
|
||||||
// In a workflow net, all "from" places should contain a token to enable
|
// In a workflow net, all "from" places should contain a token to enable
|
||||||
// the transition.
|
// the transition.
|
||||||
$this->assertFalse($workflow->can($subject, 't2'));
|
$this->assertFalse($workflow->can($subject, 't2'));
|
||||||
|
|
||||||
$subject->marking = array('b' => 1, 'c' => 1);
|
$subject->marking = ['b' => 1, 'c' => 1];
|
||||||
|
|
||||||
$this->assertFalse($workflow->can($subject, 't1'));
|
$this->assertFalse($workflow->can($subject, 't1'));
|
||||||
$this->assertTrue($workflow->can($subject, 't2'));
|
$this->assertTrue($workflow->can($subject, 't2'));
|
||||||
|
|
||||||
$subject->marking = array('f' => 1);
|
$subject->marking = ['f' => 1];
|
||||||
|
|
||||||
$this->assertFalse($workflow->can($subject, 't5'));
|
$this->assertFalse($workflow->can($subject, 't5'));
|
||||||
$this->assertTrue($workflow->can($subject, 't6'));
|
$this->assertTrue($workflow->can($subject, 't6'));
|
||||||
@ -145,7 +145,7 @@ class WorkflowTest extends TestCase
|
|||||||
$subject = new \stdClass();
|
$subject = new \stdClass();
|
||||||
$subject->marking = null;
|
$subject->marking = null;
|
||||||
|
|
||||||
$dispatchedEvents = array();
|
$dispatchedEvents = [];
|
||||||
$eventDispatcher = new EventDispatcher();
|
$eventDispatcher = new EventDispatcher();
|
||||||
|
|
||||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
|
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
|
||||||
@ -161,7 +161,7 @@ class WorkflowTest extends TestCase
|
|||||||
|
|
||||||
$workflow->can($subject, 't3');
|
$workflow->can($subject, 't3');
|
||||||
|
|
||||||
$this->assertSame(array('workflow_name.guard.t3'), $dispatchedEvents);
|
$this->assertSame(['workflow_name.guard.t3'], $dispatchedEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanWithSameNameTransition()
|
public function testCanWithSameNameTransition()
|
||||||
@ -175,7 +175,7 @@ class WorkflowTest extends TestCase
|
|||||||
$this->assertFalse($workflow->can($subject, 'b_to_c'));
|
$this->assertFalse($workflow->can($subject, 'b_to_c'));
|
||||||
$this->assertFalse($workflow->can($subject, 'to_a'));
|
$this->assertFalse($workflow->can($subject, 'to_a'));
|
||||||
|
|
||||||
$subject->marking = array('b' => 1);
|
$subject->marking = ['b' => 1];
|
||||||
$this->assertFalse($workflow->can($subject, 'a_to_bc'));
|
$this->assertFalse($workflow->can($subject, 'a_to_bc'));
|
||||||
$this->assertTrue($workflow->can($subject, 'b_to_c'));
|
$this->assertTrue($workflow->can($subject, 'b_to_c'));
|
||||||
$this->assertTrue($workflow->can($subject, 'to_a'));
|
$this->assertTrue($workflow->can($subject, 'to_a'));
|
||||||
@ -205,17 +205,17 @@ class WorkflowTest extends TestCase
|
|||||||
$this->assertTrue($workflow->buildTransitionBlockerList($subject, 't1')->isEmpty());
|
$this->assertTrue($workflow->buildTransitionBlockerList($subject, 't1')->isEmpty());
|
||||||
$this->assertFalse($workflow->buildTransitionBlockerList($subject, 't2')->isEmpty());
|
$this->assertFalse($workflow->buildTransitionBlockerList($subject, 't2')->isEmpty());
|
||||||
|
|
||||||
$subject->marking = array('b' => 1);
|
$subject->marking = ['b' => 1];
|
||||||
|
|
||||||
$this->assertFalse($workflow->buildTransitionBlockerList($subject, 't1')->isEmpty());
|
$this->assertFalse($workflow->buildTransitionBlockerList($subject, 't1')->isEmpty());
|
||||||
$this->assertFalse($workflow->buildTransitionBlockerList($subject, 't2')->isEmpty());
|
$this->assertFalse($workflow->buildTransitionBlockerList($subject, 't2')->isEmpty());
|
||||||
|
|
||||||
$subject->marking = array('b' => 1, 'c' => 1);
|
$subject->marking = ['b' => 1, 'c' => 1];
|
||||||
|
|
||||||
$this->assertFalse($workflow->buildTransitionBlockerList($subject, 't1')->isEmpty());
|
$this->assertFalse($workflow->buildTransitionBlockerList($subject, 't1')->isEmpty());
|
||||||
$this->assertTrue($workflow->buildTransitionBlockerList($subject, 't2')->isEmpty());
|
$this->assertTrue($workflow->buildTransitionBlockerList($subject, 't2')->isEmpty());
|
||||||
|
|
||||||
$subject->marking = array('f' => 1);
|
$subject->marking = ['f' => 1];
|
||||||
|
|
||||||
$this->assertFalse($workflow->buildTransitionBlockerList($subject, 't5')->isEmpty());
|
$this->assertFalse($workflow->buildTransitionBlockerList($subject, 't5')->isEmpty());
|
||||||
$this->assertTrue($workflow->buildTransitionBlockerList($subject, 't6')->isEmpty());
|
$this->assertTrue($workflow->buildTransitionBlockerList($subject, 't6')->isEmpty());
|
||||||
@ -354,10 +354,10 @@ class WorkflowTest extends TestCase
|
|||||||
public function testApplyWithSameNameTransition2()
|
public function testApplyWithSameNameTransition2()
|
||||||
{
|
{
|
||||||
$subject = new \stdClass();
|
$subject = new \stdClass();
|
||||||
$subject->marking = array('a' => 1, 'b' => 1);
|
$subject->marking = ['a' => 1, 'b' => 1];
|
||||||
|
|
||||||
$places = range('a', 'd');
|
$places = range('a', 'd');
|
||||||
$transitions = array();
|
$transitions = [];
|
||||||
$transitions[] = new Transition('t', 'a', 'c');
|
$transitions[] = new Transition('t', 'a', 'c');
|
||||||
$transitions[] = new Transition('t', 'b', 'd');
|
$transitions[] = new Transition('t', 'b', 'd');
|
||||||
$definition = new Definition($places, $transitions);
|
$definition = new Definition($places, $transitions);
|
||||||
@ -374,10 +374,10 @@ class WorkflowTest extends TestCase
|
|||||||
public function testApplyWithSameNameTransition3()
|
public function testApplyWithSameNameTransition3()
|
||||||
{
|
{
|
||||||
$subject = new \stdClass();
|
$subject = new \stdClass();
|
||||||
$subject->marking = array('a' => 1);
|
$subject->marking = ['a' => 1];
|
||||||
|
|
||||||
$places = range('a', 'd');
|
$places = range('a', 'd');
|
||||||
$transitions = array();
|
$transitions = [];
|
||||||
$transitions[] = new Transition('t', 'a', 'b');
|
$transitions[] = new Transition('t', 'a', 'b');
|
||||||
$transitions[] = new Transition('t', 'b', 'c');
|
$transitions[] = new Transition('t', 'b', 'c');
|
||||||
$transitions[] = new Transition('t', 'c', 'd');
|
$transitions[] = new Transition('t', 'c', 'd');
|
||||||
@ -398,7 +398,7 @@ class WorkflowTest extends TestCase
|
|||||||
$eventDispatcher = new EventDispatcherMock();
|
$eventDispatcher = new EventDispatcherMock();
|
||||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
|
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
|
||||||
|
|
||||||
$eventNameExpected = array(
|
$eventNameExpected = [
|
||||||
'workflow.entered',
|
'workflow.entered',
|
||||||
'workflow.workflow_name.entered',
|
'workflow.workflow_name.entered',
|
||||||
'workflow.guard',
|
'workflow.guard',
|
||||||
@ -428,7 +428,7 @@ class WorkflowTest extends TestCase
|
|||||||
'workflow.workflow_name.guard',
|
'workflow.workflow_name.guard',
|
||||||
'workflow.workflow_name.guard.t2',
|
'workflow.workflow_name.guard.t2',
|
||||||
'workflow.workflow_name.announce.t2',
|
'workflow.workflow_name.announce.t2',
|
||||||
);
|
];
|
||||||
|
|
||||||
$marking = $workflow->apply($subject, 't1');
|
$marking = $workflow->apply($subject, 't1');
|
||||||
|
|
||||||
@ -448,14 +448,14 @@ class WorkflowTest extends TestCase
|
|||||||
$this->assertEquals($name, $event->getWorkflowName());
|
$this->assertEquals($name, $event->getWorkflowName());
|
||||||
};
|
};
|
||||||
|
|
||||||
$eventNames = array(
|
$eventNames = [
|
||||||
'workflow.guard',
|
'workflow.guard',
|
||||||
'workflow.leave',
|
'workflow.leave',
|
||||||
'workflow.transition',
|
'workflow.transition',
|
||||||
'workflow.enter',
|
'workflow.enter',
|
||||||
'workflow.entered',
|
'workflow.entered',
|
||||||
'workflow.announce',
|
'workflow.announce',
|
||||||
);
|
];
|
||||||
|
|
||||||
foreach ($eventNames as $eventName) {
|
foreach ($eventNames as $eventName) {
|
||||||
$dispatcher->addListener($eventName, $assertWorkflowName);
|
$dispatcher->addListener($eventName, $assertWorkflowName);
|
||||||
@ -466,20 +466,20 @@ class WorkflowTest extends TestCase
|
|||||||
|
|
||||||
public function testMarkingStateOnApplyWithEventDispatcher()
|
public function testMarkingStateOnApplyWithEventDispatcher()
|
||||||
{
|
{
|
||||||
$definition = new Definition(range('a', 'f'), array(new Transition('t', range('a', 'c'), range('d', 'f'))));
|
$definition = new Definition(range('a', 'f'), [new Transition('t', range('a', 'c'), range('d', 'f'))]);
|
||||||
|
|
||||||
$subject = new \stdClass();
|
$subject = new \stdClass();
|
||||||
$subject->marking = array('a' => 1, 'b' => 1, 'c' => 1);
|
$subject->marking = ['a' => 1, 'b' => 1, 'c' => 1];
|
||||||
|
|
||||||
$dispatcher = new EventDispatcher();
|
$dispatcher = new EventDispatcher();
|
||||||
|
|
||||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $dispatcher, 'test');
|
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $dispatcher, 'test');
|
||||||
|
|
||||||
$assertInitialState = function (Event $event) {
|
$assertInitialState = function (Event $event) {
|
||||||
$this->assertEquals(new Marking(array('a' => 1, 'b' => 1, 'c' => 1)), $event->getMarking());
|
$this->assertEquals(new Marking(['a' => 1, 'b' => 1, 'c' => 1]), $event->getMarking());
|
||||||
};
|
};
|
||||||
$assertTransitionState = function (Event $event) {
|
$assertTransitionState = function (Event $event) {
|
||||||
$this->assertEquals(new Marking(array()), $event->getMarking());
|
$this->assertEquals(new Marking([]), $event->getMarking());
|
||||||
};
|
};
|
||||||
|
|
||||||
$dispatcher->addListener('workflow.leave', $assertInitialState);
|
$dispatcher->addListener('workflow.leave', $assertInitialState);
|
||||||
@ -512,13 +512,13 @@ class WorkflowTest extends TestCase
|
|||||||
|
|
||||||
$this->assertEmpty($workflow->getEnabledTransitions($subject));
|
$this->assertEmpty($workflow->getEnabledTransitions($subject));
|
||||||
|
|
||||||
$subject->marking = array('d' => 1);
|
$subject->marking = ['d' => 1];
|
||||||
$transitions = $workflow->getEnabledTransitions($subject);
|
$transitions = $workflow->getEnabledTransitions($subject);
|
||||||
$this->assertCount(2, $transitions);
|
$this->assertCount(2, $transitions);
|
||||||
$this->assertSame('t3', $transitions[0]->getName());
|
$this->assertSame('t3', $transitions[0]->getName());
|
||||||
$this->assertSame('t4', $transitions[1]->getName());
|
$this->assertSame('t4', $transitions[1]->getName());
|
||||||
|
|
||||||
$subject->marking = array('c' => 1, 'e' => 1);
|
$subject->marking = ['c' => 1, 'e' => 1];
|
||||||
$transitions = $workflow->getEnabledTransitions($subject);
|
$transitions = $workflow->getEnabledTransitions($subject);
|
||||||
$this->assertCount(1, $transitions);
|
$this->assertCount(1, $transitions);
|
||||||
$this->assertSame('t5', $transitions[0]->getName());
|
$this->assertSame('t5', $transitions[0]->getName());
|
||||||
@ -535,7 +535,7 @@ class WorkflowTest extends TestCase
|
|||||||
$this->assertCount(1, $transitions);
|
$this->assertCount(1, $transitions);
|
||||||
$this->assertSame('a_to_bc', $transitions[0]->getName());
|
$this->assertSame('a_to_bc', $transitions[0]->getName());
|
||||||
|
|
||||||
$subject->marking = array('b' => 1, 'c' => 1);
|
$subject->marking = ['b' => 1, 'c' => 1];
|
||||||
$transitions = $workflow->getEnabledTransitions($subject);
|
$transitions = $workflow->getEnabledTransitions($subject);
|
||||||
$this->assertCount(3, $transitions);
|
$this->assertCount(3, $transitions);
|
||||||
$this->assertSame('b_to_c', $transitions[0]->getName());
|
$this->assertSame('b_to_c', $transitions[0]->getName());
|
||||||
@ -546,7 +546,7 @@ class WorkflowTest extends TestCase
|
|||||||
|
|
||||||
class EventDispatcherMock implements \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
class EventDispatcherMock implements \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
||||||
{
|
{
|
||||||
public $dispatchedEvents = array();
|
public $dispatchedEvents = [];
|
||||||
|
|
||||||
public function dispatch($eventName, \Symfony\Component\EventDispatcher\Event $event = null)
|
public function dispatch($eventName, \Symfony\Component\EventDispatcher\Event $event = null)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user