Ejemplo n.º 1
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');
$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();
$configuration->merge(null);
$t->is($configuration->getParameters(), array(), '->merge() accepts null as an argument');
$t->is($configuration->getDefinitions(), array(), '->merge() accepts null as an argument');

$configuration = new BuilderConfiguration(array(), array('bar' => 'foo'));
$configuration1 = new BuilderConfiguration(array(), array('foo' => 'bar'));
$configuration->merge($configuration1);
$t->is($configuration->getParameters(), array('bar' => 'foo', 'foo' => 'bar'), '->merge() merges current parameters with the loaded ones');

$configuration = new BuilderConfiguration(array(), array('bar' => 'foo', 'foo' => 'baz'));
<?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');
<?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');
Ejemplo n.º 5
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\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');
}
foreach ($testsForDump as $yaml => $value) {
    if ($value == 1230) {
Ejemplo n.º 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\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() ');
$sc = new Container(array('foo' => 'bar'));
Ejemplo n.º 7
0
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');
Ejemplo n.º 8
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\DependencyInjection\Builder;
use Symfony\Components\DependencyInjection\Loader\IniFileLoader;

$t = new LimeTest(3);

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

$loader = new IniFileLoader($fixturesPath.'/ini');
$config = $loader->load('parameters.ini');
$t->is($config->getParameters(), array('foo' => 'bar', 'bar' => '%foo%'), '->load() takes a single file name as its first argument');

try
{
  $loader->load('foo.ini');
  $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->load('nonvalid.ini');
  $t->fail('->load() throws an InvalidArgumentException if the loaded file is not parseable');
 * 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')));
$fooFilter = new FooFilter();
$barFilter = new BarFilter();
$bazFilter = new BazFilter();
// @After
unset($fooFilter);
unset($barFilter);
unset($bazFilter);
// @Test: ->getFilters()
$fc = new Sonata_FilterChain();
$t->ok(is_array($fc->getFilters()) && count($fc->getFilters()) == 0, 'The method returns the empty filters array');
// @Test: ->addFilter()
$fc = new Sonata_FilterChain();
$fc->addFilter($fooFilter);
$fc->addFilter($barFilter);
$fc->addFilter($bazFilter);
$t->is($fc->getFilters(), array($fooFilter, $barFilter, $bazFilter), 'All filters were added correctly');
// @Test: ->processFilters()
$request = new Sonata_Request();
$response = new Sonata_Response();
$fooFilter = $t->mock('FooFilter');
$fooFilter->execute($request, $response)->once();
$fooFilter->replay();
$barFilter = $t->mock('BarFilter');
$barFilter->execute($request, $response)->once();
$barFilter->replay();
$bazFilter = $t->mock('BazFilter');
$bazFilter->execute($request, $response)->once();
$bazFilter->replay();
$fc = new Sonata_FilterChain();
$fc->addFilter($fooFilter);
$fc->addFilter($barFilter);
}
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 {
    $loader->getFilesAsXml(array('nonvalid.xml'));
    $t->fail('->load() throws an InvalidArgumentException if the loaded file does not validate the XSD');
} catch (InvalidArgumentException $e) {
    $t->pass('->load() throws an InvalidArgumentException if the loaded file does not validate the XSD');
}
$xmls = $loader->getFilesAsXml(array('services1.xml'));
$t->is(count($xmls), 1, '->getFilesAsXml() returns an array of simple xml objects');
$t->is(key($xmls), realpath($fixturesPath . '/xml/services1.xml'), '->getFilesAsXml() returns an array where the keys are absolutes paths to the original XML file');
$t->is(get_class(current($xmls)), 'Symfony\\Components\\DependencyInjection\\SimpleXMLElement', '->getFilesAsXml() returns an array where values are SimpleXMLElement objects');
// ->load() # parameters
$t->diag('->load() # parameters');
$loader = new ProjectLoader($fixturesPath . '/xml');
$config = $loader->load(array('services2.xml'));
$t->is($config->getParameters(), array('a string', 'foo' => 'bar', 'values' => array(0, 'integer' => 4, 100 => null, 'true', true, false, 'on', 'off', 'float' => 1.3, 1000.3, 'a string', array('foo', 'bar')), 'foo_bar' => new Reference('foo_bar')), '->load() converts XML values to PHP ones');
$loader = new ProjectLoader($fixturesPath . '/xml');
$config = $loader->load(array('services2.xml', 'services3.xml'));
$t->is($config->getParameters(), array('a string', 'foo' => 'foo', 'values' => array(true, false), 'foo_bar' => new Reference('foo_bar')), '->load() merges the first level of arguments when multiple files are loaded');
// ->load() # imports
$t->diag('->load() # imports');
$config = $loader->load(array('services4.xml'));
$t->is($config->getParameters(), array('a string', 'foo' => 'bar', 'bar' => '%foo%', 'values' => array(true, false), 'foo_bar' => new Reference('foo_bar')), '->load() imports and merges imported files');
// ->load() # anonymous services
fputs($fh, '<?php class Sonata_Pass {} ?>');
fclose($fh);
mkdir(dirname(__FILE__) . '/../../src/Pass');
$fh = fopen(dirname(__FILE__) . '/../../src/Pass/Nested.class.php', 'wb');
fputs($fh, '<?php class Sonata_Pass_Nested {} ?>');
fclose($fh);
$fh = fopen(dirname(__FILE__) . '/../../src/Fail.php', 'wb');
fputs($fh, '<?php class Sonata_Fail {} ?>');
fclose($fh);
$fh = fopen(dirname(__FILE__) . '/../fixtures/Extra.class.php', 'wb');
fputs($fh, '<?php class Extra {} ?>');
fclose($fh);
// @Before
$autoloader = new Sonata_Autoloader();
// @AfterAll
unlink(dirname(__FILE__) . '/../../src/Foo.class.php');
unlink(dirname(__FILE__) . '/../../src/Pass.class.php');
unlink(dirname(__FILE__) . '/../../src/Pass/Nested.class.php');
rmdir(dirname(__FILE__) . '/../../src/Pass');
unlink(dirname(__FILE__) . '/../../src/Fail.php');
unlink(dirname(__FILE__) . '/../fixtures/Extra.class.php');
// @Test: ->autoload() loads class files by class name
$t->is($autoloader->autoload('Sonata_Pass'), true, 'Returns true if a class can be loaded');
$t->is($autoloader->autoload('Sonata_Pass_Nested'), true, 'Still works for more nested classes');
$t->is($autoloader->autoload('Sonata_Fail'), false, 'Returns false if the class filename does not end with \'.class.php\'');
$t->is($autoloader->autoload('Foo'), false, 'Returns false if the class name does not start with \'Sonata\'');
$t->is($autoloader->autoload('Sonata_Not_Here'), false, 'Returns false for non-existing classes');
// @Test: ::extend() registers extra directories for autoloading
$t->is($autoloader->autoload('Extra'), false, 'The \'Extra\' class cannot be autoloaded because its path isn\'t registered for autoloading');
Sonata_Autoloader::extend(array(dirname(__FILE__) . '/../fixtures'));
$t->is($autoloader->autoload('Extra'), true, 'The \'Extra\' class is now autoloaded correctly');
Ejemplo n.º 13
0
$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']);
        }
    }
}
// test tabs in YAML
$yamls = array("foo:\n\tbar", "foo:\n \tbar", "foo:\n\t bar", "foo:\n \t bar");
foreach ($yamls as $yaml) {
    try {
        $content = $parser->parse($yaml);
        $t->fail('YAML files must not contain tabs');
    } catch (ParserException $e) {
        $t->pass('YAML files must not contain tabs');
    }
}
// objects
$t->diag('Objects support');
<?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');
Ejemplo n.º 15
0
  try
  {
    $loader->loadFile($fixture.'.yml');
    $t->fail('->load() throws an InvalidArgumentException if the loaded file does not validate');
  }
  catch (InvalidArgumentException $e)
  {
    $t->pass('->load() throws an InvalidArgumentException if the loaded file does not validate');
  }
}

// ->load() # parameters
$t->diag('->load() # parameters');
$loader = new ProjectLoader($fixturesPath.'/yaml');
$config = $loader->load('services2.yml');
$t->is($config->getParameters(), array('foo' => 'bar', 'values' => array(true, false, 0, 1000.3), 'bar' => 'foo', 'foo_bar' => new Reference('foo_bar')), '->load() converts YAML keys to lowercase');

// ->load() # imports
$t->diag('->load() # imports');
$config = $loader->load('services4.yml');
$t->is($config->getParameters(), array('foo' => 'bar', 'bar' => '%foo%', 'values' => array(true, false), 'foo_bar' => new Reference('foo_bar'), 'imported_from_xml' => true, 'imported_from_ini' => true), '->load() imports and merges imported files');

// ->load() # services
$t->diag('->load() # services');
$config = $loader->load('services6.yml');
$services = $config->getDefinitions();
$t->ok(isset($services['foo']), '->load() parses service elements');
$t->is(get_class($services['foo']), 'Symfony\\Components\\DependencyInjection\\Definition', '->load() converts service element to Definition instances');
$t->is($services['foo']->getClass(), 'FooClass', '->load() parses the class attribute');
$t->ok($services['shared']->isShared(), '->load() parses the shared attribute');
$t->ok(!$services['non_shared']->isShared(), '->load() parses the shared attribute');
Ejemplo n.º 16
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\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()
$t->diag('->getVersion() ->getVersion()');
Ejemplo n.º 17
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\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) {
    $t->pass('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
}
// ->register()
$t->diag('->register()');
// 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');
    unlink($tmp);
    $t->is(serialize($container1), serialize($container2), 'loading a dump from a previously loaded container returns the same container');
    $t->is($container1->getParameters(), $container2->getParameters(), '->getParameters() returns the same value for both containers');
    $services1 = array();
    foreach ($container1 as $id => $service) {
        $services1[$id] = serialize($service);
    }
    $services2 = array();
    foreach ($container2 as $id => $service) {
        $services2[$id] = serialize($service);
    }
    unset($services1['service_container'], $services2['service_container']);
    $t->is($services1, $services2, 'Iterator on the containers returns the same services');
}
Ejemplo n.º 19
0
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');

// ->addArguments()
$t->diag('->addArguments()');
Ejemplo n.º 20
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');
} catch (\InvalidArgumentException $e) {
    $t->pass('->setOption() throws a \\InvalidArgumentException if the option does not exist');
Ejemplo n.º 21
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');
Ejemplo n.º 22
0
  }
}

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');
$loader->load('index');
$t->ok($debugger->hasMessage('Fetching template'), '->load() logs a "Storing template" message if the template is fetched from cache');
Ejemplo n.º 23
0
$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');

// ->getStream()
$t->diag('->getStream()');
$output = new StreamOutput($stream);
$t->is($output->getStream(), $stream, '->getStream() returns the current stream');

// ->doWrite()
$t->diag('->doWrite()');
$output = new StreamOutput($stream);
$output->writeln('foo');
rewind($output->getStream());
$t->is(stream_get_contents($output->getStream()), "foo\n", '->doWrite() writes to the stream');
Ejemplo n.º 24
0
<?php

/**
 * This file is part of the Sonata RESTful PHP framework
 * (c) 2009-2010 Pascal Cremer <*****@*****.**>
 *
 * @author Pascal Cremer <*****@*****.**>
 */
require_once dirname(__FILE__) . '/bootstrap.php';
$t = new LimeTest();
// @Test: ::camelize()
$t->is(Sonata_Utils::camelize('foo_bar_baz'), 'FooBarBaz', 'The string was camelized correctly');
$t->is(Sonata_Utils::camelize('foo_bar_baz', true), 'fooBarBaz', 'The string was camelized correctly, starting lower-case');
$t->is(Sonata_Utils::camelize('foo _ bar _baz'), 'FooBarBaz', 'Whitespaces are ignored');
$t->is(Sonata_Utils::camelize(''), '', 'Empty strings are retuned untouched');
// @Test: ::underscore()
$t->is(Sonata_Utils::underscore('FooBar'), 'foo_bar', 'The string was underscored correctly');
$t->is(Sonata_Utils::underscore('myFooBar'), 'my_foo_bar', 'It even works for camelized strings that start lower-case');
$t->is(Sonata_Utils::underscore('Foo Bar-!/#Baz'), 'foo_bar_baz', 'Whitespaces and non-digit characters are ignored');
$t->is(Sonata_Utils::underscore(''), '', 'Empty strings are retuned untouched');
// @Test: ::slugify()
$t->is(Sonata_Utils::slugify('Here be dragons!'), 'here-be-dragons', 'The string was slugified correctly');
$t->is(Sonata_Utils::slugify('Hérè be drägons!'), 'here-be-dragons', 'Transforms UTF-8 characters correctly');
$t->is(Sonata_Utils::slugify(''), 'n-a', '\'n-a\' is returned for empty strings');
    {
        $this->foo = $foo;
    }
    public function get()
    {
        return $this->foo;
    }
}
// @Before
$paramHolder = new Sonata_ParameterHolder();
$paramHolder->add($params = array('foo' => 42, 'bar' => 4711, 'baz' => new Foo()));
// @After
unset($paramHolder);
unset($params);
// @Test: ->add()
$t->is($paramHolder->getAll(), $params, 'All parameters were added correctly');
$paramHolder->add(null);
$t->isnt($paramHolder->getAll(), null, 'Nothing is added if NULL was given');
$paramHolder->add(array());
$t->isntSame($paramHolder->getAll(), array(), 'Nothing is added if an empty array was given');
$paramHolder->add('this fails');
$t->isnt($paramHolder->getAll(), 'this fails', 'Nothing is added if parameter isn\'t an array');
// @Test: ->get()
$foo = $paramHolder->get('foo');
$t->is($foo, 42, 'The value is retrieved correctly');
$rex = $paramHolder->get('rex');
$t->is($rex, null, 'NULL is returned if the parameter could not be found');
$rex = $paramHolder->get('rex', 'fido');
$t->is($rex, 'fido', 'If a default value is given for a non-existing parameter, the default value is returned');
// @Test: ->getNames()
$t->same($paramHolder->getNames(), array('foo', 'bar', 'baz'), 'All parameter names are retrieved correctly');
Ejemplo n.º 26
0
    {
        $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');
$t->is($output->getRawValue(), $input, '->getRawValue() returns the unescaped value');
$t->diag('::escape() escapes objects');
$input = new OutputEscaperTestClass();
$output = Escaper::escape('esc_entities', $input);
$t->ok($output instanceof ObjectDecorator, '::escape() returns a ObjectDecorator object if the value to escape is an object');
$t->is($output->getTitle(), '&lt;strong&gt;escaped!&lt;/strong&gt;', '::escape() escapes all methods of the original 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\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');
$t->is($dispatcher->hasListeners('foo'), false, '->hasListeners() returns false if the event has no listener');
$t->is($dispatcher->getListeners('bar'), array('listenToBar'), '->getListeners() returns an array of listeners connected to the given event name');
Ejemplo n.º 28
0
  }
}

// ->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()
$t->diag('->load()');
$loader = new ProjectTemplateLoader($pathPattern);
$storage = $loader->load($path.'/foo.php');
$t->ok($storage instanceof FileStorage, '->load() returns a FileStorage if you pass an absolute path');
$t->is((string) $storage, $path.'/foo.php', '->load() returns a FileStorage pointing to the passed absolute path');

$t->ok($loader->load('bar') === false, '->load() returns false if the template is not found');

$storage = $loader->load('foo');
$t->ok($storage instanceof FileStorage, '->load() returns a FileStorage if you pass a relative template that exists');
$t->is((string) $storage, $path.'/foo.php', '->load() returns a FileStorage pointing to the absolute path of the template');
/**
 * This file is part of the Sonata RESTful PHP framework
 * (c) 2009-2010 Pascal Cremer <*****@*****.**>
 *
 * @author Pascal Cremer <*****@*****.**>
 */
require_once dirname(__FILE__) . '/bootstrap.php';
$t = new LimeTest();
// @Before
$templateView = new Sonata_TemplateView();
// @After
unset($templateView);
// @Test: ->assign() - with single arguments
$templateView->assign('foo', 42);
$templateView->assign('bar', 4711);
$t->is($templateView->getTemplateVars(), array('foo' => 42, 'bar' => 4711), 'Template vars are assigned correctly (single)');
// @Test: ->assign() - with array as argument
$templateView->assign(array('foo' => 42, 'bar' => 4711));
$t->is($templateView->getTemplateVars(), array('foo' => 42, 'bar' => 4711), 'Template vars are assigned correctly (array)');
// @Test: ->__get()
$templateView->assign('foo', 42);
$t->is($templateView->foo, 42, 'Template vars retrieved correctly via PHP\'s magic \'__get\' method');
// @Test: ->render()
// @Test: non-existing templates
$templateView->setDir(dirname(__FILE__) . '/../fixtures/templates');
try {
    $templateView->render('foo', 'article', 'xml');
    $t->fail('No code should be executed after this');
} catch (Sonata_Exception_Template $ex) {
    $t->pass('Throws an exception for non-existing templates');
}
<?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');