made some method name changes to have a better coherence throughout the framework

When an object has a "main" many relation with related "things" (objects,
parameters, ...), the method names are normalized:

 * get()
 * set()
 * all()
 * replace()
 * remove()
 * clear()
 * isEmpty()
 * add()
 * register()
 * count()
 * keys()

The classes below follow this method naming convention:

 * BrowserKit\CookieJar -> Cookie
 * BrowserKit\History -> Request
 * Console\Application -> Command
 * Console\Application\Helper\HelperSet -> HelperInterface
 * DependencyInjection\Container -> services
 * DependencyInjection\ContainerBuilder -> services
 * DependencyInjection\ParameterBag\ParameterBag -> parameters
 * DependencyInjection\ParameterBag\FrozenParameterBag -> parameters
 * DomCrawler\Form -> FormField
 * EventDispatcher\Event -> parameters
 * Form\FieldGroup -> Field
 * HttpFoundation\HeaderBag -> headers
 * HttpFoundation\ParameterBag -> parameters
 * HttpFoundation\Session -> attributes
 * HttpKernel\Profiler\Profiler -> DataCollectorInterface
 * Routing\RouteCollection -> Route
 * Security\Authentication\AuthenticationProviderManager -> AuthenticationProviderInterface
 * Templating\Engine -> HelperInterface
 * Translation\MessageCatalogue -> messages

The usage of these methods are only allowed when it is clear that there is a
main relation:

 * a CookieJar has many Cookies;

 * a Container has many services and many parameters (as services is the main
   relation, we use the naming convention for this relation);

 * a Console Input has many arguments and many options. There is no "main"
   relation, and so the naming convention does not apply.

For many relations where the convention does not apply, the following methods
must be used instead (where XXX is the name of the related thing):

 * get()      -> getXXX()
 * set()      -> setXXX()
 * all()      -> getXXXs()
 * replace()  -> setXXXs()
 * remove()   -> removeXXX()
 * clear()    -> clearXXX()
 * isEmpty()  -> isEmptyXXX()
 * add()      -> addXXX()
 * register() -> registerXXX()
 * count()    -> countXXX()
 * keys()
This commit is contained in:
Fabien Potencier 2010-11-23 09:42:19 +01:00
parent 5c5e8f14c1
commit 944d91c1df
56 changed files with 266 additions and 266 deletions

View File

@ -34,8 +34,8 @@ class InternalController extends ContainerAware
$request = $this->container->get('request');
$attributes = $request->attributes;
$attributes->delete('path');
$attributes->delete('controller');
$attributes->remove('path');
$attributes->remove('controller');
if ('none' !== $path)
{
parse_str($path, $tmp);

View File

@ -49,8 +49,8 @@ class RequestListener
public function handle(Event $event)
{
$request = $event->getParameter('request');
$master = HttpKernelInterface::MASTER_REQUEST === $event->getParameter('request_type');
$request = $event->get('request');
$master = HttpKernelInterface::MASTER_REQUEST === $event->get('request_type');
$this->initializeSession($request, $master);

View File

@ -47,7 +47,7 @@ class WebDebugToolbarListener
public function handle(Event $event, Response $response)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) {
return $response;
}
@ -57,10 +57,10 @@ class WebDebugToolbarListener
$response->headers->get('location'), $response->headers->get('location'))
);
$response->setStatusCode(200);
$response->headers->delete('Location');
$response->headers->remove('Location');
}
$request = $event->getParameter('request');
$request = $event->get('request');
if (!$response->headers->has('X-Debug-Token')
|| '3' === substr($response->getStatusCode(), 0, 1)
|| ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))

View File

@ -37,7 +37,7 @@ use Symfony\Component\Console\Helper\DialogHelper;
* Usage:
*
* $app = new Application('myapp', '1.0 (stable)');
* $app->addCommand(new SimpleCommand());
* $app->add(new SimpleCommand());
* $app->run();
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
@ -74,8 +74,8 @@ class Application
new DialogHelper(),
));
$this->addCommand(new HelpCommand());
$this->addCommand(new ListCommand());
$this->add(new HelpCommand());
$this->add(new ListCommand());
$this->definition = new InputDefinition(array(
new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
@ -181,7 +181,7 @@ class Application
}
// the command name MUST be the first element of the input
$command = $this->findCommand($name);
$command = $this->find($name);
$this->runningCommand = $command;
$statusCode = $command->run($input, $output);
@ -329,7 +329,7 @@ class Application
*/
public function register($name)
{
return $this->addCommand(new Command($name));
return $this->add(new Command($name));
}
/**
@ -340,7 +340,7 @@ class Application
public function addCommands(array $commands)
{
foreach ($commands as $command) {
$this->addCommand($command);
$this->add($command);
}
}
@ -353,7 +353,7 @@ class Application
*
* @return Command The registered command
*/
public function addCommand(Command $command)
public function add(Command $command)
{
$command->setApplication($this);
@ -375,7 +375,7 @@ class Application
*
* @throws \InvalidArgumentException When command name given does not exist
*/
public function getCommand($name)
public function get($name)
{
if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) {
throw new \InvalidArgumentException(sprintf('The command "%s" does not exist.', $name));
@ -386,7 +386,7 @@ class Application
if ($this->wantHelps) {
$this->wantHelps = false;
$helpCommand = $this->getCommand('help');
$helpCommand = $this->get('help');
$helpCommand->setCommand($command);
return $helpCommand;
@ -402,7 +402,7 @@ class Application
*
* @return Boolean true if the command exists, false otherwise
*/
public function hasCommand($name)
public function has($name)
{
return isset($this->commands[$name]) || isset($this->aliases[$name]);
}
@ -451,7 +451,7 @@ class Application
/**
* Finds a command by name or alias.
*
* Contrary to getCommand, this command tries to find the best
* Contrary to get, this command tries to find the best
* match if you give it an abbreviation of a name or alias.
*
* @param string $name A command name or a command alias
@ -460,7 +460,7 @@ class Application
*
* @throws \InvalidArgumentException When command name is incorrect or ambiguous
*/
public function findCommand($name)
public function find($name)
{
// namespace
$namespace = '';
@ -481,7 +481,7 @@ class Application
$abbrevs = static::getAbbreviations($commands);
if (isset($abbrevs[$name]) && 1 == count($abbrevs[$name])) {
return $this->getCommand($namespace ? $namespace.':'.$abbrevs[$name][0] : $abbrevs[$name][0]);
return $this->get($namespace ? $namespace.':'.$abbrevs[$name][0] : $abbrevs[$name][0]);
}
if (isset($abbrevs[$name]) && count($abbrevs[$name]) > 1) {
@ -500,7 +500,7 @@ class Application
throw new \InvalidArgumentException(sprintf('Command "%s" is ambiguous (%s).', $fullName, $this->getAbbreviationSuggestions($abbrevs[$fullName])));
}
return $this->getCommand($abbrevs[$fullName][0]);
return $this->get($abbrevs[$fullName][0]);
}
/**
@ -512,7 +512,7 @@ class Application
*
* @return array An array of Command instances
*/
public function getCommands($namespace = null)
public function all($namespace = null)
{
if (null === $namespace) {
return $this->commands;
@ -566,7 +566,7 @@ class Application
*/
public function asText($namespace = null)
{
$commands = $namespace ? $this->getCommands($this->findNamespace($namespace)) : $this->commands;
$commands = $namespace ? $this->all($this->findNamespace($namespace)) : $this->commands;
$messages = array($this->getHelp(), '');
if ($namespace) {
@ -607,7 +607,7 @@ class Application
*/
public function asXml($namespace = null, $asDom = false)
{
$commands = $namespace ? $this->getCommands($this->findNamespace($namespace)) : $this->commands;
$commands = $namespace ? $this->all($this->findNamespace($namespace)) : $this->commands;
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;

View File

@ -65,7 +65,7 @@ EOF
protected function execute(InputInterface $input, OutputInterface $output)
{
if (null === $this->command) {
$this->command = $this->application->getCommand($input->getArgument('command_name'));
$this->command = $this->application->get($input->getArgument('command_name'));
}
if ($input->getOption('xml')) {

View File

@ -97,7 +97,7 @@ class Shell
// task name?
if (false === strpos($text, ' ') || !$text) {
return array_keys($this->application->getCommands());
return array_keys($this->application->all());
}
// options and arguments?

View File

@ -215,7 +215,7 @@ class Form implements \ArrayAccess
*
* @return Boolean true if the field exists, false otherwise
*/
public function hasField($name)
public function has($name)
{
return isset($this->fields[$name]);
}
@ -229,9 +229,9 @@ class Form implements \ArrayAccess
*
* @throws \InvalidArgumentException When field is not present in this form
*/
public function getField($name)
public function get($name)
{
if (!$this->hasField($name)) {
if (!$this->has($name)) {
throw new \InvalidArgumentException(sprintf('The form has no "%s" field', $name));
}
@ -245,7 +245,7 @@ class Form implements \ArrayAccess
*
* @return FormField The field instance
*/
public function setField(Field\FormField $field)
public function set(Field\FormField $field)
{
$this->fields[$field->getName()] = $field;
}
@ -255,7 +255,7 @@ class Form implements \ArrayAccess
*
* @return array An array of fields
*/
public function getFields()
public function all()
{
return $this->fields;
}
@ -280,21 +280,21 @@ class Form implements \ArrayAccess
$nodeName = $node->nodeName;
if ($node === $button) {
$this->setField(new Field\InputFormField($node));
$this->set(new Field\InputFormField($node));
} elseif ('select' == $nodeName || 'input' == $nodeName && 'checkbox' == $node->getAttribute('type')) {
$this->setField(new Field\ChoiceFormField($node));
$this->set(new Field\ChoiceFormField($node));
} elseif ('input' == $nodeName && 'radio' == $node->getAttribute('type')) {
if ($this->hasField($node->getAttribute('name'))) {
$this->getField($node->getAttribute('name'))->addChoice($node);
if ($this->has($node->getAttribute('name'))) {
$this->get($node->getAttribute('name'))->addChoice($node);
} else {
$this->setField(new Field\ChoiceFormField($node));
$this->set(new Field\ChoiceFormField($node));
}
} elseif ('input' == $nodeName && 'file' == $node->getAttribute('type')) {
$this->setField(new Field\FileFormField($node));
$this->set(new Field\FileFormField($node));
} elseif ('input' == $nodeName && !in_array($node->getAttribute('type'), array('submit', 'button', 'image'))) {
$this->setField(new Field\InputFormField($node));
$this->set(new Field\InputFormField($node));
} elseif ('textarea' == $nodeName) {
$this->setField(new Field\TextareaFormField($node));
$this->set(new Field\TextareaFormField($node));
}
}
}
@ -308,7 +308,7 @@ class Form implements \ArrayAccess
*/
public function offsetExists($name)
{
return $this->hasField($name);
return $this->has($name);
}
/**
@ -322,7 +322,7 @@ class Form implements \ArrayAccess
*/
public function offsetGet($name)
{
if (!$this->hasField($name)) {
if (!$this->has($name)) {
throw new \InvalidArgumentException(sprintf('The form field "%s" does not exist', $name));
}
@ -339,7 +339,7 @@ class Form implements \ArrayAccess
*/
public function offsetSet($name, $value)
{
if (!$this->hasField($name)) {
if (!$this->has($name)) {
throw new \InvalidArgumentException(sprintf('The form field "%s" does not exist', $name));
}

View File

@ -102,7 +102,7 @@ class Event
*
* @return array The event parameters
*/
public function getParameters()
public function all()
{
return $this->parameters;
}
@ -114,7 +114,7 @@ class Event
*
* @return Boolean true if the parameter exists, false otherwise
*/
public function hasParameter($name)
public function has($name)
{
return array_key_exists($name, $this->parameters);
}
@ -128,7 +128,7 @@ class Event
*
* @throws \InvalidArgumentException When parameter doesn't exists for this event
*/
public function getParameter($name)
public function get($name)
{
if (!array_key_exists($name, $this->parameters)) {
throw new \InvalidArgumentException(sprintf('The event "%s" has no "%s" parameter.', $this->name, $name));
@ -143,7 +143,7 @@ class Event
* @param string $name The parameter name
* @param mixed $value The parameter value
*/
public function setParameter($name, $value)
public function set($name, $value)
{
$this->parameters[$name] = $value;
}

View File

@ -145,11 +145,11 @@ class HeaderBag
}
/**
* Deletes a header.
* Removes a header.
*
* @param string $key The HTTP header name
*/
public function delete($key)
public function remove($key)
{
$key = strtr(strtolower($key), '_', '-');

View File

@ -105,11 +105,11 @@ class ParameterBag
}
/**
* Deletes a parameter.
* Removes a parameter.
*
* @param string $key The key
*/
public function delete($key)
public function remove($key)
{
unset($this->parameters[$key]);
}

View File

@ -369,14 +369,14 @@ class Response
/**
* Sets the Expires HTTP header with a \DateTime instance.
*
* If passed a null value, it deletes the header.
* If passed a null value, it removes the header.
*
* @param \DateTime $date A \DateTime instance
*/
public function setExpires(\DateTime $date = null)
{
if (null === $date) {
$this->headers->delete('Expires');
$this->headers->remove('Expires');
} else {
$date = clone $date;
$date->setTimezone(new \DateTimeZone('UTC'));
@ -490,14 +490,14 @@ class Response
/**
* Sets the Last-Modified HTTP header with a \DateTime instance.
*
* If passed a null value, it deletes the header.
* If passed a null value, it removes the header.
*
* @param \DateTime $date A \DateTime instance
*/
public function setLastModified(\DateTime $date = null)
{
if (null === $date) {
$this->headers->delete('Last-Modified');
$this->headers->remove('Last-Modified');
} else {
$date = clone $date;
$date->setTimezone(new \DateTimeZone('UTC'));
@ -524,7 +524,7 @@ class Response
public function setEtag($etag = null, $weak = false)
{
if (null === $etag) {
$this->headers->delete('Etag');
$this->headers->remove('Etag');
} else {
if (0 !== strpos($etag, '"')) {
$etag = '"'.$etag.'"';
@ -595,7 +595,7 @@ class Response
// remove headers that MUST NOT be included with 304 Not Modified responses
foreach (array('Allow', 'Content-Encoding', 'Content-Language', 'Content-Length', 'Content-MD5', 'Content-Type', 'Last-Modified') as $header) {
$this->headers->delete($header);
$this->headers->remove($header);
}
}

View File

@ -49,9 +49,9 @@ class ResponseHeaderBag extends HeaderBag
/**
* {@inheritdoc}
*/
public function delete($key)
public function remove($key)
{
parent::delete($key);
parent::remove($key);
if ('cache-control' === strtr(strtolower($key), '_', '-')) {
$this->computedCacheControl = array();

View File

@ -301,7 +301,7 @@ class Cache implements HttpKernelInterface
}
$entry = clone $entry;
$entry->headers->delete('Date');
$entry->headers->remove('Date');
foreach (array('Date', 'Expires', 'Cache-Control', 'ETag', 'Last-Modified') as $name) {
if ($response->headers->has($name)) {
@ -338,8 +338,8 @@ class Cache implements HttpKernelInterface
$subRequest->setMethod('get');
// avoid that the backend sends no content
$subRequest->headers->delete('if_modified_since');
$subRequest->headers->delete('if_none_match');
$subRequest->headers->remove('if_modified_since');
$subRequest->headers->remove('if_none_match');
$response = $this->forward($subRequest);
@ -516,14 +516,14 @@ class Cache implements HttpKernelInterface
}
$response->setContent(ob_get_clean());
$response->headers->delete('X-Body-Eval');
$response->headers->remove('X-Body-Eval');
} elseif ($response->headers->has('X-Body-File')) {
$response->setContent(file_get_contents($response->headers->get('X-Body-File')));
} else {
return;
}
$response->headers->delete('X-Body-File');
$response->headers->remove('X-Body-File');
if (!$response->headers->has('Transfer-Encoding')) {
$response->headers->set('Content-Length', strlen($response->getContent()));

View File

@ -155,7 +155,7 @@ class Esi
if ($response->headers->has('Surrogate-Control')) {
$value = $response->headers->get('Surrogate-Control');
if ('content="ESI/1.0"' == $value) {
$response->headers->delete('Surrogate-Control');
$response->headers->remove('Surrogate-Control');
} elseif (preg_match('#,\s*content="ESI/1.0"#', $value)) {
$response->headers->set('Surrogate-Control', preg_replace('#,\s*content="ESI/1.0"#', '', $value));
} elseif (preg_match('#content="ESI/1.0",\s*#', $value)) {

View File

@ -57,7 +57,7 @@ class EsiListener
*/
public function filter($event, Response $response)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) {
return $response;
}

View File

@ -48,12 +48,12 @@ class ExceptionListener
public function handle(Event $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) {
return false;
}
$exception = $event->getParameter('exception');
$request = $event->getParameter('request');
$exception = $event->get('exception');
$request = $event->get('request');
if (null !== $this->logger) {
$this->logger->err(sprintf('%s: %s (uncaught exception)', get_class($exception), $exception->getMessage()));

View File

@ -62,11 +62,11 @@ class ProfilerListener
*/
public function handleException(Event $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) {
return false;
}
$this->exception = $event->getParameter('exception');
$this->exception = $event->get('exception');
return false;
}
@ -80,11 +80,11 @@ class ProfilerListener
*/
public function handleResponse(Event $event, Response $response)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) {
return $response;
}
if (null !== $this->matcher && !$this->matcher->matches($event->getParameter('request'))) {
if (null !== $this->matcher && !$this->matcher->matches($event->get('request'))) {
return $response;
}
@ -92,7 +92,7 @@ class ProfilerListener
return $response;
}
$this->profiler->collect($event->getParameter('request'), $response, $this->exception);
$this->profiler->collect($event->get('request'), $response, $this->exception);
$this->exception = null;
return $response;

View File

@ -41,11 +41,11 @@ class ResponseListener
*/
public function filter(Event $event, Response $response)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type') || $response->headers->has('Content-Type')) {
if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type') || $response->headers->has('Content-Type')) {
return $response;
}
$request = $event->getParameter('request');
$request = $event->get('request');
$format = $request->getRequestFormat();
if ((null !== $format) && $mimeType = $request->getMimeType($format)) {
$response->headers->set('Content-Type', $mimeType);

View File

@ -60,11 +60,11 @@ class Firewall
*/
public function handle(Event $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) {
return;
}
$request = $event->getParameter('request');
$request = $event->get('request');
$this->dispatcher->disconnect('core.security');
list($listeners, $exception) = $this->map->getListeners($request);

View File

@ -65,7 +65,7 @@ class AccessListener
throw new AuthenticationCredentialsNotFoundException('A Token was not found in the SecurityContext.');
}
$request = $event->getParameter('request');
$request = $event->get('request');
list($attributes, $channel) = $this->map->getPatterns($request);

View File

@ -55,7 +55,7 @@ class AnonymousAuthenticationListener
*/
public function handle(Event $event)
{
$request = $event->getParameter('request');
$request = $event->get('request');
if (null !== $this->context->getToken()) {
return;

View File

@ -60,7 +60,7 @@ class BasicAuthenticationListener
*/
public function handle(Event $event)
{
$request = $event->getParameter('request');
$request = $event->get('request');
if (false === $username = $request->server->get('PHP_AUTH_USER', false)) {
return;

View File

@ -54,7 +54,7 @@ class ChannelListener
*/
public function handle(Event $event)
{
$request = $event->getParameter('request');
$request = $event->get('request');
list($attributes, $channel) = $this->map->getPatterns($request);

View File

@ -55,7 +55,7 @@ class ContextListener
*/
public function read(Event $event)
{
$request = $event->getParameter('request');
$request = $event->get('request');
$session = $request->hasSession() ? $request->getSession() : null;
@ -83,7 +83,7 @@ class ContextListener
*/
public function write(Event $event, Response $response)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) {
return $response;
}
@ -99,7 +99,7 @@ class ContextListener
$this->logger->debug('Write SecurityContext in the session');
}
$event->getParameter('request')->getSession()->set('_security', serialize($token));
$event->get('request')->getSession()->set('_security', serialize($token));
return $response;
}

View File

@ -63,7 +63,7 @@ class DigestAuthenticationListener
*/
public function handle(Event $event)
{
$request = $event->getParameter('request');
$request = $event->get('request');
if (!$header = $request->server->get('PHP_AUTH_DIGEST')) {
return;

View File

@ -62,8 +62,8 @@ class ExceptionListener
*/
public function handleException(Event $event)
{
$exception = $event->getParameter('exception');
$request = $event->getParameter('request');
$exception = $event->get('exception');
$request = $event->get('request');
if ($exception instanceof AuthenticationException) {
if (null !== $this->logger) {
@ -73,7 +73,7 @@ class ExceptionListener
try {
$response = $this->startAuthentication($request, $exception);
} catch (\Exception $e) {
$event->setParameter('exception', $e);
$event->set('exception', $e);
return;
}
@ -87,7 +87,7 @@ class ExceptionListener
try {
$response = $this->startAuthentication($request, new InsufficientAuthenticationException('Full authentication is required to access this resource.', $token, 0, $exception));
} catch (\Exception $e) {
$event->setParameter('exception', $e);
$event->set('exception', $e);
return;
}
@ -110,7 +110,7 @@ class ExceptionListener
$this->logger->err(sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()));
}
$event->setParameter('exception', new \RuntimeException('Exception thrown when handling an exception.', 0, $e));
$event->set('exception', new \RuntimeException('Exception thrown when handling an exception.', 0, $e));
return;
}

View File

@ -77,7 +77,7 @@ abstract class FormAuthenticationListener
*/
public function handle(Event $event)
{
$request = $event->getParameter('request');
$request = $event->get('request');
if ($this->options['check_path'] !== $request->getPathInfo()) {
return;

View File

@ -58,7 +58,7 @@ class LogoutListener
*/
public function handle(Event $event)
{
$request = $event->getParameter('request');
$request = $event->get('request');
if ($this->logoutPath !== $request->getPathInfo()) {
return;

View File

@ -58,7 +58,7 @@ abstract class PreAuthenticatedListener
*/
public function handle(Event $event)
{
$request = $event->getParameter('request');
$request = $event->get('request');
if (null !== $this->logger) {
$this->logger->debug(sprintf('Checking secure context token: %s', $this->securityContext->getToken()));

View File

@ -74,7 +74,7 @@ class SwitchUserListener
*/
public function handle(Event $event)
{
$request = $event->getParameter('request');
$request = $event->get('request');
if (!$request->get($this->usernameParameter)) {
return;

View File

@ -54,7 +54,7 @@ class UrlGenerator implements UrlGeneratorInterface
*/
public function generate($name, array $parameters, $absolute = false)
{
if (null === $route = $this->routes->getRoute($name)) {
if (null === $route = $this->routes->get($name)) {
throw new \InvalidArgumentException(sprintf('Route "%s" does not exist.', $name));
}

View File

@ -104,7 +104,7 @@ class XmlFileLoader extends FileLoader
$route = new Route((string) $definition->getAttribute('pattern'), $defaults, $requirements, $options);
$collection->addRoute((string) $definition->getAttribute('id'), $route);
$collection->add((string) $definition->getAttribute('id'), $route);
}
/**

View File

@ -83,7 +83,7 @@ class YamlFileLoader extends FileLoader
$route = new Route($config['pattern'], $defaults, $requirements, $options);
$collection->addRoute($name, $route);
$collection->add($name, $route);
}
protected function loadFile($file)

View File

@ -40,7 +40,7 @@ class RouteCollection
*
* @throws \InvalidArgumentException When route name contains non valid characters
*/
public function addRoute($name, Route $route)
public function add($name, Route $route)
{
if (!preg_match('/^[a-z0-9A-Z_]+$/', $name)) {
throw new \InvalidArgumentException(sprintf('Name "%s" contains non valid characters for a route name.', $name));
@ -54,7 +54,7 @@ class RouteCollection
*
* @return array An array of routes
*/
public function getRoutes()
public function all()
{
return $this->routes;
}
@ -66,7 +66,7 @@ class RouteCollection
*
* @return Route $route A Route instance
*/
public function getRoute($name)
public function get($name)
{
return isset($this->routes[$name]) ? $this->routes[$name] : null;
}
@ -85,7 +85,7 @@ class RouteCollection
$this->addResource($resource);
}
$this->routes = array_merge($this->routes, $collection->getRoutes());
$this->routes = array_merge($this->routes, $collection->all());
}
/**
@ -99,7 +99,7 @@ class RouteCollection
return;
}
foreach ($this->getRoutes() as $route) {
foreach ($this->all() as $route) {
$route->setPattern($prefix.$route->getPattern());
}
}

View File

@ -90,7 +90,7 @@ class AuthenticationProviderManager implements AuthenticationManagerInterface
*
* @return AuthenticationProviderInterface[] An array of AuthenticationProviderInterface instances
*/
public function getProviders()
public function all()
{
return $this->providers;
}
@ -104,7 +104,7 @@ class AuthenticationProviderManager implements AuthenticationManagerInterface
{
$this->providers = array();
foreach ($providers as $provider) {
$this->addProvider($provider);
$this->add($provider);
}
}
@ -113,7 +113,7 @@ class AuthenticationProviderManager implements AuthenticationManagerInterface
*
* @param AuthenticationProviderInterface $provider A AuthenticationProviderInterface instance
*/
public function addProvider(AuthenticationProviderInterface $provider)
public function add(AuthenticationProviderInterface $provider)
{
$this->providers[] = $provider;
}

View File

@ -27,7 +27,7 @@ class ArrayLoader implements LoaderInterface
{
$this->flatten($resource);
$catalogue = new MessageCatalogue($locale);
$catalogue->addMessages($resource, $domain);
$catalogue->add($resource, $domain);
return $catalogue;
}

View File

@ -31,7 +31,7 @@ class XliffFileLoader implements LoaderInterface
$catalogue = new MessageCatalogue($locale);
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
$catalogue->setMessage((string) $translation->source, (string) $translation->target, $domain);
$catalogue->set((string) $translation->source, (string) $translation->target, $domain);
}
$catalogue->addResource(new FileResource($resource));

View File

@ -56,7 +56,7 @@ class MessageCatalogue implements MessageCatalogueInterface
/**
* {@inheritdoc}
*/
public function getMessages($domain = null)
public function all($domain = null)
{
if (null === $domain) {
return $this->messages;
@ -68,15 +68,15 @@ class MessageCatalogue implements MessageCatalogueInterface
/**
* {@inheritdoc}
*/
public function setMessage($id, $translation, $domain = 'messages')
public function set($id, $translation, $domain = 'messages')
{
$this->addMessages(array($id => $translation), $domain);
$this->add(array($id => $translation), $domain);
}
/**
* {@inheritdoc}
*/
public function hasMessage($id, $domain = 'messages')
public function has($id, $domain = 'messages')
{
return isset($this->messages[$domain][$id]);
}
@ -84,7 +84,7 @@ class MessageCatalogue implements MessageCatalogueInterface
/**
* {@inheritdoc}
*/
public function getMessage($id, $domain = 'messages')
public function get($id, $domain = 'messages')
{
return isset($this->messages[$domain][$id]) ? $this->messages[$domain][$id] : $id;
}
@ -92,17 +92,17 @@ class MessageCatalogue implements MessageCatalogueInterface
/**
* {@inheritdoc}
*/
public function setMessages($messages, $domain = 'messages')
public function replace($messages, $domain = 'messages')
{
$this->messages[$domain] = array();
$this->addMessages($messages, $domain);
$this->add($messages, $domain);
}
/**
* {@inheritdoc}
*/
public function addMessages($messages, $domain = 'messages')
public function add($messages, $domain = 'messages')
{
if (!isset($this->messages[$domain])) {
$this->messages[$domain] = $messages;
@ -120,8 +120,8 @@ class MessageCatalogue implements MessageCatalogueInterface
throw new \LogicException(sprintf('Cannot add a catalogue for locale "%s" as the current locale for this catalogue is "%s"', $catalogue->getLocale(), $this->locale));
}
foreach ($catalogue->getMessages() as $domain => $messages) {
$this->addMessages($messages, $domain);
foreach ($catalogue->all() as $domain => $messages) {
$this->add($messages, $domain);
}
foreach ($catalogue->getResources() as $resource) {
@ -135,9 +135,9 @@ class MessageCatalogue implements MessageCatalogueInterface
public function addFallbackCatalogue(MessageCatalogueInterface $catalogue)
{
foreach ($catalogue->getDomains() as $domain) {
foreach ($catalogue->getMessages($domain) as $id => $translation) {
if (false === $this->hasMessage($id, $domain)) {
$this->setMessage($id, $translation, $domain);
foreach ($catalogue->all($domain) as $id => $translation) {
if (false === $this->has($id, $domain)) {
$this->set($id, $translation, $domain);
}
}
}

View File

@ -43,7 +43,7 @@ interface MessageCatalogueInterface
*
* @return array An array of messages
*/
function getMessages($domain = null);
function all($domain = null);
/**
* Sets a message translation.
@ -52,7 +52,7 @@ interface MessageCatalogueInterface
* @param string $translation The messages translation
* @param string $domain The domain name
*/
function setMessage($id, $translation, $domain = 'messages');
function set($id, $translation, $domain = 'messages');
/**
* Checks if a message has a translation.
@ -62,7 +62,7 @@ interface MessageCatalogueInterface
*
* @return Boolean true if the message has a translation, false otherwise
*/
function hasMessage($id, $domain = 'messages');
function has($id, $domain = 'messages');
/**
* Gets a message translation.
@ -72,7 +72,7 @@ interface MessageCatalogueInterface
*
* @return string The message translation
*/
function getMessage($id, $domain = 'messages');
function get($id, $domain = 'messages');
/**
* Sets translations for a given domain.
@ -80,7 +80,7 @@ interface MessageCatalogueInterface
* @param string $messages An array of translations
* @param string $domain The domain name
*/
function setMessages($messages, $domain = 'messages');
function replace($messages, $domain = 'messages');
/**
* Adds translations for a given domain.
@ -88,7 +88,7 @@ interface MessageCatalogueInterface
* @param string $messages An array of translations
* @param string $domain The domain name
*/
function addMessages($messages, $domain = 'messages');
function add($messages, $domain = 'messages');
/**
* Merges translations from the given Catalogue into the current one.

View File

@ -112,7 +112,7 @@ class Translator implements TranslatorInterface
$this->loadCatalogue($locale);
}
return strtr($this->catalogues[$locale]->getMessage($id, $domain), $parameters);
return strtr($this->catalogues[$locale]->get($id, $domain), $parameters);
}
/**
@ -128,7 +128,7 @@ class Translator implements TranslatorInterface
$this->loadCatalogue($locale);
}
return strtr($this->selector->choose($this->catalogues[$locale]->getMessage($id, $domain), (int) $number, $locale), $parameters);
return strtr($this->selector->choose($this->catalogues[$locale]->get($id, $domain), (int) $number, $locale), $parameters);
}
protected function loadCatalogue($locale)

View File

@ -38,7 +38,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application = new Application('foo', 'bar');
$this->assertEquals('foo', $application->getName(), '__construct() takes the application name as its first argument');
$this->assertEquals('bar', $application->getVersion(), '__construct() takes the application version as its first argument');
$this->assertEquals(array('help', 'list'), array_keys($application->getCommands()), '__construct() registered the help and list commands by default');
$this->assertEquals(array('help', 'list'), array_keys($application->all()), '__construct() registered the help and list commands by default');
}
public function testSetGetName()
@ -67,15 +67,15 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this->assertStringEqualsFile(self::$fixturesPath.'/application_gethelp.txt', $application->getHelp(), '->setHelp() returns a help message');
}
public function testGetCommands()
public function testAll()
{
$application = new Application();
$commands = $application->getCommands();
$this->assertEquals('Symfony\\Component\\Console\\Command\\HelpCommand', get_class($commands['help']), '->getCommands() returns the registered commands');
$commands = $application->all();
$this->assertEquals('Symfony\\Component\\Console\\Command\\HelpCommand', get_class($commands['help']), '->all() returns the registered commands');
$application->addCommand(new \FooCommand());
$commands = $application->getCommands('foo');
$this->assertEquals(1, count($commands), '->getCommands() takes a namespace as its first argument');
$application->add(new \FooCommand());
$commands = $application->all('foo');
$this->assertEquals(1, count($commands), '->all() takes a namespace as its first argument');
}
public function testRegister()
@ -85,60 +85,60 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('foo', $command->getName(), '->register() registers a new command');
}
public function testAddCommand()
public function testAdd()
{
$application = new Application();
$application->addCommand($foo = new \FooCommand());
$commands = $application->getCommands();
$this->assertEquals($foo, $commands['foo:bar'], '->addCommand() registers a command');
$application->add($foo = new \FooCommand());
$commands = $application->all();
$this->assertEquals($foo, $commands['foo:bar'], '->add() registers a command');
$application = new Application();
$application->addCommands(array($foo = new \FooCommand(), $foo1 = new \Foo1Command()));
$commands = $application->getCommands();
$commands = $application->all();
$this->assertEquals(array($foo, $foo1), array($commands['foo:bar'], $commands['foo:bar1']), '->addCommands() registers an array of commands');
}
public function testHasGetCommand()
public function testHasGet()
{
$application = new Application();
$this->assertTrue($application->hasCommand('list'), '->hasCommand() returns true if a named command is registered');
$this->assertFalse($application->hasCommand('afoobar'), '->hasCommand() returns false if a named command is not registered');
$this->assertTrue($application->has('list'), '->has() returns true if a named command is registered');
$this->assertFalse($application->has('afoobar'), '->has() returns false if a named command is not registered');
$application->addCommand($foo = new \FooCommand());
$this->assertTrue($application->hasCommand('afoobar'), '->hasCommand() returns true if an alias is registered');
$this->assertEquals($foo, $application->getCommand('foo:bar'), '->getCommand() returns a command by name');
$this->assertEquals($foo, $application->getCommand('afoobar'), '->getCommand() returns a command by alias');
$application->add($foo = new \FooCommand());
$this->assertTrue($application->has('afoobar'), '->has() returns true if an alias is registered');
$this->assertEquals($foo, $application->get('foo:bar'), '->get() returns a command by name');
$this->assertEquals($foo, $application->get('afoobar'), '->get() returns a command by alias');
try {
$application->getCommand('foofoo');
$this->fail('->getCommand() throws an \InvalidArgumentException if the command does not exist');
$application->get('foofoo');
$this->fail('->get() throws an \InvalidArgumentException if the command does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->getCommand() throws an \InvalidArgumentException if the command does not exist');
$this->assertEquals('The command "foofoo" does not exist.', $e->getMessage(), '->getCommand() throws an \InvalidArgumentException if the command does not exist');
$this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws an \InvalidArgumentException if the command does not exist');
$this->assertEquals('The command "foofoo" does not exist.', $e->getMessage(), '->get() throws an \InvalidArgumentException if the command does not exist');
}
$application = new TestApplication();
$application->addCommand($foo = new \FooCommand());
$application->add($foo = new \FooCommand());
$application->setWantHelps();
$command = $application->getCommand('foo:bar');
$this->assertEquals('Symfony\Component\Console\Command\HelpCommand', get_class($command), '->getCommand() returns the help command if --help is provided as the input');
$command = $application->get('foo:bar');
$this->assertEquals('Symfony\Component\Console\Command\HelpCommand', get_class($command), '->get() returns the help command if --help is provided as the input');
}
public function testGetNamespaces()
{
$application = new TestApplication();
$application->addCommand(new \FooCommand());
$application->addCommand(new \Foo1Command());
$application->add(new \FooCommand());
$application->add(new \Foo1Command());
$this->assertEquals(array('foo'), $application->getNamespaces(), '->getNamespaces() returns an array of unique used namespaces');
}
public function testFindNamespace()
{
$application = new TestApplication();
$application->addCommand(new \FooCommand());
$application->add(new \FooCommand());
$this->assertEquals('foo', $application->findNamespace('foo'), '->findNamespace() returns the given namespace if it exists');
$this->assertEquals('foo', $application->findNamespace('f'), '->findNamespace() finds a namespace given an abbreviation');
$application->addCommand(new \Foo2Command());
$application->add(new \Foo2Command());
$this->assertEquals('foo', $application->findNamespace('foo'), '->findNamespace() returns the given namespace if it exists');
try {
$application->findNamespace('f');
@ -157,41 +157,41 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
}
}
public function testFindCommand()
public function testFind()
{
$application = new TestApplication();
$application->addCommand(new \FooCommand());
$this->assertEquals('FooCommand', get_class($application->findCommand('foo:bar')), '->findCommand() returns a command if its name exists');
$this->assertEquals('Symfony\Component\Console\Command\HelpCommand', get_class($application->findCommand('h')), '->findCommand() returns a command if its name exists');
$this->assertEquals('FooCommand', get_class($application->findCommand('f:bar')), '->findCommand() returns a command if the abbreviation for the namespace exists');
$this->assertEquals('FooCommand', get_class($application->findCommand('f:b')), '->findCommand() returns a command if the abbreviation for the namespace and the command name exist');
$this->assertEquals('FooCommand', get_class($application->findCommand('a')), '->findCommand() returns a command if the abbreviation exists for an alias');
$application->add(new \FooCommand());
$this->assertEquals('FooCommand', get_class($application->find('foo:bar')), '->find() returns a command if its name exists');
$this->assertEquals('Symfony\Component\Console\Command\HelpCommand', get_class($application->find('h')), '->find() returns a command if its name exists');
$this->assertEquals('FooCommand', get_class($application->find('f:bar')), '->find() returns a command if the abbreviation for the namespace exists');
$this->assertEquals('FooCommand', get_class($application->find('f:b')), '->find() returns a command if the abbreviation for the namespace and the command name exist');
$this->assertEquals('FooCommand', get_class($application->find('a')), '->find() returns a command if the abbreviation exists for an alias');
$application->addCommand(new \Foo1Command());
$application->addCommand(new \Foo2Command());
$application->add(new \Foo1Command());
$application->add(new \Foo2Command());
try {
$application->findCommand('f');
$this->fail('->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
$application->find('f');
$this->fail('->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
$this->assertEquals('Command "f" is not defined.', $e->getMessage(), '->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
$this->assertEquals('Command "f" is not defined.', $e->getMessage(), '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
}
try {
$application->findCommand('a');
$this->fail('->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
$application->find('a');
$this->fail('->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
$this->assertEquals('Command "a" is ambiguous (afoobar, afoobar1 and 1 more).', $e->getMessage(), '->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
$this->assertEquals('Command "a" is ambiguous (afoobar, afoobar1 and 1 more).', $e->getMessage(), '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
}
try {
$application->findCommand('foo:b');
$this->fail('->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
$application->find('foo:b');
$this->fail('->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
$this->assertEquals('Command "foo:b" is ambiguous (foo:bar, foo:bar1).', $e->getMessage(), '->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
$this->assertEquals('Command "foo:b" is ambiguous (foo:bar, foo:bar1).', $e->getMessage(), '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
}
}
@ -218,7 +218,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
public function testAsText()
{
$application = new Application();
$application->addCommand(new \FooCommand);
$application->add(new \FooCommand);
$this->assertStringEqualsFile(self::$fixturesPath.'/application_astext1.txt', $application->asText(), '->asText() returns a text representation of the application');
$this->assertStringEqualsFile(self::$fixturesPath.'/application_astext2.txt', $application->asText('foo'), '->asText() returns a text representation of the application');
}
@ -226,7 +226,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
public function testAsXml()
{
$application = new Application();
$application->addCommand(new \FooCommand);
$application->add(new \FooCommand);
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml1.txt', $application->asXml(), '->asXml() returns an XML representation of the application');
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml2.txt', $application->asXml('foo'), '->asXml() returns an XML representation of the application');
}
@ -252,7 +252,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$application->addCommand($command = new \Foo1Command());
$application->add($command = new \Foo1Command());
$_SERVER['argv'] = array('cli.php', 'foo:bar1');
ob_start();
@ -328,7 +328,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$application->addCommand(new \FooCommand());
$application->add(new \FooCommand());
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo:bar', '--no-interaction' => true));
$this->assertEquals("called\n", $this->normalize($tester->getDisplay()), '->run() does not called interact() if --no-interaction is passed');

View File

@ -30,7 +30,7 @@ class HelpCommandTest extends \PHPUnit_Framework_TestCase
$this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
$application = new Application();
$commandTester = new CommandTester($application->getCommand('help'));
$commandTester = new CommandTester($application->get('help'));
$commandTester->execute(array('command_name' => 'list'));
$this->assertRegExp('/list \[--xml\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');

View File

@ -19,7 +19,7 @@ class ListCommandTest extends \PHPUnit_Framework_TestCase
{
$application = new Application();
$commandTester = new CommandTester($command = $application->getCommand('list'));
$commandTester = new CommandTester($command = $application->get('list'));
$commandTester->execute(array('command' => $command->getFullName()));
$this->assertRegExp('/help Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands');

View File

@ -60,7 +60,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
public function testConstructor($message, $form, $values)
{
$form = $this->createForm('<form>'.$form.'</form>');
$this->assertEquals($values, array_map(function ($field) { return array(get_class($field), $field->getValue()); }, $form->getFields()), '->getDefaultValues() '.$message);
$this->assertEquals($values, array_map(function ($field) { return array(get_class($field), $field->getValue()); }, $form->all()), '->getDefaultValues() '.$message);
}
public function provideInitializeValues()
@ -336,35 +336,35 @@ class FormTest extends \PHPUnit_Framework_TestCase
);
}
public function testHasField()
public function testHas()
{
$form = $this->createForm('<form method="post"><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
$this->assertFalse($form->hasField('foo'), '->hasField() returns false if a field is not in the form');
$this->assertTrue($form->hasField('bar'), '->hasField() returns true if a field is in the form');
$this->assertFalse($form->has('foo'), '->has() returns false if a field is not in the form');
$this->assertTrue($form->has('bar'), '->has() returns true if a field is in the form');
}
public function testGetField()
public function testGet()
{
$form = $this->createForm('<form method="post"><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
$this->assertEquals('Symfony\\Component\\DomCrawler\\Field\\InputFormField', get_class($form->getField('bar')), '->getField() returns the field object associated with the given name');
$this->assertEquals('Symfony\\Component\\DomCrawler\\Field\\InputFormField', get_class($form->get('bar')), '->get() returns the field object associated with the given name');
try {
$form->getField('foo');
$this->fail('->getField() throws an \InvalidArgumentException if the field does not exist');
$form->get('foo');
$this->fail('->get() throws an \InvalidArgumentException if the field does not exist');
} catch (\InvalidArgumentException $e) {
$this->assertTrue(true, '->getField() throws an \InvalidArgumentException if the field does not exist');
$this->assertTrue(true, '->get() throws an \InvalidArgumentException if the field does not exist');
}
}
public function testGetFields()
public function testAll()
{
$form = $this->createForm('<form method="post"><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
$fields = $form->getFields();
$this->assertEquals(1, count($fields), '->getFields() return an array of form field objects');
$this->assertEquals('Symfony\\Component\\DomCrawler\\Field\\InputFormField', get_class($fields['bar']), '->getFields() return an array of form field objects');
$fields = $form->all();
$this->assertEquals(1, count($fields), '->all() return an array of form field objects');
$this->assertEquals('Symfony\\Component\\DomCrawler\\Field\\InputFormField', get_class($fields['bar']), '->all() return an array of form field objects');
}
protected function createForm($form, $method = null, $host = null, $path = '/')

View File

@ -32,19 +32,19 @@ class EventTest extends \PHPUnit_Framework_TestCase
{
$event = $this->createEvent();
$this->assertEquals($this->parameters, $event->getParameters(), '->getParameters() returns the event parameters');
$this->assertEquals('bar', $event->getParameter('foo'), '->getParameter() returns the value of a parameter');
$event->setParameter('foo', 'foo');
$this->assertEquals('foo', $event->getParameter('foo'), '->setParameter() changes the value of a parameter');
$this->assertTrue($event->hasParameter('foo'), '->hasParameter() returns true if the parameter is defined');
$this->assertFalse($event->hasParameter('oof'), '->hasParameter() returns false if the parameter is not defined');
$this->assertEquals($this->parameters, $event->all(), '->all() returns the event parameters');
$this->assertEquals('bar', $event->get('foo'), '->get() returns the value of a parameter');
$event->set('foo', 'foo');
$this->assertEquals('foo', $event->get('foo'), '->set() changes the value of a parameter');
$this->assertTrue($event->has('foo'), '->has() returns true if the parameter is defined');
$this->assertFalse($event->has('oof'), '->has() returns false if the parameter is not defined');
try {
$event->getParameter('foobar');
$this->fail('->getParameter() throws an \InvalidArgumentException exception when the parameter does not exist');
$event->get('foobar');
$this->fail('->get() throws an \InvalidArgumentException exception when the parameter does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->getParameter() throws an \InvalidArgumentException exception when the parameter does not exist');
$this->assertEquals('The event "name" has no "foobar" parameter.', $e->getMessage(), '->getParameter() throws an \InvalidArgumentException exception when the parameter does not exist');
$this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws an \InvalidArgumentException exception when the parameter does not exist');
$this->assertEquals('The event "name" has no "foobar" parameter.', $e->getMessage(), '->get() throws an \InvalidArgumentException exception when the parameter does not exist');
}
$event = new Event($this->subject, 'name', $this->parameters);
}

View File

@ -44,7 +44,7 @@ class BaseHttpKernelTest extends \PHPUnit_Framework_TestCase
$dispatcher = new EventDispatcher();
$dispatcher->connect('core.exception', function ($event)
{
$event->setReturnValue(new Response($event->getParameter('exception')->getMessage()));
$event->setReturnValue(new Response($event->get('exception')->getMessage()));
return true;
});

View File

@ -769,7 +769,7 @@ class CacheTest extends CacheTestCase
} elseif ('POST' == $request->getMethod()) {
$response->setStatusCode(303);
$response->headers->set('Location', '/');
$response->headers->delete('Cache-Control');
$response->headers->remove('Cache-Control');
$response->setContent('');
}
});

View File

@ -40,11 +40,11 @@ class ClosureLoaderTest extends \PHPUnit_Framework_TestCase
{
$routes = new RouteCollection();
$routes->addRoute('foo', $route);
$routes->add('foo', $route);
return $routes;
});
$this->assertEquals($route, $routes->getRoute('foo'), '->load() loads a \Closure resource');
$this->assertEquals($route, $routes->get('foo'), '->load() loads a \Closure resource');
}
}

View File

@ -71,12 +71,12 @@ class DelegatingLoaderTest extends \PHPUnit_Framework_TestCase
{
$routes = new RouteCollection();
$routes->addRoute('foo', $route);
$routes->add('foo', $route);
return $routes;
});
$this->assertSame($route, $routes->getRoute('foo'), '->load() loads a resource using the loaders from the resolver');
$this->assertSame($route, $routes->get('foo'), '->load() loads a resource using the loaders from the resolver');
try {
$loader->load('foo.foo');

View File

@ -20,7 +20,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
public function testNormalizeUrl()
{
$collection = new RouteCollection();
$collection->addRoute('foo', new Route('/:foo'));
$collection->add('foo', new Route('/:foo'));
$matcher = new UrlMatcherForTests($collection, array(), array());

View File

@ -21,39 +21,39 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase
{
$collection = new RouteCollection();
$route = new Route('/foo');
$collection->addRoute('foo', $route);
$this->assertEquals(array('foo' => $route), $collection->getRoutes(), '->addRoute() adds a route');
$this->assertEquals($route, $collection->getRoute('foo'), '->getRoute() returns a route by name');
$this->assertNull($collection->getRoute('bar'), '->getRoute() returns null if a route does not exist');
$collection->add('foo', $route);
$this->assertEquals(array('foo' => $route), $collection->all(), '->add() adds a route');
$this->assertEquals($route, $collection->get('foo'), '->get() returns a route by name');
$this->assertNull($collection->get('bar'), '->get() returns null if a route does not exist');
}
/**
* @covers Symfony\Component\Routing\RouteCollection::addRoute
* @covers Symfony\Component\Routing\RouteCollection::add
* @expectedException InvalidArgumentException
*/
public function testAddInvalidRoute()
{
$collection = new RouteCollection();
$route = new Route('/foo');
$collection->addRoute('f o o', $route);
$collection->add('f o o', $route);
}
public function testAddCollection()
{
$collection = new RouteCollection();
$collection->addRoute('foo', $foo = new Route('/foo'));
$collection->add('foo', $foo = new Route('/foo'));
$collection1 = new RouteCollection();
$collection1->addRoute('foo', $foo1 = new Route('/foo1'));
$collection1->addRoute('bar', $bar1 = new Route('/bar1'));
$collection1->add('foo', $foo1 = new Route('/foo1'));
$collection1->add('bar', $bar1 = new Route('/bar1'));
$collection->addCollection($collection1);
$this->assertEquals(array('foo' => $foo1, 'bar' => $bar1), $collection->getRoutes(), '->addCollection() adds routes from another collection');
$this->assertEquals(array('foo' => $foo1, 'bar' => $bar1), $collection->all(), '->addCollection() adds routes from another collection');
$collection = new RouteCollection();
$collection->addRoute('foo', $foo = new Route('/foo'));
$collection->add('foo', $foo = new Route('/foo'));
$collection1 = new RouteCollection();
$collection1->addRoute('foo', $foo1 = new Route('/foo1'));
$collection1->add('foo', $foo1 = new Route('/foo1'));
$collection->addCollection($collection1, '/foo');
$this->assertEquals('/foo/foo1', $collection->getRoute('foo')->getPattern(), '->addCollection() can add a prefix to all merged routes');
$this->assertEquals('/foo/foo1', $collection->get('foo')->getPattern(), '->addCollection() can add a prefix to all merged routes');
$collection = new RouteCollection();
$collection->addResource($foo = new FileResource(__DIR__.'/Fixtures/foo.xml'));
@ -66,11 +66,11 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase
public function testAddPrefix()
{
$collection = new RouteCollection();
$collection->addRoute('foo', $foo = new Route('/foo'));
$collection->addRoute('bar', $bar = new Route('/bar'));
$collection->add('foo', $foo = new Route('/foo'));
$collection->add('bar', $bar = new Route('/bar'));
$collection->addPrefix('/admin');
$this->assertEquals('/admin/foo', $collection->getRoute('foo')->getPattern(), '->addPrefix() adds a prefix to all routes');
$this->assertEquals('/admin/bar', $collection->getRoute('bar')->getPattern(), '->addPrefix() adds a prefix to all routes');
$this->assertEquals('/admin/foo', $collection->get('foo')->getPattern(), '->addPrefix() adds a prefix to all routes');
$this->assertEquals('/admin/bar', $collection->get('bar')->getPattern(), '->addPrefix() adds a prefix to all routes');
}
public function testResource()

View File

@ -21,11 +21,11 @@ class AuthenticationProviderManagerTest extends \PHPUnit_Framework_TestCase
public function testProviderAccessors()
{
$manager = new AuthenticationProviderManager();
$manager->addProvider($provider = $this->getMock('Symfony\Component\Security\Authentication\Provider\AuthenticationProviderInterface'));
$this->assertSame(array($provider), $manager->getProviders());
$manager->add($provider = $this->getMock('Symfony\Component\Security\Authentication\Provider\AuthenticationProviderInterface'));
$this->assertSame(array($provider), $manager->all());
$manager->setProviders($providers = array($this->getMock('Symfony\Component\Security\Authentication\Provider\AuthenticationProviderInterface')));
$this->assertSame($providers, $manager->getProviders());
$this->assertSame($providers, $manager->all());
}
/**

View File

@ -22,7 +22,7 @@ class PhpFileLoaderTest extends \PHPUnit_Framework_TestCase
$resource = __DIR__.'/../fixtures/resources.php';
$catalogue = $loader->load($resource, 'en', 'domain1');
$this->assertEquals(array('foo' => 'bar'), $catalogue->getMessages('domain1'));
$this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
$this->assertEquals('en', $catalogue->getLocale());
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
}

View File

@ -22,7 +22,7 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase
$resource = __DIR__.'/../fixtures/resources.xliff';
$catalogue = $loader->load($resource, 'en', 'domain1');
$this->assertEquals(array('foo' => 'bar'), $catalogue->getMessages('domain1'));
$this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
$this->assertEquals('en', $catalogue->getLocale());
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
}

View File

@ -22,7 +22,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
$resource = __DIR__.'/../fixtures/resources.yml';
$catalogue = $loader->load($resource, 'en', 'domain1');
$this->assertEquals(array('foo' => 'bar'), $catalogue->getMessages('domain1'));
$this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1'));
$this->assertEquals('en', $catalogue->getLocale());
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
}

View File

@ -29,55 +29,55 @@ class MessageCatalogueTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array('domain1', 'domain2'), $catalogue->getDomains());
}
public function testGetMessages()
public function testAll()
{
$catalogue = new MessageCatalogue('en', $messages = array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
$this->assertEquals(array('foo' => 'foo'), $catalogue->getMessages('domain1'));
$this->assertEquals(array(), $catalogue->getMessages('domain88'));
$this->assertEquals($messages, $catalogue->getMessages());
$this->assertEquals(array('foo' => 'foo'), $catalogue->all('domain1'));
$this->assertEquals(array(), $catalogue->all('domain88'));
$this->assertEquals($messages, $catalogue->all());
}
public function testHasMessage()
public function testHas()
{
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
$this->assertTrue($catalogue->hasMessage('foo', 'domain1'));
$this->assertFalse($catalogue->hasMessage('bar', 'domain1'));
$this->assertFalse($catalogue->hasMessage('foo', 'domain88'));
$this->assertTrue($catalogue->has('foo', 'domain1'));
$this->assertFalse($catalogue->has('bar', 'domain1'));
$this->assertFalse($catalogue->has('foo', 'domain88'));
}
public function testGetSetMessage()
public function testGetSet()
{
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
$catalogue->setMessage('foo1', 'foo1', 'domain1');
$catalogue->set('foo1', 'foo1', 'domain1');
$this->assertEquals('foo', $catalogue->getMessage('foo', 'domain1'));
$this->assertEquals('foo1', $catalogue->getMessage('foo1', 'domain1'));
$this->assertEquals('foo', $catalogue->get('foo', 'domain1'));
$this->assertEquals('foo1', $catalogue->get('foo1', 'domain1'));
}
public function testAddMessages()
public function testAdd()
{
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
$catalogue->addMessages(array('foo1' => 'foo1'), 'domain1');
$catalogue->add(array('foo1' => 'foo1'), 'domain1');
$this->assertEquals('foo', $catalogue->getMessage('foo', 'domain1'));
$this->assertEquals('foo1', $catalogue->getMessage('foo1', 'domain1'));
$this->assertEquals('foo', $catalogue->get('foo', 'domain1'));
$this->assertEquals('foo1', $catalogue->get('foo1', 'domain1'));
$catalogue->addMessages(array('foo' => 'bar'), 'domain1');
$this->assertEquals('bar', $catalogue->getMessage('foo', 'domain1'));
$this->assertEquals('foo1', $catalogue->getMessage('foo1', 'domain1'));
$catalogue->add(array('foo' => 'bar'), 'domain1');
$this->assertEquals('bar', $catalogue->get('foo', 'domain1'));
$this->assertEquals('foo1', $catalogue->get('foo1', 'domain1'));
$catalogue->addMessages(array('foo' => 'bar'), 'domain88');
$this->assertEquals('bar', $catalogue->getMessage('foo', 'domain88'));
$catalogue->add(array('foo' => 'bar'), 'domain88');
$this->assertEquals('bar', $catalogue->get('foo', 'domain88'));
}
public function testSetMessages()
public function testReplace()
{
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
$catalogue->setMessages($messages = array('foo1' => 'foo1'), 'domain1');
$catalogue->replace($messages = array('foo1' => 'foo1'), 'domain1');
$this->assertEquals($messages, $catalogue->getMessages('domain1'));
$this->assertEquals($messages, $catalogue->all('domain1'));
}
public function testAddCatalogue()
@ -96,8 +96,8 @@ class MessageCatalogueTest extends \PHPUnit_Framework_TestCase
$catalogue->addCatalogue($catalogue1);
$this->assertEquals('foo', $catalogue->getMessage('foo', 'domain1'));
$this->assertEquals('foo1', $catalogue->getMessage('foo1', 'domain1'));
$this->assertEquals('foo', $catalogue->get('foo', 'domain1'));
$this->assertEquals('foo1', $catalogue->get('foo1', 'domain1'));
$this->assertEquals(array($r, $r1), $catalogue->getResources());
}
@ -118,8 +118,8 @@ class MessageCatalogueTest extends \PHPUnit_Framework_TestCase
$catalogue->addFallbackCatalogue($catalogue1);
$this->assertEquals('foo', $catalogue->getMessage('foo', 'domain1'));
$this->assertEquals('foo1', $catalogue->getMessage('foo1', 'domain1'));
$this->assertEquals('foo', $catalogue->get('foo', 'domain1'));
$this->assertEquals('foo1', $catalogue->get('foo1', 'domain1'));
$this->assertEquals(array($r, $r1), $catalogue->getResources());
}