<?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\Storage\Storage; use Symfony\Components\Templating\Storage\StringStorage; $t = new LimeTest(2); $storage = new StringStorage('foo'); $t->ok($storage instanceof Storage, 'StringStorage is an instance of Storage'); // ->getContent() $t->diag('->getContent()'); $storage = new StringStorage('foo'); $t->is($storage->getContent(), 'foo', '->getContent() returns the content of the template');
* 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()'); $builder = new Builder();
$t->is($configuration->getParameter('FOO'), 'baz1', '->getParameter() converts the key to lowercase'); try { $configuration->getParameter('baba'); $t->fail('->getParameter() throws an \InvalidArgumentException if the key does not exist'); } catch (\InvalidArgumentException $e) { $t->pass('->getParameter() throws an \InvalidArgumentException if the key does not exist'); } // ->hasParameter() $t->diag('->hasParameter()'); $configuration = new BuilderConfiguration(array(), array('foo' => 'bar')); $t->ok($configuration->hasParameter('foo'), '->hasParameter() returns true if a parameter is defined'); $t->ok($configuration->hasParameter('Foo'), '->hasParameter() converts the key to lowercase'); $t->ok(!$configuration->hasParameter('bar'), '->hasParameter() returns false if a parameter is not defined'); // ->addParameters() $t->diag('->addParameters()'); $configuration = new BuilderConfiguration(array(), array('foo' => 'bar')); $configuration->addParameters(array('bar' => 'foo')); $t->is($configuration->getParameters(), array('foo' => 'bar', 'bar' => 'foo'), '->addParameters() adds parameters to the existing ones'); $configuration->addParameters(array('Bar' => 'fooz')); $t->is($configuration->getParameters(), array('foo' => 'bar', 'bar' => 'fooz'), '->addParameters() converts keys to lowercase'); // ->setAlias() ->getAlias() ->hasAlias() ->getAliases() ->addAliases() $t->diag('->setAlias() ->getAlias() ->hasAlias()'); $configuration = new BuilderConfiguration(); $configuration->setAlias('bar', 'foo');
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'); $loader->load('index'); $t->ok($debugger->hasMessage('Fetching template'), '->load() logs a "Storing template" message if the template is fetched from cache');
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() $t->diag('->load()');
$executable = new LimeExecutable(LimeExecutable::php() . ' %file%'); $file = tempnam(sys_get_temp_dir(), 'lime'); $output = $t->mock('LimeOutputInterface'); $input = new LimeInputTap($output); // @After $file = null; $output = null; $input = null; // @Test: Successful tests are passed to pass() // fixtures $output->pass('A passed test', '', 0, '', ''); $output->replay(); // test $input->parse("ok 1 - A passed test\n"); // assertions $t->ok($input->done(), 'The input is done'); // @Test: Successful tests without message are passed to pass() // fixtures $output->pass('', '', 0, '', ''); $output->replay(); // test $input->parse("ok 1\n"); // assertions $t->ok($input->done(), 'The input is done'); // @Test: Failed tests are passed to fail() // fixtures $output->fail('A failed test', '', 0, '', ''); $output->replay(); // test $input->parse("not ok 1 - A failed test\n"); // assertions
<?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->is($event->getSubject(), $subject, '->getSubject() returns the event subject'); // ->getName() $t->diag('->getName()'); $t->is($event->getName(), 'name', '->getName() returns the event name'); // ->getParameters() $t->diag('->getParameters()'); $t->is($event->getParameters(), $parameters, '->getParameters() returns the event parameters'); // ->getReturnValue() ->setReturnValue() $t->diag('->getReturnValue() ->setReturnValue()'); $event->setReturnValue('foo'); $t->is($event->getReturnValue(), 'foo', '->getReturnValue() returns the return value of the event'); // ->setProcessed() ->isProcessed() $t->diag('->setProcessed() ->isProcessed()'); $event->setProcessed(true); $t->is($event->isProcessed(), true, '->isProcessed() returns true if the event has been processed'); $event->setProcessed(false); $t->is($event->isProcessed(), false, '->setProcessed() changes the processed status'); // ArrayAccess interface $t->diag('ArrayAccess interface'); $t->is($event['foo'], 'bar', 'Event implements the ArrayAccess interface'); $event['foo'] = 'foo'; $t->is($event['foo'], 'foo', 'Event implements the ArrayAccess interface'); try { $event['foobar']; $t->fail('::offsetGet() throws an \\InvalidArgumentException exception when the parameter does not exist'); } catch (\InvalidArgumentException $e) { $t->pass('::offsetGet() throws an \\InvalidArgumentException exception when the parameter does not exist'); } $t->ok(isset($event['foo']), 'Event implements the ArrayAccess interface'); unset($event['foo']); $t->ok(!isset($event['foo']), 'Event implements the ArrayAccess interface');
$t = new LimeTest(5); class ProjectTemplateLoader extends ChainLoader { public function getLoaders() { return $this->loaders; } } $loader1 = new FilesystemLoader($fixturesPath.'/null/%name%'); $loader2 = new FilesystemLoader($fixturesPath.'/templates/%name%.%renderer%'); // __construct() $t->diag('__construct()'); $loader = new ProjectTemplateLoader(array($loader1, $loader2)); $t->is($loader->getLoaders(), array($loader1, $loader2), '__construct() takes an array of template loaders as its second argument'); // ->addLoader() $t->diag('->addLoader()'); $loader = new ProjectTemplateLoader(array($loader1)); $loader->addLoader($loader2); $t->is($loader->getLoaders(), array($loader1, $loader2), '->addLoader() adds a template loader at the end of the loaders'); // ->load() $t->diag('->load()'); $loader = new ProjectTemplateLoader(array($loader1, $loader2)); $t->ok($loader->load('bar') === false, '->load() returns false if the template is not found'); $t->ok($loader->load('foo', array('renderer' => 'xml')) === false, '->load() returns false if the template does not exists for the given renderer'); $t->ok($loader->load('foo') instanceof FileStorage, '->load() returns a FileStorage if the template exists');
// ->getSubject() $t->diag('->getSubject()'); $t->is($event->getSubject(), $subject, '->getSubject() returns the event subject'); // ->getName() $t->diag('->getName()'); $t->is($event->getName(), 'name', '->getName() returns the event name'); // ->getParameters() ->setParameter() ->hasParameter() ->getParameter() $t->diag('->getParameters()'); $t->is($event->getParameters(), $parameters, '->getParameters() returns the event parameters'); $t->is($event->getParameter('foo'), 'bar', '->getParameter() returns the value of a parameter'); $event->setParameter('foo', 'foo'); $t->is($event->getParameter('foo'), 'foo', '->setParameter() changes the value of a parameter'); $t->ok($event->hasParameter('foo'), '->hasParameter() returns true if the parameter is defined'); unset($event['foo']); $t->ok(!$event->hasParameter('foo'), '->hasParameter() returns false if the parameter is not defined'); try { $event->getParameter('foobar'); $t->fail('->getParameter() throws an \InvalidArgumentException exception when the parameter does not exist'); } catch (\InvalidArgumentException $e) { $t->pass('->getParameter() throws an \InvalidArgumentException exception when the parameter does not exist'); } $event = new Event($subject, 'name', $parameters); // ->getReturnValue() ->setReturnValue()
$loader->getFilesAsArray(array('parameters.ini')); $t->fail('->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file'); } catch (InvalidArgumentException $e) { $t->pass('->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file'); } $loader = new ProjectLoader($fixturesPath . '/yaml'); foreach (array('nonvalid1', 'nonvalid2') as $fixture) { try { $loader->getFilesAsArray(array($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'); } } $yamls = $loader->getFilesAsArray(array('services1.yml')); $t->ok(is_array($yamls), '->getFilesAsArray() returns an array'); $t->is(key($yamls), realpath($fixturesPath . '/yaml/services1.yml'), '->getFilesAsArray() returns an array where the keys are absolutes paths to the original YAML file'); // ->load() # parameters $t->diag('->load() # parameters'); $loader = new ProjectLoader($fixturesPath . '/yaml'); $config = $loader->load(array('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'); $loader = new ProjectLoader($fixturesPath . '/yaml'); $config = $loader->load(array('services2.yml', 'services3.yml')); $t->is($config->getParameters(), array('foo' => 'foo', 'values' => array(true, false), 'bar' => 'foo', '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.yml')); $t->is($config->getParameters(), array('foo' => 'bar', 'bar' => '%foo%', 'values' => array(true, false), 'foo_bar' => new Reference('foo_bar')), '->load() imports and merges imported files'); // ->load() # services $t->diag('->load() # services');
$t->is($option->isParameterRequired(), true, '__construct() can take "Option::PARAMETER_REQUIRED" as its mode'); $t->is($option->isParameterOptional(), false, '__construct() can take "Option::PARAMETER_REQUIRED" as its mode'); $option = new Option('foo', 'f', Option::PARAMETER_OPTIONAL); $t->is($option->acceptParameter(), true, '__construct() can take "Option::PARAMETER_OPTIONAL" as its mode'); $t->is($option->isParameterRequired(), false, '__construct() can take "Option::PARAMETER_OPTIONAL" as its mode'); $t->is($option->isParameterOptional(), true, '__construct() can take "Option::PARAMETER_OPTIONAL" as its mode'); try { $option = new Option('foo', 'f', 'ANOTHER_ONE'); $t->fail('__construct() throws an Exception if the mode is not valid'); } catch (\Exception $e) { $t->pass('__construct() throws an Exception if the mode is not valid'); } // ->isArray() $t->diag('->isArray()'); $option = new Option('foo', null, Option::PARAMETER_OPTIONAL | Option::PARAMETER_IS_ARRAY); $t->ok($option->isArray(), '->isArray() returns true if the option can be an array'); $option = new Option('foo', null, Option::PARAMETER_NONE); $t->ok(!$option->isArray(), '->isArray() returns false if the option can not be an array'); // ->getDescription() $t->diag('->getDescription()'); $option = new Option('foo', 'f', null, 'Some description'); $t->is($option->getDescription(), 'Some description', '->getDescription() returns the description message'); // ->getDefault() $t->diag('->getDefault()'); $option = new Option('foo', null, Option::PARAMETER_OPTIONAL, '', 'default'); $t->is($option->getDefault(), 'default', '->getDefault() returns the default value'); $option = new Option('foo', null, Option::PARAMETER_REQUIRED, '', 'default'); $t->is($option->getDefault(), 'default', '->getDefault() returns the default value'); $option = new Option('foo', null, Option::PARAMETER_REQUIRED); $t->ok(is_null($option->getDefault()), '->getDefault() returns null if no default value is configured'); $option = new Option('foo', null, Option::PARAMETER_OPTIONAL | Option::PARAMETER_IS_ARRAY);
use Symfony\Components\Templating\Engine; use Symfony\Components\Templating\Renderer\Renderer; use Symfony\Components\Templating\Storage\Storage; use Symfony\Components\Templating\Loader\FilesystemLoader; $t = new LimeTest(1); class ProjectTemplateRenderer extends Renderer { public function getEngine() { return $this->engine; } public function evaluate(Storage $template, array $parameters = array()) { } } $loader = new FilesystemLoader(array(__DIR__.'/fixtures/templates/%name%.%renderer%')); $engine = new Engine($loader); $engine->set('foo', 'bar'); $engine->getHelperSet()->set(new SimpleHelper('foo'), 'bar'); // ->setEngine() $t->diag('->setEngine()'); $renderer = new ProjectTemplateRenderer(); $renderer->setEngine($engine); $t->ok($renderer->getEngine() === $engine, '->setEngine() sets the engine instance tied to this renderer');
use Symfony\Components\CLI\Input\Definition; use Symfony\Components\CLI\Input\Argument; use Symfony\Components\CLI\Input\Option; $t = new LimeTest(15); // ->getFirstArgument() $t->diag('->getFirstArgument()'); $input = new ArrayInput(array()); $t->is($input->getFirstArgument(), null, '->getFirstArgument() returns null if no argument were passed'); $input = new ArrayInput(array('name' => 'Fabien')); $t->is($input->getFirstArgument(), 'Fabien', '->getFirstArgument() returns the first passed argument'); $input = new ArrayInput(array('--foo' => 'bar', 'name' => 'Fabien')); $t->is($input->getFirstArgument(), 'Fabien', '->getFirstArgument() returns the first passed argument'); // ->hasParameterOption() $t->diag('->hasParameterOption()'); $input = new ArrayInput(array('name' => 'Fabien', '--foo' => 'bar')); $t->ok($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if an option is present in the passed parameters'); $t->ok(!$input->hasParameterOption('--bar'), '->hasParameterOption() returns false if an option is not present in the passed parameters'); $input = new ArrayInput(array('--foo')); $t->ok($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if an option is present in the passed parameters'); // ->parse() $t->diag('->parse()'); $input = new ArrayInput(array('name' => 'foo'), new Definition(array(new Argument('name')))); $t->is($input->getArguments(), array('name' => 'foo'), '->parse() parses required arguments'); try { $input = new ArrayInput(array('foo' => 'foo'), new Definition(array(new Argument('name')))); $t->fail('->parse() throws an \\InvalidArgumentException exception if an invalid argument is passed'); } catch (\RuntimeException $e) { $t->pass('->parse() throws an \\InvalidArgumentException exception if an invalid argument is passed'); } $input = new ArrayInput(array('--foo' => 'bar'), new Definition(array(new Option('foo')))); $t->is($input->getOptions(), array('foo' => 'bar'), '->parse() parses long options');
* (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');
$t->is($argument->isRequired(), true, '__construct() can take "Argument::PARAMETER_REQUIRED" as its mode'); try { $argument = new InputArgument('foo', 'ANOTHER_ONE'); $t->fail('__construct() throws an Exception if the mode is not valid'); } catch (\Exception $e) { $t->pass('__construct() throws an Exception if the mode is not valid'); } // ->isArray() $t->diag('->isArray()'); $argument = new InputArgument('foo', InputArgument::IS_ARRAY); $t->ok($argument->isArray(), '->isArray() returns true if the argument can be an array'); $argument = new InputArgument('foo', InputArgument::OPTIONAL | InputArgument::IS_ARRAY); $t->ok($argument->isArray(), '->isArray() returns true if the argument can be an array'); $argument = new InputArgument('foo', InputArgument::OPTIONAL); $t->ok(!$argument->isArray(), '->isArray() returns false if the argument can not be an array'); // ->getDescription() $t->diag('->getDescription()'); $argument = new InputArgument('foo', null, 'Some description'); $t->is($argument->getDescription(), 'Some description', '->getDescription() return the message description'); // ->getDefault() $t->diag('->getDefault()'); $argument = new InputArgument('foo', InputArgument::OPTIONAL, '', 'default'); $t->is($argument->getDefault(), 'default', '->getDefault() return the default value');
{ public function execute(Sonata_Request $request, Sonata_Response $response) { } } // @Before $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();
$command = $application->register('foo'); $t->is($command->getName(), 'foo', '->register() regiters a new command'); // ->addCommand() ->addCommands() $t->diag('->addCommand() ->addCommands()'); $application = new Application(); $application->addCommand($foo = new FooCommand()); $commands = $application->getCommands(); $t->is($commands['foo:bar'], $foo, '->addCommand() registers a command'); $application = new Application(); $application->addCommands(array($foo = new FooCommand(), $foo1 = new Foo1Command())); $commands = $application->getCommands(); $t->is(array($commands['foo:bar'], $commands['foo:bar1']), array($foo, $foo1), '->addCommands() registers an array of commands'); // ->hasCommand() ->getCommand() $t->diag('->hasCommand() ->getCommand()'); $application = new Application(); $t->ok($application->hasCommand('list'), '->hasCommand() returns true if a named command is registered'); $t->ok(!$application->hasCommand('afoobar'), '->hasCommand() returns false if a named command is not registered'); $application->addCommand($foo = new FooCommand()); $t->ok($application->hasCommand('afoobar'), '->hasCommand() returns true if an alias is registered'); $t->is($application->getCommand('foo:bar'), $foo, '->getCommand() returns a command by name'); $t->is($application->getCommand('afoobar'), $foo, '->getCommand() returns a command by alias'); try { $application->getCommand('foofoo'); $t->fail('->getCommand() throws an \\InvalidArgumentException if the command does not exist'); } catch (\InvalidArgumentException $e) { $t->pass('->getCommand() throws an \\InvalidArgumentException if the command does not exist'); } class TestApplication extends Application { public function setWantHelps() {
$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 $t->diag('->load() # anonymous services'); $config = $loader->load(array('services5.xml')); $services = $config->getDefinitions(); $t->is(count($services), 3, '->load() attributes unique ids to anonymous services'); $args = $services['foo']->getArguments(); $t->is(count($args), 1, '->load() references anonymous services as "normal" ones'); $t->is(get_class($args[0]), 'Symfony\\Components\\DependencyInjection\\Reference', '->load() converts anonymous services to references to "normal" services'); $t->ok(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones'); $inner = $services[(string) $args[0]]; $t->is($inner->getClass(), 'BarClass', '->load() uses the same configuration as for the anonymous ones'); $args = $inner->getArguments(); $t->is(count($args), 1, '->load() references anonymous services as "normal" ones'); $t->is(get_class($args[0]), 'Symfony\\Components\\DependencyInjection\\Reference', '->load() converts anonymous services to references to "normal" services'); $t->ok(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones'); $inner = $services[(string) $args[0]]; $t->is($inner->getClass(), 'BazClass', '->load() uses the same configuration as for the anonymous ones'); // ->load() # services $t->diag('->load() # services'); $config = $loader->load(array('services6.xml')); $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');
<?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');
} try { $input->getArgument('foo'); $t->fail('->getArgument() throws a \\InvalidArgumentException if the argument does not exist'); } catch (\InvalidArgumentException $e) { $t->pass('->getArgument() throws a \\InvalidArgumentException if the argument does not exist'); } // ->validate() $t->diag('->validate()'); $input = new ArrayInput(array()); $input->bind(new Definition(array(new Argument('name', Argument::REQUIRED)))); try { $input->validate(); $t->fail('->validate() throws a \\RuntimeException if not enough arguments are given'); } catch (\RuntimeException $e) { $t->pass('->validate() throws a \\RuntimeException if not enough arguments are given'); } $input = new ArrayInput(array('name' => 'foo')); $input->bind(new Definition(array(new Argument('name', Argument::REQUIRED)))); try { $input->validate(); $t->pass('->validate() does not throw a \\RuntimeException if enough arguments are given'); } catch (\RuntimeException $e) { $t->fail('->validate() does not throw a \\RuntimeException if enough arguments are given'); } // ->setInteractive() ->isInteractive() $t->diag('->setInteractive() ->isInteractive()'); $input = new ArrayInput(array()); $t->ok($input->isInteractive(), '->isInteractive() returns whether the input should be interactive or not'); $input->setInteractive(false); $t->ok(!$input->isInteractive(), '->setInteractive() changes the interactive flag');
public static function autoload($class) { ++self::$calls; } } spl_autoload_register(array('TestAutoloader', 'autoload')); $t = new LimeTest(); // @Before $m = LimeMock::create('TestClass'); // @After $m = null; // @Test: Interfaces can be mocked // test $m = LimeMock::create('TestInterface'); // assertions $t->ok($m instanceof TestInterface, 'The mock implements the interface'); $t->ok($m instanceof LimeMockInterface, 'The mock implements "LimeMockInterface"'); // @Test: Namespaced interfaces can be mocked (PHP 5.3) if (version_compare(PHP_VERSION, '5.3', '>=')) { require_once __DIR__ . '/php5.3/TestInterface.php'; // test $m = LimeMock::create('TestNamespace\\TestSubNamespace\\TestInterface'); // assertions $interface = 'TestNamespace\\TestSubNamespace\\TestInterface'; $t->ok($m instanceof $interface, 'The mock implements the interface'); $t->ok($m instanceof LimeMockInterface, 'The mock implements "LimeMockInterface"'); } else { $t->skip(); $t->skip(); } // @Test: Abstract classes can be mocked
{ 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>'), '<strong>escaped!</strong>', '::escape() returns an escaped string if the value to escape is a string'); $t->is(Escaper::escape('esc_entities', '<strong>échappé</strong>'), '<strong>échappé</strong>', '::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'], '<strong>escaped!</strong>', '::escape() escapes all elements of the original array'); $t->is($output['bar']['foo'], '<strong>escaped!</strong>', '::escape() is recursive'); $t->is($output->getRawValue(), $input, '->getRawValue() returns the unescaped value'); $t->diag('::escape() escapes objects');
<?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');
// ->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'); $t->is($services['constructor']->getConstructor(), 'getInstance', '->load() parses the constructor attribute'); $t->is($services['file']->getFile(), '%path%/foo.php', '->load() parses the file tag'); $t->is($services['arguments']->getArguments(), array('foo', new Reference('foo'), array(true, false)), '->load() parses the argument tags'); $t->is($services['configurator1']->getConfigurator(), 'sc_configure', '->load() parses the configurator tag'); $t->is($services['configurator2']->getConfigurator(), array(new Reference('baz'), 'configure'), '->load() parses the configurator tag'); $t->is($services['configurator3']->getConfigurator(), array('BazClass', 'configureStatic'), '->load() parses the configurator tag'); $t->is($services['method_call1']->getMethodCalls(), array(array('setBar', array())), '->load() parses the method_call tag'); $t->is($services['method_call2']->getMethodCalls(), array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), '->load() parses the method_call tag'); $aliases = $config->getAliases(); $t->ok(isset($aliases['alias_for_foo']), '->load() parses aliases'); $t->is($aliases['alias_for_foo'], 'foo', '->load() parses aliases');
$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(); $command->setApplication($application); $t->is($command->getApplication(), $application, '->setApplication() sets the current application'); // ->setDefinition() ->getDefinition() $t->diag('->setDefinition() ->getDefinition()'); $ret = $command->setDefinition($definition = new InputDefinition()); $t->is($ret, $command, '->setDefinition() implements a fluent interface'); $t->is($command->getDefinition(), $definition, '->setDefinition() sets the current InputDefinition instance'); $command->setDefinition(array(new InputArgument('foo'), new InputOption('bar'))); $t->ok($command->getDefinition()->hasArgument('foo'), '->setDefinition() also takes an array of InputArguments and InputOptions as an argument'); $t->ok($command->getDefinition()->hasOption('bar'), '->setDefinition() also takes an array of InputArguments and InputOptions as an argument'); $command->setDefinition(new InputDefinition()); // ->addArgument() $t->diag('->addArgument()'); $ret = $command->addArgument('foo'); $t->is($ret, $command, '->addArgument() implements a fluent interface'); $t->ok($command->getDefinition()->hasArgument('foo'), '->addArgument() adds an argument to the command'); // ->addOption() $t->diag('->addOption()'); $ret = $command->addOption('foo'); $t->is($ret, $command, '->addOption() implements a fluent interface'); $t->ok($command->getDefinition()->hasOption('foo'), '->addOption() adds an option to the command');
$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')); $sc->setParameter('bar', 'foo'); $t->is($sc->getParameter('bar'), 'foo', '->setParameter() sets the value of a new parameter'); $t->is($sc['bar'], 'foo', '->offsetGet() gets the value of a parameter'); $sc['bar1'] = 'foo1'; $t->is($sc['bar1'], 'foo1', '->offsetset() sets the value of a parameter'); unset($sc['bar1']); $t->ok(!isset($sc['bar1']), '->offsetUnset() removes a parameter'); $sc->setParameter('foo', 'baz'); $t->is($sc->getParameter('foo'), 'baz', '->setParameter() overrides previously set parameter'); $sc->setParameter('Foo', 'baz1'); $t->is($sc->getParameter('foo'), 'baz1', '->setParameter() converts the key to lowercase'); $t->is($sc->getParameter('FOO'), 'baz1', '->getParameter() converts the key to lowercase'); $t->is($sc['FOO'], 'baz1', '->offsetGet() converts the key to lowercase'); try { $sc->getParameter('baba'); $t->fail('->getParameter() thrown an \\InvalidArgumentException if the key does not exist'); } catch (\InvalidArgumentException $e) { $t->pass('->getParameter() thrown an \\InvalidArgumentException if the key does not exist'); } try { $sc['baba']; $t->fail('->offsetGet() thrown an \\InvalidArgumentException if the key does not exist');
<?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');
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'); $t->is($dispatcher->getListeners('foobar'), array(), '->getListeners() returns an empty array if no listener are connected to the given event name'); $listener = new Listener(); // ->notify() $t->diag('->notify()'); $listener->reset(); $dispatcher = new EventDispatcher(); $dispatcher->connect('foo', array($listener, 'listenToFoo'));
<?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\Loader\Loader; require_once __DIR__ . '/../../../../../fixtures/Symfony/Components/DependencyInjection/includes/ProjectExtension.php'; class ProjectLoader extends Loader { public function load($resource) { } } $t = new LimeTest(1); // ::registerExtension() ::getExtension() $t->diag('::registerExtension() ::getExtension()'); ProjectLoader::registerExtension($extension = new ProjectExtension()); $t->ok(ProjectLoader::getExtension('project') === $extension, '::registerExtension() registers an extension');