Beispiel #1
0
<?php

/*
 * This file is part of Twig.
 *
 * (c) Fabien Potencier
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../../lib/lime/LimeAutoloader.php';
LimeAutoloader::register();
require_once dirname(__FILE__) . '/../../../lib/Twig/Autoloader.php';
Twig_Autoloader::register();
$t = new LimeTest(3);
// ->autoload()
$t->diag('->autoload()');
$t->ok(!class_exists('Foo'), '->autoload() does not try to load classes that does not begin with Twig');
$autoloader = new Twig_Autoloader();
$t->is($autoloader->autoload('Twig_Parser'), true, '->autoload() returns true if it is able to load a class');
$t->is($autoloader->autoload('Foo'), false, '->autoload() returns false if it is not able to load a class');
Beispiel #2
0
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../../bootstrap.php';
use Symfony\Components\CLI\Tester\CommandTester;
use Symfony\Components\CLI\Command\HelpCommand;
use Symfony\Components\CLI\Command\ListCommand;
use Symfony\Components\CLI\Application;
$t = new LimeTest(4);
// ->execute()
$t->diag('->execute()');
$command = new HelpCommand();
$command->setCommand(new ListCommand());
$commandTester = new CommandTester($command);
$commandTester->execute(array());
$t->like($commandTester->getDisplay(), '/list \\[--xml\\] \\[namespace\\]/', '->execute() returns a text help for the given command');
$commandTester->execute(array('--xml' => true));
$t->like($commandTester->getDisplay(), '/<command/', '->execute() returns an XML help text if --xml is passed');
$application = new Application();
$commandTester = new CommandTester($application->getCommand('help'));
$commandTester->execute(array('command_name' => 'list'));
$t->like($commandTester->getDisplay(), '/list \\[--xml\\] \\[namespace\\]/', '->execute() returns a text help for the given command');
$commandTester->execute(array('command_name' => 'list', '--xml' => true));
$t->like($commandTester->getDisplay(), '/<command/', '->execute() returns an XML help text if --xml is passed');
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../bootstrap.php';
use Symfony\Components\EventDispatcher\Event;
use Symfony\Components\EventDispatcher\EventDispatcher;
$t = new LimeTest(19);
$dispatcher = new EventDispatcher();
// ->connect() ->disconnect()
$t->diag('->connect() ->disconnect()');
$dispatcher->connect('bar', 'listenToBar');
$t->is($dispatcher->getListeners('bar'), array('listenToBar'), '->connect() connects a listener to an event name');
$dispatcher->connect('bar', 'listenToBarBar');
$t->is($dispatcher->getListeners('bar'), array('listenToBar', 'listenToBarBar'), '->connect() can connect several listeners for the same event name');
$dispatcher->connect('barbar', 'listenToBarBar');
$dispatcher->disconnect('bar', 'listenToBarBar');
$t->is($dispatcher->getListeners('bar'), array('listenToBar'), '->disconnect() disconnects a listener for an event name');
$t->is($dispatcher->getListeners('barbar'), array('listenToBarBar'), '->disconnect() disconnects a listener for an event name');
$t->ok($dispatcher->disconnect('foobar', 'listen') === false, '->disconnect() returns false if the listener does not exist');
// ->getListeners() ->hasListeners()
$t->diag('->getListeners() ->hasListeners()');
$t->is($dispatcher->hasListeners('foo'), false, '->hasListeners() returns false if the event has no listener');
$dispatcher->connect('foo', 'listenToFoo');
$t->is($dispatcher->hasListeners('foo'), true, '->hasListeners() returns true if the event has some listeners');
$dispatcher->disconnect('foo', 'listenToFoo');
Beispiel #4
0
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../../bootstrap.php';
use Symfony\Components\CLI\Output\Formatter;
$t = new LimeTest(4);
// ::formatSection()
$t->diag('::formatSection()');
$t->is(Formatter::formatSection('cli', 'Some text to display'), '<info>[cli]</info> Some text to display', '::formatSection() formats a message in a section');
// ::formatBlock()
$t->diag('::formatBlock()');
$t->is(Formatter::formatBlock('Some text to display', 'error'), '<error> Some text to display </error>', '::formatBlock() formats a message in a block');
$t->is(Formatter::formatBlock(array('Some text to display', 'foo bar'), 'error'), "<error> Some text to display </error>\n<error> foo bar              </error>", '::formatBlock() formats a message in a block');
$t->is(Formatter::formatBlock('Some text to display', 'error', true), "<error>                        </error>\n<error>  Some text to display  </error>\n<error>                        </error>", '::formatBlock() formats a message in a block');
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

require_once __DIR__.'/../../../../bootstrap.php';

use Symfony\Components\Console\Output\Output;
use Symfony\Components\Console\Output\StreamOutput;

$t = new LimeTest(5);

$stream = fopen('php://memory', 'a', false);

// __construct()
$t->diag('__construct()');

try
{
  $output = new StreamOutput('foo');
  $t->fail('__construct() throws an \InvalidArgumentException if the first argument is not a stream');
}
catch (\InvalidArgumentException $e)
{
  $t->pass('__construct() throws an \InvalidArgumentException if the first argument is not a stream');
}

$output = new StreamOutput($stream, Output::VERBOSITY_QUIET, true);
$t->is($output->getVerbosity(), Output::VERBOSITY_QUIET, '__construct() takes the verbosity as its first argument');
$t->is($output->isDecorated(), true, '__construct() takes the decorated flag as its second argument');
Beispiel #6
0
/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../bootstrap.php';
use Symfony\Components\DependencyInjection\Builder;
use Symfony\Components\DependencyInjection\BuilderConfiguration;
use Symfony\Components\DependencyInjection\Definition;
use Symfony\Components\DependencyInjection\Reference;
$fixturesPath = __DIR__ . '/../../../../fixtures/Symfony/Components/DependencyInjection/';
$t = new LimeTest(61);
// ->setDefinitions() ->addDefinitions() ->getDefinitions() ->setDefinition() ->getDefinition() ->hasDefinition()
$t->diag('->setDefinitions() ->addDefinitions() ->getDefinitions() ->setDefinition() ->getDefinition() ->hasDefinition()');
$builder = new Builder();
$definitions = array('foo' => new Definition('FooClass'), 'bar' => new Definition('BarClass'));
$builder->setDefinitions($definitions);
$t->is($builder->getDefinitions(), $definitions, '->setDefinitions() sets the service definitions');
$t->ok($builder->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
$t->ok(!$builder->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
$builder->setDefinition('foobar', $foo = new Definition('FooBarClass'));
$t->is($builder->getDefinition('foobar'), $foo, '->getDefinition() returns a service definition if defined');
$t->ok($builder->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fuild interface by returning the service reference');
$builder->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
$t->is($builder->getDefinitions(), array_merge($definitions, $defs), '->addDefinitions() adds the service definitions');
try {
    $builder->getDefinition('baz');
    $t->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
} catch (InvalidArgumentException $e) {
use Symfony\Components\Console\Input\InputDefinition;
use Symfony\Components\Console\Input\InputArgument;
use Symfony\Components\Console\Input\InputOption;
use Symfony\Components\Console\Exception;

$fixtures = __DIR__.'/../../../../../fixtures/Symfony/Components/Console';

$t = new LimeTest(51);

$foo = new InputArgument('foo');
$bar = new InputArgument('bar');
$foo1 = new InputArgument('foo');
$foo2 = new InputArgument('foo2', InputArgument::REQUIRED);

// __construct()
$t->diag('__construct()');
$definition = new InputDefinition();
$t->is($definition->getArguments(), array(), '__construct() creates a new InputDefinition object');

$definition = new InputDefinition(array($foo, $bar));
$t->is($definition->getArguments(), array('foo' => $foo, 'bar' => $bar), '__construct() takes an array of InputArgument objects as its first argument');

// ->setArguments()
$t->diag('->setArguments()');
$definition = new InputDefinition();
$definition->setArguments(array($foo));
$t->is($definition->getArguments(), array('foo' => $foo), '->setArguments() sets the array of InputArgument objects');
$definition->setArguments(array($bar));

$t->is($definition->getArguments(), array('bar' => $bar), '->setArguments() clears all InputArgument objects');
Beispiel #8
0
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../bootstrap.php';
use Symfony\Components\Yaml\Yaml;
use Symfony\Components\Yaml\Parser;
use Symfony\Components\Yaml\ParserException;
Yaml::setSpecVersion('1.1');
$t = new LimeTest(148);
$parser = new Parser();
$path = __DIR__ . '/../../../../fixtures/Symfony/Components/Yaml';
$files = $parser->parse(file_get_contents($path . '/index.yml'));
foreach ($files as $file) {
    $t->diag($file);
    $yamls = file_get_contents($path . '/' . $file . '.yml');
    // split YAMLs documents
    foreach (preg_split('/^---( %YAML\\:1\\.0)?/m', $yamls) as $yaml) {
        if (!$yaml) {
            continue;
        }
        $test = $parser->parse($yaml);
        if (isset($test['todo']) && $test['todo']) {
            $t->todo($test['test']);
        } else {
            $expected = var_export(eval('return ' . trim($test['php']) . ';'), true);
            $t->is(var_export($parser->parse($test['yaml']), true), $expected, $test['test']);
        }
    }
}
use Symfony\Components\DependencyInjection\Reference;
use Symfony\Components\DependencyInjection\Definition;
use Symfony\Components\DependencyInjection\Loader\Loader;
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
$t = new LimeTest(44);
$fixturesPath = realpath(__DIR__ . '/../../../../../fixtures/Symfony/Components/DependencyInjection/');
require_once $fixturesPath . '/includes/ProjectExtension.php';
class ProjectLoader extends XmlFileLoader
{
    public function getFilesAsXml(array $files)
    {
        return parent::getFilesAsXml($files);
    }
}
// ->getFilesAsXml()
$t->diag('->getFilesAsXml()');
$loader = new ProjectLoader($fixturesPath . '/ini');
try {
    $loader->getFilesAsXml(array('foo.xml'));
    $t->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
} catch (InvalidArgumentException $e) {
    $t->pass('->load() throws an InvalidArgumentException if the loaded file does not exist');
}
try {
    $loader->getFilesAsXml(array('parameters.ini'));
    $t->fail('->load() throws an InvalidArgumentException if the loaded file is not a valid XML file');
} catch (InvalidArgumentException $e) {
    $t->pass('->load() throws an InvalidArgumentException if the loaded file is not a valid XML file');
}
$loader = new ProjectLoader($fixturesPath . '/xml');
try {
Beispiel #10
0
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

require_once __DIR__.'/../../../../bootstrap.php';

use Symfony\Components\Templating\Storage\Storage;
use Symfony\Components\Templating\Renderer\PhpRenderer;

$t = new LimeTest(2);

class TestStorage extends Storage
{
  public function getContent()
  {
  }
}

// __construct() __toString()
$t->diag('__construct() __toString()');

$storage = new TestStorage('foo');
$t->is((string) $storage, 'foo', '__toString() returns the template name');

// ->getRenderer()
$t->diag('->getRenderer()');
$storage = new TestStorage('foo', $renderer = new PhpRenderer());
$t->ok($storage->getRenderer() === $renderer, '->getRenderer() returns the renderer');
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../bootstrap.php';
use Symfony\Components\DependencyInjection\Reference;
$t = new LimeTest(1);
// __construct() ->__toString()
$t->diag('__construct() ->__toString()');
$ref = new Reference('foo');
$t->is((string) $ref, 'foo', '__construct() sets the id of the reference, which is used for the __toString() method');
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../bootstrap.php';
use Symfony\Components\Routing\FileResource;
$t = new LimeTest(4);
// ->getResource()
$t->diag('->getResource()');
$file = sys_get_temp_dir() . '/tmp.xml';
touch($file);
$resource = new FileResource($file);
$t->is($resource->getResource(), $file, '->getResource() returns the path to the resource');
// ->isUptodate()
$t->diag('->isUptodate()');
$t->ok($resource->isUptodate(time() + 10), '->isUptodate() returns true if the resource has not changed');
$t->ok(!$resource->isUptodate(time() - 86400), '->isUptodate() returns false if the resource has been updated');
unlink($file);
$resource = new FileResource('/____foo/foobar' . rand(1, 999999));
$t->ok(!$resource->isUptodate(time()), '->isUptodate() returns false if the resource does not exist');
Beispiel #13
0
use Symfony\Components\Console\Input\StringInput;
use Symfony\Components\Console\Output\OutputInterface;
use Symfony\Components\Console\Output\NullOutput;
use Symfony\Components\Console\Output\StreamOutput;
use Symfony\Components\Console\Tester\CommandTester;

$fixtures = __DIR__.'/../../../../../fixtures/Symfony/Components/Console';

$t = new LimeTest(46);

require_once $fixtures.'/TestCommand.php';

$application = new Application();

// __construct()
$t->diag('__construct()');
try
{
  $command = new Command();
  $t->fail('__construct() throws a \LogicException if the name is null');
}
catch (\LogicException $e)
{
  $t->pass('__construct() throws a \LogicException if the name is null');
}
$command = new Command('foo:bar');
$t->is($command->getFullName(), 'foo:bar', '__construct() takes the command name as its first argument');

// ->setApplication()
$t->diag('->setApplication()');
$command = new TestCommand();
<?php

/*
 * This file is part of the symfony package.
 *
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../../bootstrap.php';
require_once __DIR__ . '/../../../../../lib/SymfonyTests/Components/Templating/ProjectTemplateDebugger.php';
use Symfony\Components\Templating\Loader\Loader;
$t = new LimeTest(1);
class ProjectTemplateLoader extends Loader
{
    public function load($template, $renderer = 'php')
    {
    }
    public function getDebugger()
    {
        return $this->debugger;
    }
}
// ->setDebugger()
$t->diag('->setDebugger()');
$loader = new ProjectTemplateLoader();
$loader->setDebugger($debugger = new ProjectTemplateDebugger());
$t->ok($loader->getDebugger() === $debugger, '->setDebugger() sets the debugger instance');
class ProjectTemplateLoader extends FilesystemLoader
{
  public function getTemplatePathPatterns()
  {
    return $this->templatePathPatterns;
  }

  static public function isAbsolutePath($path)
  {
    return parent::isAbsolutePath($path);
  }
}

// ->isAbsolutePath()
$t->diag('->isAbsolutePath()');
$t->ok(ProjectTemplateLoader::isAbsolutePath('/foo.xml'), '->isAbsolutePath() returns true if the path is an absolute path');
$t->ok(ProjectTemplateLoader::isAbsolutePath('c:\\\\foo.xml'), '->isAbsolutePath() returns true if the path is an absolute path');
$t->ok(ProjectTemplateLoader::isAbsolutePath('c:/foo.xml'), '->isAbsolutePath() returns true if the path is an absolute path');
$t->ok(ProjectTemplateLoader::isAbsolutePath('\\server\\foo.xml'), '->isAbsolutePath() returns true if the path is an absolute path');

// __construct()
$t->diag('__construct()');
$pathPattern = $fixturesPath.'/templates/%name%.%renderer%';
$path = $fixturesPath.'/templates';
$loader = new ProjectTemplateLoader($pathPattern);
$t->is($loader->getTemplatePathPatterns(), array($pathPattern), '__construct() takes a path as its second argument');
$loader = new ProjectTemplateLoader(array($pathPattern));
$t->is($loader->getTemplatePathPatterns(), array($pathPattern), '__construct() takes an array of paths as its second argument');

// ->load()
<?php

/*
 * This file is part of the symfony package.
 *
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../../bootstrap.php';
use Symfony\Components\Templating\Helper\Helper;
use Symfony\Components\Templating\Helper\HelperSet;
$t = new LimeTest(1);
class ProjectTemplateHelper extends Helper
{
    public function getName()
    {
        return 'foo';
    }
}
// ->getHelperSet() ->setHelperSet()
$t->diag('->getHelperSet() ->setHelperSet()');
$helper = new ProjectTemplateHelper();
$helper->setHelperSet($helperSet = new HelperSet(array($helper)));
$t->ok($helperSet === $helper->getHelperSet(), '->setHelperSet() sets the helper set related to this helper');
$t = new LimeTest(25);

$fixturesPath = realpath(__DIR__.'/../../../../../fixtures/Symfony/Components/DependencyInjection/');

require_once $fixturesPath.'/includes/ProjectExtension.php';

class ProjectLoader extends YamlFileLoader
{
  public function loadFile($file)
  {
    return parent::loadFile($file);
  }
}

// ->loadFile()
$t->diag('->loadFile()');

$loader = new ProjectLoader($fixturesPath.'/ini');

try
{
  $loader->loadFile('foo.yml');
  $t->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
}
catch (InvalidArgumentException $e)
{
  $t->pass('->load() throws an InvalidArgumentException if the loaded file does not exist');
}

try
{
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../../bootstrap.php';
use Symfony\Components\Routing\Matcher\UrlMatcher;
use Symfony\Components\Routing\RouteCollection;
use Symfony\Components\Routing\Route;
$t = new LimeTest(1);
$collection = new RouteCollection();
$collection->addRoute('foo', new Route('/:foo'));
class UrlMatcherTest extends UrlMatcher
{
    public function normalizeUrl($url)
    {
        return parent::normalizeUrl($url);
    }
}
$matcher = new UrlMatcherTest($collection, array(), array());
// ->normalizeUrl()
$t->diag('->normalizeUrl()');
$t->is($matcher->normalizeUrl(''), '/', '->normalizeUrl() adds a / at the beginning of the URL if needed');
$t->is($matcher->normalizeUrl('foo'), '/foo', '->normalizeUrl() adds a / at the beginning of the URL if needed');
$t->is($matcher->normalizeUrl('/foo?foo=bar'), '/foo', '->normalizeUrl() removes the query string');
$t->is($matcher->normalizeUrl('/foo//bar'), '/foo/bar', '->normalizeUrl() removes duplicated /');
// ->match()
$t->diag('->match()');
//var_export($matcher->match('/foo'));
//print_R($compiler->compile(new route('/:foo')));
Beispiel #19
0
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../bootstrap.php';
use Symfony\Components\DependencyInjection\Container;
$fixturesPath = __DIR__ . '/../../../../fixtures/Symfony/Components/DependencyInjection/';
$t = new LimeTest(42);
// __construct()
$t->diag('__construct()');
$sc = new Container();
$t->is(spl_object_hash($sc->getService('service_container')), spl_object_hash($sc), '__construct() automatically registers itself as a service');
$sc = new Container(array('foo' => 'bar'));
$t->is($sc->getParameters(), array('foo' => 'bar'), '__construct() takes an array of parameters as its first argument');
// ->setParameters() ->getParameters()
$t->diag('->setParameters() ->getParameters()');
$sc = new Container();
$t->is($sc->getParameters(), array(), '->getParameters() returns an empty array if no parameter has been defined');
$sc->setParameters(array('foo' => 'bar'));
$t->is($sc->getParameters(), array('foo' => 'bar'), '->setParameters() sets the parameters');
$sc->setParameters(array('bar' => 'foo'));
$t->is($sc->getParameters(), array('bar' => 'foo'), '->setParameters() overrides the previous defined parameters');
$sc->setParameters(array('Bar' => 'foo'));
$t->is($sc->getParameters(), array('bar' => 'foo'), '->setParameters() converts the key to lowercase');
// ->setParameter() ->getParameter()
$t->diag('->setParameter() ->getParameter() ');
<?php

/*
 * This file is part of the symfony package.
 *
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../../bootstrap.php';
use Symfony\Components\Templating\Helper\AssetsHelper;
$t = new LimeTest(25);
// __construct()
$t->diag('__construct()');
$helper = new AssetsHelper('foo', 'http://www.example.com', 'abcd');
$t->is($helper->getBasePath(), '/foo/', '__construct() takes a base path as its first argument');
$t->is($helper->getBaseURLs(), array('http://www.example.com'), '__construct() takes a base URL as its second argument');
$t->is($helper->getVersion(), 'abcd', '__construct() takes a version as its thrid argument');
// ->getBasePath() ->setBasePath()
$t->diag('->getBasePath() ->setBasePath()');
$helper = new AssetsHelper();
$helper->setBasePath('foo/');
$t->is($helper->getBasePath(), '/foo/', '->setBasePath() prepends a / if needed');
$helper->setBasePath('/foo');
$t->is($helper->getBasePath(), '/foo/', '->setBasePath() appends a / is needed');
$helper->setBasePath('');
$t->is($helper->getBasePath(), '/', '->setBasePath() returns / if no base path is defined');
$helper->setBasePath('0');
$t->is($helper->getBasePath(), '/0/', '->setBasePath() returns /0/ if 0 is given');
// ->getVersion() ->getVersion()
class OutputEscaperTest
{
  public function __toString()
  {
    return $this->getTitle();
  }

  public function getTitle()
  {
    return '<strong>escaped!</strong>';
  }

  public function getTitles()
  {
    return array(1, 2, '<strong>escaped!</strong>');
  }
}

$object = new OutputEscaperTest();
$escaped = Escaper::escape('entities', $object);

$t->is($escaped->getTitle(), '&lt;strong&gt;escaped!&lt;/strong&gt;', 'The escaped object behaves like the real object');

$array = $escaped->getTitles();
$t->is($array[2], '&lt;strong&gt;escaped!&lt;/strong&gt;', 'The escaped object behaves like the real object');

// __toString()
$t->diag('__toString()');

$t->is($escaped->__toString(), '&lt;strong&gt;escaped!&lt;/strong&gt;', 'The escaped object behaves like the real object');
/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../bootstrap.php';
use Symfony\Components\DependencyInjection\Builder;
$fixturesPath = realpath(__DIR__ . '/../../../../fixtures/Symfony/Components/DependencyInjection/');
require_once $fixturesPath . '/includes/classes.php';
require_once $fixturesPath . '/includes/foo.php';
$t = new LimeTest(30);
// cross-check loaders/dumpers
$t->diag('cross-check loaders/dumpers');
$fixtures = array('services1.xml' => 'xml', 'services2.xml' => 'xml', 'services6.xml' => 'xml', 'services8.xml' => 'xml', 'services9.xml' => 'xml', 'services1.yml' => 'yaml', 'services2.yml' => 'yaml', 'services6.yml' => 'yaml', 'services8.yml' => 'yaml', 'services9.yml' => 'yaml');
foreach ($fixtures as $fixture => $type) {
    $loaderClass = 'Symfony\\Components\\DependencyInjection\\Loader\\' . ucfirst($type) . 'FileLoader';
    $dumperClass = 'Symfony\\Components\\DependencyInjection\\Dumper\\' . ucfirst($type) . 'Dumper';
    $container1 = new Builder();
    $loader1 = new $loaderClass($container1);
    $loader1->load($fixturesPath . '/' . $type . '/' . $fixture);
    $container1->setParameter('path', $fixturesPath . '/includes');
    $dumper = new $dumperClass($container1);
    $tmp = tempnam('sf_service_container', 'sf');
    file_put_contents($tmp, $dumper->dump());
    $container2 = new Builder();
    $loader2 = new $loaderClass($container2);
    $loader2->load($tmp);
    $container2->setParameter('path', $fixturesPath . '/includes');
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../bootstrap.php';
use Symfony\Components\DependencyInjection\Definition;
$t = new LimeTest(21);
// __construct()
$t->diag('__construct()');
$def = new Definition('stdClass');
$t->is($def->getClass(), 'stdClass', '__construct() takes the class name as its first argument');
$def = new Definition('stdClass', array('foo'));
$t->is($def->getArguments(), array('foo'), '__construct() takes an optional array of arguments as its second argument');
// ->setConstructor() ->getConstructor()
$t->diag('->setConstructor() ->getConstructor()');
$def = new Definition('stdClass');
$t->is(spl_object_hash($def->setConstructor('foo')), spl_object_hash($def), '->setConstructor() implements a fluent interface');
$t->is($def->getConstructor(), 'foo', '->getConstructor() returns the constructor name');
// ->setClass() ->getClass()
$t->diag('->setClass() ->getClass()');
$def = new Definition('stdClass');
$t->is(spl_object_hash($def->setClass('foo')), spl_object_hash($def), '->setClass() implements a fluent interface');
$t->is($def->getClass(), 'foo', '->getClass() returns the class name');
// ->setArguments() ->getArguments() ->addArgument()
$t->diag('->setArguments() ->getArguments() ->addArgument()');
$def = new Definition('stdClass');
Beispiel #24
0
/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../../bootstrap.php';
use Symfony\Components\CLI\Input\ArrayInput;
use Symfony\Components\CLI\Input\Definition;
use Symfony\Components\CLI\Input\Argument;
use Symfony\Components\CLI\Input\Option;
$t = new LimeTest(19);
// __construct()
$t->diag('__construct()');
$input = new ArrayInput(array('name' => 'foo'), new Definition(array(new Argument('name'))));
$t->is($input->getArgument('name'), 'foo', '->__construct() takes a Definition as an argument');
// ->getOption() ->setOption() ->getOptions()
$t->diag('->getOption() ->setOption() ->getOptions()');
$input = new ArrayInput(array('--name' => 'foo'), new Definition(array(new Option('name'))));
$t->is($input->getOption('name'), 'foo', '->getOption() returns the value for the given option');
$input->setOption('name', 'bar');
$t->is($input->getOption('name'), 'bar', '->setOption() sets the value for a given option');
$t->is($input->getOptions(), array('name' => 'bar'), '->getOptions() returns all option values');
$input = new ArrayInput(array('--name' => 'foo'), new Definition(array(new Option('name'), new Option('bar', '', Option::PARAMETER_OPTIONAL, '', 'default'))));
$t->is($input->getOption('bar'), 'default', '->getOption() returns the default value for optional options');
$t->is($input->getOptions(), array('name' => 'foo', 'bar' => 'default'), '->getOptions() returns all option values, even optional ones');
try {
    $input->setOption('foo', 'bar');
    $t->fail('->setOption() throws a \\InvalidArgumentException if the option does not exist');
Beispiel #25
0
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../bootstrap.php';
use Symfony\Components\Yaml\Yaml;
use Symfony\Components\Yaml\Inline;
Yaml::setSpecVersion('1.1');
$t = new LimeTest(124);
// ::load()
$t->diag('::load()');
$testsForLoad = array('' => '', 'null' => null, 'false' => false, 'true' => true, '12' => 12, '"quoted string"' => 'quoted string', "'quoted string'" => 'quoted string', '12.30e+02' => 1230.0, '0x4D2' => 0x4d2, '02333' => 02333, '.Inf' => -log(0), '-.Inf' => log(0), '123456789123456789' => '123456789123456789', '"foo\\r\\nbar"' => "foo\r\nbar", "'foo#bar'" => 'foo#bar', "'foo # bar'" => 'foo # bar', "'#cfcfcf'" => '#cfcfcf', '2007-10-30' => mktime(0, 0, 0, 10, 30, 2007), '2007-10-30T02:59:43Z' => gmmktime(2, 59, 43, 10, 30, 2007), '2007-10-30 02:59:43 Z' => gmmktime(2, 59, 43, 10, 30, 2007), '"a \\"string\\" with \'quoted strings inside\'"' => 'a "string" with \'quoted strings inside\'', "'a \"string\" with ''quoted strings inside'''" => 'a "string" with \'quoted strings inside\'', '[foo, http://urls.are/no/mappings, false, null, 12]' => array('foo', 'http://urls.are/no/mappings', false, null, 12), '[  foo  ,   bar , false  ,  null     ,  12  ]' => array('foo', 'bar', false, null, 12), '[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'), '{foo:bar,bar:foo,false:false,null:null,integer:12}' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), '{ foo  : bar, bar : foo,  false  :   false,  null  :   null,  integer :  12  }' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), '{foo: \'bar\', bar: \'foo: bar\'}' => array('foo' => 'bar', 'bar' => 'foo: bar'), '{\'foo\': \'bar\', "bar": \'foo: bar\'}' => array('foo' => 'bar', 'bar' => 'foo: bar'), '{\'foo\'\'\': \'bar\', "bar\\"": \'foo: bar\'}' => array('foo\'' => 'bar', "bar\"" => 'foo: bar'), '{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}' => array('foo: ' => 'bar', "bar: " => 'foo: bar'), '[foo, [bar, foo]]' => array('foo', array('bar', 'foo')), '[foo, {bar: foo}]' => array('foo', array('bar' => 'foo')), '{ foo: {bar: foo} }' => array('foo' => array('bar' => 'foo')), '{ foo: [bar, foo] }' => array('foo' => array('bar', 'foo')), '[  foo, [  bar, foo  ]  ]' => array('foo', array('bar', 'foo')), '[{ foo: {bar: foo} }]' => array(array('foo' => array('bar' => 'foo'))), '[foo, [bar, [foo, [bar, foo]], foo]]' => array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo')), '[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]' => array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo'))), '[foo, bar: { foo: bar }]' => array('foo', '1' => array('bar' => array('foo' => 'bar'))));
foreach ($testsForLoad as $yaml => $value) {
    $t->is(Inline::load($yaml), $value, sprintf('::load() converts an inline YAML to a PHP structure (%s)', $yaml));
}
$testsForDump = array('null' => null, 'false' => false, 'true' => true, '12' => 12, "'quoted string'" => 'quoted string', '12.30e+02' => 1230.0, '1234' => 0x4d2, '1243' => 02333, '.Inf' => -log(0), '-.Inf' => log(0), '"foo\\r\\nbar"' => "foo\r\nbar", "'foo#bar'" => 'foo#bar', "'foo # bar'" => 'foo # bar', "'#cfcfcf'" => '#cfcfcf', "'a \"string\" with ''quoted strings inside'''" => 'a "string" with \'quoted strings inside\'', '[foo, bar, false, null, 12]' => array('foo', 'bar', false, null, 12), '[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'), '{ foo: bar, bar: foo, \'false\': false, \'null\': null, integer: 12 }' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), '{ foo: bar, bar: \'foo: bar\' }' => array('foo' => 'bar', 'bar' => 'foo: bar'), '[foo, [bar, foo]]' => array('foo', array('bar', 'foo')), '[foo, [bar, [foo, [bar, foo]], foo]]' => array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo')), '{ foo: { bar: foo } }' => array('foo' => array('bar' => 'foo')), '[foo, { bar: foo }]' => array('foo', array('bar' => 'foo')), '[foo, { bar: foo, foo: [foo, { bar: foo }] }, [foo, { bar: foo }]]' => array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo'))));
// ::dump()
$t->diag('::dump()');
foreach ($testsForDump as $yaml => $value) {
    $t->is(Inline::dump($value), $yaml, sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml));
}
foreach ($testsForLoad as $yaml => $value) {
    if ($value == 1230) {
        continue;
    }
    $t->is(Inline::load(Inline::dump($value)), $value, 'check consistency');
    }

    return false;
  }
}

class CompilableTemplateLoader extends ProjectTemplateLoaderVar implements CompilableLoaderInterface
{
  public function compile($template)
  {
    return preg_replace('/{{\s*([a-zA-Z0-9_]+)\s*}}/', '<?php echo $$1 ?>', $template);
  }
}

// __construct()
$t->diag('__construct()');
$loader = new ProjectTemplateLoader($varLoader = new ProjectTemplateLoaderVar(), sys_get_temp_dir());
$t->ok($loader->getLoader() === $varLoader, '__construct() takes a template loader as its first argument');
$t->is($loader->getDir(), sys_get_temp_dir(), '__construct() takes a directory where to store the cache as its second argument');

// ->load()
$t->diag('->load()');

$dir = sys_get_temp_dir().DIRECTORY_SEPARATOR.rand(111111, 999999);
mkdir($dir, 0777, true);

$loader = new ProjectTemplateLoader($varLoader = new ProjectTemplateLoaderVar(), $dir);
$loader->setDebugger($debugger = new ProjectTemplateDebugger());
$t->ok($loader->load('foo') === false, '->load() returns false if the embed loader is not able to load the template');
$loader->load('index');
$t->ok($debugger->hasMessage('Storing template'), '->load() logs a "Storing template" message if the template is found');
 */

require_once __DIR__.'/../../../bootstrap.php';

use Symfony\Components\DependencyInjection\Builder;
use Symfony\Components\DependencyInjection\BuilderConfiguration;
use Symfony\Components\DependencyInjection\Definition;
use Symfony\Components\DependencyInjection\Reference;
use Symfony\Components\DependencyInjection\FileResource;

$fixturesPath = __DIR__.'/../../../../fixtures/Symfony/Components/DependencyInjection/';

$t = new LimeTest(39);

// __construct()
$t->diag('__construct()');
$definitions = array(
  'foo' => new Definition('FooClass'),
  'bar' => new Definition('BarClass'),
);
$parameters = array(
  'foo' => 'foo',
  'bar' => 'bar',
);
$configuration = new BuilderConfiguration($definitions, $parameters);
$t->is($configuration->getDefinitions(), $definitions, '__construct() takes an array of definitions as its first argument');
$t->is($configuration->getParameters(), $parameters, '__construct() takes an array of parameters as its second argument');

// ->merge()
$t->diag('->merge()');
$configuration = new BuilderConfiguration();
    public $title = '<strong>escaped!</strong>';
    public function getTitle()
    {
        return $this->title;
    }
    public function getTitleTitle()
    {
        $o = new self();
        return $o->getTitle();
    }
}
class OutputEscaperTestClassChild extends OutputEscaperTestClass
{
}
// ::escape()
$t->diag('::escape()');
$t->diag('::escape() does not escape special values');
$t->ok(Escaper::escape('esc_entities', null) === null, '::escape() returns null if the value to escape is null');
$t->ok(Escaper::escape('esc_entities', false) === false, '::escape() returns false if the value to escape is false');
$t->ok(Escaper::escape('esc_entities', true) === true, '::escape() returns true if the value to escape is true');
$t->diag('::escape() does not escape a value when escaping method is ESC_RAW');
$t->is(Escaper::escape('esc_raw', '<strong>escaped!</strong>'), '<strong>escaped!</strong>', '::escape() takes an escaping strategy function name as its first argument');
$t->diag('::escape() escapes strings');
$t->is(Escaper::escape('esc_entities', '<strong>escaped!</strong>'), '&lt;strong&gt;escaped!&lt;/strong&gt;', '::escape() returns an escaped string if the value to escape is a string');
$t->is(Escaper::escape('esc_entities', '<strong>échappé</strong>'), '&lt;strong&gt;&eacute;chapp&eacute;&lt;/strong&gt;', '::escape() returns an escaped string if the value to escape is a string');
$t->diag('::escape() escapes arrays');
$input = array('foo' => '<strong>escaped!</strong>', 'bar' => array('foo' => '<strong>escaped!</strong>'));
$output = Escaper::escape('esc_entities', $input);
$t->ok($output instanceof ArrayDecorator, '::escape() returns a ArrayDecorator object if the value to escape is an array');
$t->is($output['foo'], '&lt;strong&gt;escaped!&lt;/strong&gt;', '::escape() escapes all elements of the original array');
$t->is($output['bar']['foo'], '&lt;strong&gt;escaped!&lt;/strong&gt;', '::escape() is recursive');
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../../bootstrap.php';
use Symfony\Components\DependencyInjection\Builder;
use Symfony\Components\DependencyInjection\Dumper\GraphvizDumper;
$t = new LimeTest(4);
$fixturesPath = __DIR__ . '/../../../../../fixtures/Symfony/Components/DependencyInjection/';
// ->dump()
$t->diag('->dump()');
$dumper = new GraphvizDumper($container = new Builder());
$t->is($dumper->dump(), file_get_contents($fixturesPath . '/graphviz/services1.dot'), '->dump() dumps an empty container as an empty dot file');
$container = new Builder();
$dumper = new GraphvizDumper($container);
$container = (include $fixturesPath . '/containers/container9.php');
$dumper = new GraphvizDumper($container);
$t->is($dumper->dump(), str_replace('%path%', __DIR__, file_get_contents($fixturesPath . '/graphviz/services9.dot')), '->dump() dumps services');
$container = (include $fixturesPath . '/containers/container10.php');
$dumper = new GraphvizDumper($container);
$t->is($dumper->dump(), str_replace('%path%', __DIR__, file_get_contents($fixturesPath . '/graphviz/services10.dot')), '->dump() dumps services');
$container = (include $fixturesPath . '/containers/container10.php');
$dumper = new GraphvizDumper($container);
$t->is($dumper->dump(array('graph' => array('ratio' => 'normal'), 'node' => array('fontsize' => 13, 'fontname' => 'Verdana', 'shape' => 'square'), 'edge' => array('fontsize' => 12, 'fontname' => 'Verdana', 'color' => 'white', 'arrowhead' => 'closed', 'arrowsize' => 1), 'node.instance' => array('fillcolor' => 'green', 'style' => 'empty'), 'node.definition' => array('fillcolor' => 'grey'), 'node.missing' => array('fillcolor' => 'red', 'style' => 'empty'))), str_replace('%path%', __DIR__, file_get_contents($fixturesPath . '/graphviz/services10-1.dot')), '->dump() dumps services');
Beispiel #30
0
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../bootstrap.php';
use Symfony\Components\CLI\Application;
use Symfony\Components\CLI\Input\ArrayInput;
use Symfony\Components\CLI\Output\Output;
use Symfony\Components\CLI\Output\StreamOutput;
use Symfony\Components\CLI\Tester\ApplicationTester;
$fixtures = __DIR__ . '/../../../../fixtures/Symfony/Components/CLI';
require_once $fixtures . '/FooCommand.php';
require_once $fixtures . '/Foo1Command.php';
require_once $fixtures . '/Foo2Command.php';
$t = new LimeTest(52);
// __construct()
$t->diag('__construct()');
$application = new Application('foo', 'bar');
$t->is($application->getName(), 'foo', '__construct() takes the application name as its first argument');
$t->is($application->getVersion(), 'bar', '__construct() takes the application version as its first argument');
$t->is(array_keys($application->getCommands()), array('help', 'list'), '__construct() registered the help and list commands by default');
// ->setName() ->getName()
$t->diag('->setName() ->getName()');
$application = new Application();
$application->setName('foo');
$t->is($application->getName(), 'foo', '->setName() sets the name of the application');
// ->getVersion() ->getVersion()
$t->diag('->getVersion() ->getVersion()');
$application = new Application();
$application->setVersion('bar');
$t->is($application->getVersion(), 'bar', '->setVersion() sets the version of the application');
// ->getLongVersion()