public function __construct($plan = null, $options = array()) { // for BC if (!is_array($options)) { $options = array(); // drop the old output because it is not compatible with LimeTest } parent::__construct($plan, $options); }
public function __construct($plan = null, array $options = array()) { parent::__construct($plan, $options); $this->testRunner = new LimeTestRunner($this->getOutput()); $this->testRunner->addBefore(array($this, 'setUp')); $this->testRunner->addAfter(array($this, 'tearDown')); // attention: the following lines are not tested $this->testRunner->addExceptionHandler(array($this, 'handleException')); $this->testRunner->addAfter(array($this, 'verifyException')); foreach (get_class_methods($this) as $method) { if (strpos($method, 'test') === 0 && strlen($method) > 4) { $this->testRunner->addTest(array($this, $method), $this->humanize($method)); } } }
public function __construct(LimeConfiguration $configuration = null) { parent::__construct($configuration); $this->testRunner = new LimeTestRunner($this->getOutput()); $this->testRunner->addBefore(array($this, 'beginTest')); $this->testRunner->addBefore(array($this, 'setUp')); $this->testRunner->addAfter(array($this, 'tearDown')); // attention: the following lines are not tested $this->testRunner->addExceptionHandler(array($this, 'handleException')); $this->testRunner->addAfter(array($this, 'endTest')); $class = new ReflectionClass($this); foreach ($class->getMethods() as $method) { if (strpos($method->getName(), 'test') === 0 && strlen($method->getName()) > 4) { $this->testRunner->addTest(array($this, $method->getName()), $this->humanize($method->getName()), $method->getFileName(), $method->getStartLine()); } } }
<?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\CLI\Output\NullOutput; $t = new LimeTest(1); $output = new NullOutput(); $output->write('foo'); $t->pass('->write() does nothing');
<?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\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');
<?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');
<?php /* * This file is part of the Lime framework. * * (c) Fabien Potencier <*****@*****.**> * (c) Bernhard Schussek <*****@*****.**> * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ LimeAnnotationSupport::enable(); $t = new LimeTest(); // @Test: is() throws an exception if keys are missing // fixtures $actual = new LimeTesterArray(array()); $expected = new LimeTesterArray(array(0 => 1)); // test $t->expect('LimeAssertionFailedException'); $actual->is($expected); // @Test: is() throws an exception if keys are unexpected // fixtures $actual = new LimeTesterArray(array(0 => 1)); $expected = new LimeTesterArray(array()); // test $t->expect('LimeAssertionFailedException'); $actual->is($expected); // @Test: is() throws an exception if values don't match // fixtures $actual = new LimeTesterArray(array(0 => 1)); $expected = new LimeTesterArray(array(0 => 2));
<?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\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');
<?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; $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);
<?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()
<?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\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()
<?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\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');
<?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\Application; $t = new LimeTest(2); $application = new Application(); // ->execute() $t->diag('->execute()'); $commandTester = new CommandTester($application->getCommand('list')); $commandTester->execute(array()); $t->like($commandTester->getDisplay(), '/help Displays help for a command/', '->execute() returns a list of available commands'); $commandTester->execute(array('--xml' => true)); $t->like($commandTester->getDisplay(), '/<command id="list" namespace="_global" name="list">/', '->execute() returns a list of available commands in XML if --xml is passed');
* (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\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()
<?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\OutputEscaper\Escaper; $t = new LimeTest(3); class OutputEscaperTest { public function __toString() { return $this->getTitle(); } public function getTitle() { return '<strong>escaped!</strong>'; } public function getTitles() {
* (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; use Symfony\Components\Templating\Loader\CacheLoader; use Symfony\Components\Templating\Loader\CompilableLoaderInterface; use Symfony\Components\Templating\Storage\StringStorage; $t = new LimeTest(9); class ProjectTemplateLoader extends CacheLoader { public function getDir() { return $this->dir; } public function getLoader() { return $this->loader; } } class ProjectTemplateLoaderVar extends Loader
<?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');
<?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');
<?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\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'); }
/* * 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\OutputEscaper\Escaper; use Symfony\Components\OutputEscaper\Safe; use Symfony\Components\OutputEscaper\IteratorDecorator; use Symfony\Components\OutputEscaper\ArrayDecorator; use Symfony\Components\OutputEscaper\ObjectDecorator; $t = new LimeTest(39); class OutputEscaperTestClass { public $title = '<strong>escaped!</strong>'; public function getTitle() { return $this->title; } public function getTitleTitle() { $o = new self(); return $o->getTitle(); } } class OutputEscaperTestClassChild extends OutputEscaperTestClass {
<?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(); // @BeforeAll class Foo { private $foo = null; public function __construct($foo = null) { if (is_null($foo)) { $foo = 'Here be dragons'; } $this->foo = $foo; } public function set($foo) { $this->foo = $foo; } public function get() { return $this->foo; } } // @Before
* (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\FilesystemLoader; use Symfony\Components\Templating\Storage\FileStorage; $fixturesPath = realpath(__DIR__.'/../../../../../fixtures/Symfony/Components/Templating/'); $t = new LimeTest(14); class ProjectTemplateLoader extends FilesystemLoader { public function getTemplatePathPatterns() { return $this->templatePathPatterns; } static public function isAbsolutePath($path) { return parent::isAbsolutePath($path); } } // ->isAbsolutePath()
* * 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; 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');
* 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\Reference; use Symfony\Components\DependencyInjection\Definition; use Symfony\Components\DependencyInjection\Loader\Loader; use Symfony\Components\DependencyInjection\Loader\YamlFileLoader; $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()');
<?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');
<?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\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');
<?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(); // @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) {
<?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() ');