Merge branch '2.0'

* 2.0:
  [FrameworkBundle] Added functional tests.
  [Form] Added missing use statements (closes #2880)
  [Console] Improve input definition output for Boolean defaults
  [SecurityBundle] Changed environment to something unique.
  2879: missing space between catch and the brace
  #2688: Entities are generated in wrong folder (doctrine:generate:entities Namespace)
  [TwigBundle] Fix the exception message escaping
This commit is contained in:
Fabien Potencier 2011-12-15 18:17:38 +01:00
commit 2750adb52d
20 changed files with 451 additions and 19 deletions

View File

@ -113,7 +113,12 @@ EOT
$output->writeln(sprintf(' > backing up <comment>%s.php</comment> to <comment>%s.php~</comment>', $basename, $basename));
}
// Getting the metadata for the entity class once more to get the correct path if the namespace has multiple occurrences
$entityMetadata = $manager->getClassMetadata($m->getName(), $input->getOption('path'));
try {
$entityMetadata = $manager->getClassMetadata($m->getName(), $input->getOption('path'));
} catch (\RuntimeException $e) {
// fall back to the bundle metadata when no entity class could be found
$entityMetadata = $metadata;
}
$output->writeln(sprintf(' > generating <comment>%s</comment>', $m->name));
$generator->generate(array($m), $entityMetadata->getPath());

View File

@ -0,0 +1,73 @@
<?php
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\DependencyInjection\ContainerAware;
class SessionController extends ContainerAware
{
public function welcomeAction($name=null)
{
$request = $this->container->get('request');
$session = $request->getSession();
// new session case
if (!$session->has('name')) {
if (!$name) {
return new Response('You are new here and gave no name.');
}
// remember name
$session->set('name', $name);
return new Response(sprintf('Hello %s, nice to meet you.', $name));
}
// existing session
$name = $session->get('name');
return new Response(sprintf('Welcome back %s, nice to meet you.', $name));
}
public function logoutAction()
{
$request = $this->container->get('request')->getSession('session')->clear();
return new Response('Session cleared.');
}
public function setFlashAction($message)
{
$request = $this->container->get('request');
$session = $request->getSession();
$session->setFlash('notice', $message);
return new RedirectResponse($this->container->get('router')->generate('session_showflash'));
}
public function showFlashAction()
{
$request = $this->container->get('request');
$session = $request->getSession();
if ($session->hasFlash('notice')) {
$output = $session->getFlash('notice');
} else {
$output = 'No flash was set.';
}
return new Response($output);
}
}

View File

@ -0,0 +1,20 @@
session_welcome:
pattern: /session
defaults: { _controller: TestBundle:Session:welcome }
session_welcome_name:
pattern: /session/{name}
defaults: { _controller: TestBundle:Session:welcome }
session_logout:
pattern: /session_logout
defaults: { _controller: TestBundle:Session:logout}
session_setflash:
pattern: /session_setflash/{message}
defaults: { _controller: TestBundle:Session:setFlash}
session_showflash:
pattern: /session_showflash
defaults: { _controller: TestBundle:Session:showFlash}

View File

@ -0,0 +1,18 @@
<?php
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class TestBundle extends Bundle
{
}

View File

@ -0,0 +1,87 @@
<?php
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
/**
* @group functional
*/
class SessionTest extends WebTestCase
{
/**
* @dataProvider getConfigs
*/
public function testWelcome($config)
{
$client = $this->createClient(array('test_case' => 'Session', 'root_config' => $config));
$client->insulate();
// no session
$crawler = $client->request('GET', '/session');
$this->assertContains('You are new here and gave no name.', $crawler->text());
// remember name
$crawler = $client->request('GET', '/session/drak');
$this->assertContains('Hello drak, nice to meet you.', $crawler->text());
// prove remembered name
$crawler = $client->request('GET', '/session');
$this->assertContains('Welcome back drak, nice to meet you.', $crawler->text());
// clear session
$crawler = $client->request('GET', '/session_logout');
$this->assertContains('Session cleared.', $crawler->text());
// prove cleared session
$crawler = $client->request('GET', '/session');
$this->assertContains('You are new here and gave no name.', $crawler->text());
}
/**
* @dataProvider getConfigs
*/
public function testFlash($config)
{
$client = $this->createClient(array('test_case' => 'Session', 'root_config' => $config));
$client->insulate();
// set flash
$crawler = $client->request('GET', '/session_setflash/Hello%20world.');
// check flash displays on redirect
$this->assertContains('Hello world.', $client->followRedirect()->text());
// check flash is gone
$crawler = $client->request('GET', '/session_showflash');
$this->assertContains('No flash was set.', $crawler->text());
}
public function getConfigs()
{
return array(
array('config.yml'),
);
}
protected function setUp()
{
parent::setUp();
$this->deleteTmpDir('SessionTest');
}
protected function tearDown()
{
parent::tearDown();
$this->deleteTmpDir('SessionTest');
}
}

View File

@ -0,0 +1,66 @@
<?php
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
use Symfony\Component\HttpKernel\Util\Filesystem;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
class WebTestCase extends BaseWebTestCase
{
static public function assertRedirect($response, $location)
{
self::assertTrue($response->isRedirect(), 'Response is not a redirect, got status code: '.substr($response, 0, 2000));
self::assertEquals('http://localhost'.$location, $response->headers->get('Location'));
}
protected function setUp()
{
if (!class_exists('Twig_Environment')) {
$this->markTestSkipped('Twig is not available.');
}
parent::setUp();
}
protected function deleteTmpDir($testCase)
{
if (!file_exists($dir = sys_get_temp_dir().'/'.$testCase)) {
return;
}
$fs = new Filesystem();
$fs->remove($dir);
}
static protected function getKernelClass()
{
require_once __DIR__.'/app/AppKernel.php';
return 'Symfony\Bundle\FrameworkBundle\Tests\Functional\AppKernel';
}
static protected function createKernel(array $options = array())
{
$class = self::getKernelClass();
if (!isset($options['test_case'])) {
throw new \InvalidArgumentException('The option "test_case" must be set.');
}
return new $class(
$options['test_case'],
isset($options['root_config']) ? $options['root_config'] : 'config.yml',
isset($options['environment']) ? $options['environment'] : 'frameworkbundletest',
isset($options['debug']) ? $options['debug'] : true
);
}
}

View File

@ -0,0 +1,113 @@
<?php
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
// get the autoload file
$dir = __DIR__;
$lastDir = null;
while ($dir !== $lastDir) {
$lastDir = $dir;
if (is_file($dir.'/autoload.php')) {
require_once $dir.'/autoload.php';
break;
}
if (is_file($dir.'/autoload.php.dist')) {
require_once $dir.'/autoload.php.dist';
break;
}
$dir = dirname($dir);
}
use Symfony\Component\HttpKernel\Util\Filesystem;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;
/**
* App Test Kernel for functional tests.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class AppKernel extends Kernel
{
private $testCase;
private $rootConfig;
public function __construct($testCase, $rootConfig, $environment, $debug)
{
if (!is_dir(__DIR__.'/'.$testCase)) {
throw new \InvalidArgumentException(sprintf('The test case "%s" does not exist.', $testCase));
}
$this->testCase = $testCase;
$fs = new Filesystem();
if (!$fs->isAbsolutePath($rootConfig) && !is_file($rootConfig = __DIR__.'/'.$testCase.'/'.$rootConfig)) {
throw new \InvalidArgumentException(sprintf('The root config "%s" does not exist.', $rootConfig));
}
$this->rootConfig = $rootConfig;
parent::__construct($environment, $debug);
}
public function registerBundles()
{
if (!is_file($filename = $this->getRootDir().'/'.$this->testCase.'/bundles.php')) {
throw new \RuntimeException(sprintf('The bundles file "%s" does not exist.', $filename));
}
return include $filename;
}
public function init()
{
}
public function getRootDir()
{
return __DIR__;
}
public function getCacheDir()
{
return sys_get_temp_dir().'/'.$this->testCase.'/cache/'.$this->environment;
}
public function getLogDir()
{
return sys_get_temp_dir().'/'.$this->testCase.'/logs';
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->rootConfig);
}
public function serialize()
{
return serialize(array($this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug()));
}
public function unserialize($str)
{
call_user_func_array(array($this, '__construct'), unserialize($str));
}
protected function getKernelParameters()
{
$parameters = parent::getKernelParameters();
$parameters['kernel.test_case'] = $this->testCase;
return $parameters;
}
}

View File

@ -0,0 +1,9 @@
<?php
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
return array(
new FrameworkBundle(),
new TestBundle(),
);

View File

@ -0,0 +1,3 @@
imports:
- { resource: ./../config/default.yml }

View File

@ -0,0 +1,2 @@
_sessiontest_bundle:
resource: @TestBundle/Resources/config/routing.yml

View File

@ -0,0 +1,2 @@
imports:
- { resource: framework.yml }

View File

@ -0,0 +1,14 @@
framework:
charset: UTF-8
secret: test
csrf_protection:
enabled: true
router: { resource: "%kernel.root_dir%/%kernel.test_case%/routing.yml" }
validation: { enabled: true, enable_annotations: true }
form: ~
test: ~
session:
auto_start: true
storage_id: session.storage.filesystem
services:
logger: { class: Symfony\Component\HttpKernel\Log\NullLogger }

View File

@ -59,7 +59,7 @@ class WebTestCase extends BaseWebTestCase
return new $class(
$options['test_case'],
isset($options['root_config']) ? $options['root_config'] : 'config.yml',
isset($options['environment']) ? $options['environment'] : 'test',
isset($options['environment']) ? $options['environment'] : 'securitybundletest',
isset($options['debug']) ? $options['debug'] : true
);
}

View File

@ -2,7 +2,7 @@
{% if count > 0 %}
<h2>
<span><small>[{{ count - position + 1 }}/{{ count + 1 }}]</small></span>
{{ exception.class|abbr_class }}: {{ exception.message|replace({ "\n": '<br />' }) }}&nbsp;
{{ exception.class|abbr_class }}: {{ exception.message|e|replace({"\n": '<br />'})|format_file_from_text }}&nbsp;
{% spaceless %}
<a href="#" onclick="toggle('traces_{{ position }}', 'traces'); switchIcons('icon_traces_{{ position }}_open', 'icon_traces_{{ position }}_close'); return false;">
<img class="toggle" id="icon_traces_{{ position }}_close" alt="-" src="{{ asset('bundles/framework/images/blue_picto_less.gif') }}" style="visibility: {{ 0 == count ? 'display' : 'hidden' }}" />

View File

@ -426,7 +426,7 @@ class InputDefinition
$text[] = '<comment>Arguments:</comment>';
foreach ($this->getArguments() as $argument) {
if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) {
$default = sprintf('<comment> (default: %s)</comment>', is_array($argument->getDefault()) ? str_replace("\n", '', var_export($argument->getDefault(), true)): $argument->getDefault());
$default = sprintf('<comment> (default: %s)</comment>', is_bool($argument->getDefault()) || is_array($argument->getDefault()) ? str_replace("\n", '', var_export($argument->getDefault(), true)): $argument->getDefault());
} else {
$default = '';
}
@ -444,7 +444,7 @@ class InputDefinition
foreach ($this->getOptions() as $option) {
if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
$default = sprintf('<comment> (default: %s)</comment>', is_array($option->getDefault()) ? str_replace("\n", '', print_r($option->getDefault(), true)): $option->getDefault());
$default = sprintf('<comment> (default: %s)</comment>', is_bool($option->getDefault()) || is_array($option->getDefault()) ? str_replace("\n", '', var_export($option->getDefault(), true)): $option->getDefault());
} else {
$default = '';
}
@ -491,7 +491,7 @@ class InputDefinition
$descriptionXML->appendChild($dom->createTextNode($argument->getDescription()));
$argumentXML->appendChild($defaultsXML = $dom->createElement('defaults'));
$defaults = is_array($argument->getDefault()) ? $argument->getDefault() : ($argument->getDefault() ? array($argument->getDefault()) : array());
$defaults = is_array($argument->getDefault()) ? $argument->getDefault() : (is_bool($argument->getDefault()) ? array(var_export($argument->getDefault(), true)) : ($argument->getDefault() ? array($argument->getDefault()) : array()));
foreach ($defaults as $default) {
$defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
$defaultXML->appendChild($dom->createTextNode($default));
@ -511,7 +511,7 @@ class InputDefinition
if ($option->acceptValue()) {
$optionXML->appendChild($defaultsXML = $dom->createElement('defaults'));
$defaults = is_array($option->getDefault()) ? $option->getDefault() : ($option->getDefault() ? array($option->getDefault()) : array());
$defaults = is_array($option->getDefault()) ? $option->getDefault() : (is_bool($option->getDefault()) ? array(var_export($option->getDefault(), true)) : ($option->getDefault() ? array($option->getDefault()) : array()));
foreach ($defaults as $default) {
$defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
$defaultXML->appendChild($dom->createTextNode($default));

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Form\Extension\Core\DataTransformer;
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
class ArrayToBooleanChoicesTransformer implements DataTransformerInterface

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Form\Extension\Core\DataTransformer;
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Util\FormUtil;

View File

@ -1,7 +1,9 @@
<comment>Arguments:</comment>
<info>foo </info> The bar argument
<info>bar </info> The foo argument<comment> (default: array ( 0 => 'bar',))</comment>
<info>foo </info> The foo argument
<info>baz </info> The baz argument<comment> (default: true)</comment>
<info>bar </info> The bar argument<comment> (default: array ( 0 => 'bar',))</comment>
<comment>Options:</comment>
<info>--foo</info> (-f) The foo option
<info>--bar</info> (-b) The foo option<comment> (default: bar)</comment>
<info>--baz</info> The baz option<comment> (default: false)</comment>
<info>--bar</info> (-b) The bar option<comment> (default: bar)</comment>

View File

@ -2,11 +2,17 @@
<definition>
<arguments>
<argument name="foo" is_required="0" is_array="0">
<description>The bar argument</description>
<description>The foo argument</description>
<defaults/>
</argument>
<argument name="baz" is_required="0" is_array="0">
<description>The baz argument</description>
<defaults>
<default>true</default>
</defaults>
</argument>
<argument name="bar" is_required="0" is_array="1">
<description>The foo argument</description>
<description>The bar argument</description>
<defaults>
<default>bar</default>
</defaults>
@ -17,8 +23,14 @@
<description>The foo option</description>
<defaults/>
</option>
<option name="--baz" shortcut="" accept_value="1" is_value_required="0" is_multiple="0">
<description>The baz option</description>
<defaults>
<default>false</default>
</defaults>
</option>
<option name="--bar" shortcut="-b" accept_value="1" is_value_required="0" is_multiple="0">
<description>The foo option</description>
<description>The bar option</description>
<defaults>
<default>bar</default>
</defaults>

View File

@ -321,10 +321,12 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
public function testAsText()
{
$definition = new InputDefinition(array(
new InputArgument('foo', InputArgument::OPTIONAL, 'The bar argument'),
new InputArgument('bar', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'The foo argument', array('bar')),
new InputArgument('foo', InputArgument::OPTIONAL, 'The foo argument'),
new InputArgument('baz', InputArgument::OPTIONAL, 'The baz argument', true),
new InputArgument('bar', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'The bar argument', array('bar')),
new InputOption('foo', 'f', InputOption::VALUE_REQUIRED, 'The foo option'),
new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL, 'The foo option', 'bar'),
new InputOption('baz', null, InputOption::VALUE_OPTIONAL, 'The baz option', false),
new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL, 'The bar option', 'bar'),
));
$this->assertStringEqualsFile(self::$fixtures.'/definition_astext.txt', $definition->asText(), '->asText() returns a textual representation of the InputDefinition');
}
@ -332,10 +334,12 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
public function testAsXml()
{
$definition = new InputDefinition(array(
new InputArgument('foo', InputArgument::OPTIONAL, 'The bar argument'),
new InputArgument('bar', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'The foo argument', array('bar')),
new InputArgument('foo', InputArgument::OPTIONAL, 'The foo argument'),
new InputArgument('baz', InputArgument::OPTIONAL, 'The baz argument', true),
new InputArgument('bar', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'The bar argument', array('bar')),
new InputOption('foo', 'f', InputOption::VALUE_REQUIRED, 'The foo option'),
new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL, 'The foo option', 'bar'),
new InputOption('baz', null, InputOption::VALUE_OPTIONAL, 'The baz option', false),
new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL, 'The bar option', 'bar'),
));
$this->assertXmlStringEqualsXmlFile(self::$fixtures.'/definition_asxml.txt', $definition->asXml(), '->asText() returns a textual representation of the InputDefinition');
}