本文整理汇总了PHP中lime_test::fail方法的典型用法代码示例。如果您正苦于以下问题:PHP lime_test::fail方法的具体用法?PHP lime_test::fail怎么用?PHP lime_test::fail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lime_test
的用法示例。
在下文中一共展示了lime_test::fail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fail
/**
* Tests that this input fails
*
* @param string $input
* @param string $message
*/
public function fail($input, $message = null, $encoding = 'utf-8')
{
$this->lime->diag($input);
try {
$this->lexer->tokenize($input, $encoding);
$this->lime->fail('exception not thrown');
if ($message) {
$this->lime->skip('');
}
} catch (Exception $e) {
$this->lime->pass('exception caught: ' . $e->getMessage());
if ($message) {
$this->lime->is($e->getMessage(), $message, 'exception message matches');
}
}
}
示例2: php_html_writer_run_tests
function php_html_writer_run_tests(lime_test $t, array $tests, $callable)
{
foreach ($tests as $test) {
$parameters = $test['params'];
$expectedResult = isset($test['result']) ? $test['result'] : null;
try {
$result = call_user_func_array($callable, $parameters);
if (isset($test['throws'])) {
$t->fail($parameters[0] . ' throws a ' . $test['throws']);
} else {
$t->is_deeply($result, $expectedResult, '"' . str_replace('"', '\'', $parameters[0]) . '" ' . str_replace("\n", '', var_export($expectedResult, true)));
}
} catch (Exception $exception) {
$exceptionClass = get_class($exception);
$message = sprintf('"%s" throws a %s: %s', isset($parameters[0]) ? str_replace('"', '\'', (string) $parameters[0]) : 'NULL', $exceptionClass, $exception->getMessage());
if (isset($test['throws']) && $test['throws'] == $exceptionClass) {
$t->pass($message);
} else {
$t->fail($message);
}
}
}
}
示例3: _createTmpGitRepo
/**
*
* @param lime_test $t
* @return PHPGit_Repository the git repo
*/
function _createTmpGitRepo(lime_test $t, array $options = array())
{
$repoDir = sys_get_temp_dir() . '/php-git-repo/' . uniqid();
$t->ok(!is_dir($repoDir . '/.git'), $repoDir . ' is not a Git repo');
try {
new PHPGit_Repository($repoDir, true, $options);
$t->fail($repoDir . ' is not a valid git repository');
} catch (InvalidArgumentException $e) {
$t->pass($repoDir . ' is not a valid git repository');
}
$t->comment('Create Git repo');
exec('git init ' . escapeshellarg($repoDir));
$t->ok(is_dir($repoDir . '/.git'), $repoDir . ' is a Git repo');
$repo = new PHPGit_Repository($repoDir, true, $options);
$t->isa_ok($repo, 'PHPGit_Repository', $repoDir . ' is a valid git repo');
$originalRepoDir = dirname(__FILE__) . '/repo';
foreach (array('README.markdown', 'index.php') as $file) {
copy($originalRepoDir . '/' . $file, $repoDir . '/' . $file);
}
return $repo;
}
示例4: dirname
<?php
require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php';
$helper = new dmUnitTestHelper();
$helper->boot('front');
clearstatcache(true);
$isSqlite = Doctrine_Manager::getInstance()->getConnection('doctrine') instanceof Doctrine_Connection_Sqlite;
$t = new lime_test(16 + ($isSqlite ? 0 : 1) + 3 * count($helper->get('i18n')->getCultures()));
$user = $helper->get('user');
try {
$index = $helper->get('search_index');
$t->fail('Can\'t create index without dir');
} catch (dmSearchIndexException $e) {
$t->pass('Can\'t create index without dir');
}
$engine = $helper->get('search_engine');
$t->isa_ok($engine, 'dmSearchEngine', 'Got a dmSearchEngine instance');
$expected = dmProject::rootify(dmArray::get($helper->get('service_container')->getParameter('search_engine.options'), 'dir'));
$t->is($engine->getFullPath(), $expected, 'Current engine full path is ' . $expected);
$t->ok(!file_exists(dmProject::rootify('segments.gen')), 'There is no segments.gen in project root dir');
$engine->setDir('cache/testIndex');
foreach ($helper->get('i18n')->getCultures() as $culture) {
$user->setCulture($culture);
$currentIndex = $engine->getCurrentIndex();
$t->is($currentIndex->getName(), 'dm_page_' . $culture, 'Current index name is ' . $currentIndex->getName());
$t->is($currentIndex->getCulture(), $culture, 'Current index culture is ' . $culture);
$t->is($currentIndex->getFullPath(), dmProject::rootify('cache/testIndex/' . $currentIndex->getName()), 'Current index full path is ' . $currentIndex->getFullPath());
}
$user->setCulture(sfConfig::get('sf_default_culture'));
$currentIndex = $engine->getCurrentIndex();
$t->isa_ok($currentIndex->getLuceneIndex(), 'Zend_Search_Lucene_Proxy', 'The current index is instanceof Zend_Search_Lucene_Proxy');
示例5: dirname
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new lime_test(18, new lime_output_color());
$v1 = new sfValidatorString(array('max_length' => 3));
$v2 = new sfValidatorString(array('min_length' => 3));
$v = new sfValidatorOr(array($v1, $v2));
// __construct()
$t->diag('__construct()');
$v = new sfValidatorOr();
$t->is($v->getValidators(), array(), '->__construct() can take no argument');
$v = new sfValidatorOr($v1);
$t->is($v->getValidators(), array($v1), '->__construct() can take a validator as its first argument');
$v = new sfValidatorOr(array($v1, $v2));
$t->is($v->getValidators(), array($v1, $v2), '->__construct() can take an array of validators as its first argument');
try {
$v = new sfValidatorOr('string');
$t->fail('_construct() throws an exception when passing a non supported first argument');
} catch (InvalidArgumentException $e) {
$t->pass('_construct() throws an exception when passing a non supported first argument');
}
// ->addValidator()
$t->diag('->addValidator()');
$v = new sfValidatorOr();
$v->addValidator($v1);
$v->addValidator($v2);
$t->is($v->getValidators(), array($v1, $v2), '->addValidator() adds a validator');
// ->clean()
$t->diag('->clean()');
$t->is($v->clean('foo'), 'foo', '->clean() returns the string unmodified');
try {
$v->setOption('required', true);
$v->clean(null);
示例6: dirname
*/
require_once dirname(__FILE__) . '/../lib/lime/lime.php';
require_once dirname(__FILE__) . '/../../lib/sfServiceContainerAutoloader.php';
sfServiceContainerAutoloader::register();
require_once dirname(__FILE__) . '/../lib/yaml/sfYaml.php';
$t = new lime_test(4);
$dir = dirname(__FILE__) . '/fixtures/yaml';
// ->dump()
$t->diag('->dump()');
$dumper = new sfServiceContainerDumperYaml($container = new sfServiceContainerBuilder());
$t->is($dumper->dump(), file_get_contents($dir . '/services1.yml'), '->dump() dumps an empty container as an empty YAML file');
$container = new sfServiceContainerBuilder();
$dumper = new sfServiceContainerDumperYaml($container);
// ->addParameters()
$t->diag('->addParameters()');
$container = (include dirname(__FILE__) . '/fixtures/containers/container8.php');
$dumper = new sfServiceContainerDumperYaml($container);
$t->is($dumper->dump(), file_get_contents($dir . '/services8.yml'), '->dump() dumps parameters');
// ->addService()
$t->diag('->addService()');
$container = (include dirname(__FILE__) . '/fixtures/containers/container9.php');
$dumper = new sfServiceContainerDumperYaml($container);
$t->is($dumper->dump(), str_replace('%path%', dirname(__FILE__) . '/fixtures/includes', file_get_contents($dir . '/services9.yml')), '->dump() dumps services');
$dumper = new sfServiceContainerDumperYaml($container = new sfServiceContainerBuilder());
$container->register('foo', 'FooClass')->addArgument(new stdClass());
try {
$dumper->dump();
$t->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
} catch (RuntimeException $e) {
$t->pass('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
}
示例7: guessFromFileBinary
}
public function guessFromFileBinary($file)
{
return parent::guessFromFileBinary($file);
}
public function getMimeTypesFromCategory($category)
{
return parent::getMimeTypesFromCategory($category);
}
}
// ->getMimeTypesFromCategory()
$t->diag('->getMimeTypesFromCategory()');
$v = new testValidatorFile();
try {
$t->is($v->getMimeTypesFromCategory('non_existant_category'), '');
$t->fail('->getMimeTypesFromCategory() throws an InvalidArgumentException if the category does not exist');
} catch (InvalidArgumentException $e) {
$t->pass('->getMimeTypesFromCategory() throws an InvalidArgumentException if the category does not exist');
}
$categories = $v->getOption('mime_categories');
$t->is($v->getMimeTypesFromCategory('web_images'), $categories['web_images'], '->getMimeTypesFromCategory() returns an array of mime types for a given category');
$v->setOption('mime_categories', array_merge($v->getOption('mime_categories'), array('text' => array('text/plain'))));
$t->is($v->getMimeTypesFromCategory('text'), array('text/plain'), '->getMimeTypesFromCategory() returns an array of mime types for a given category');
// ->guessFromFileinfo()
$t->diag('->guessFromFileinfo()');
if (!function_exists('finfo_open')) {
$t->skip('finfo_open is not available', 2);
} else {
$v = new testValidatorFile();
$t->is($v->guessFromFileinfo($tmpDir . '/test.txt'), 'text/plain', '->guessFromFileinfo() guesses the type of a given file');
$t->is($v->guessFromFileinfo($tmpDir . '/foo.txt'), null, '->guessFromFileinfo() returns null if the file type is not guessable');
示例8: hasTemplate
{
return new self();
}
public function hasTemplate($template)
{
return false;
}
}
$t->diag('::isTaggable');
$t->ok(TaggableToolkit::isTaggable('ValidModel'), 'valid model name');
$t->ok(TaggableToolkit::isTaggable(new ValidModel('ValidModel')), 'valid model object');
$t->ok(!TaggableToolkit::isTaggable('InValidModel'), 'invalid model name');
$t->ok(!TaggableToolkit::isTaggable(new InValidModel('InValidModel')), 'invalid model object');
try {
TaggableToolkit::isTaggable('MyClass');
$t->fail('no exception for no doctrine model name');
} catch (Exception $e) {
$t->pass('no doctrine model name');
}
class MyClass
{
}
try {
TaggableToolkit::isTaggable(new MyClass());
$t->fail('no exception for no doctrine model class');
} catch (Exception $e) {
$t->pass('no doctrine model class');
}
$t->diag('::normalize');
$t->todo('test normalize');
$t->diag('::triplify');
示例9: catch
// checking if the old session record still exists
$result = $connection->query(sprintf('SELECT sess_id, sess_data FROM session WHERE sess_id = "%s"', $session_id));
$data = $result->fetchAll();
$t->is(count($data), 1, 'regenerate() has kept destroyed old session');
// checking if the new session record has been created
$result = $connection->query(sprintf('SELECT sess_id, sess_data FROM session WHERE sess_id = "%s"', session_id()));
$data = $result->fetchAll();
$t->is(count($data), 1, 'regenerate() has created a new session record');
$t->is($data[0]['sess_data'], $newSessionData, 'regenerate() has created a new record with correct data');
$session_id = session_id();
// sessionRead()
try {
$retrieved_data = $storage->sessionRead($session_id);
$t->pass('sessionRead() does not throw an exception');
} catch (Exception $e) {
$t->fail('sessionRead() does not throw an exception');
}
$t->is($retrieved_data, $newSessionData, 'sessionRead() reads session data');
// sessionWrite()
$otherSessionData = 'foo:foo:foo';
try {
$write = $storage->sessionWrite($session_id, $otherSessionData);
$t->pass('sessionWrite() does not throw an exception');
} catch (Exception $e) {
$t->fail('sessionWrite() does not throw an exception');
}
$t->ok($write, 'sessionWrite() returns true');
$t->is($storage->sessionRead($session_id), $otherSessionData, 'sessionWrite() wrote session data');
// sessionGC()
try {
$storage->sessionGC(0);
示例10: dirname
<?php
/*
* This file is part of the symfony package.
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new lime_test(5);
// __construct()
$t->diag('__construct()');
try {
new sfValidatorCSRFToken();
$t->fail('__construct() throws an RuntimeException if you don\'t pass a token option');
} catch (RuntimeException $e) {
$t->pass('__construct() throws an RuntimeException if you don\'t pass a token option');
}
$v = new sfValidatorCSRFToken(array('token' => 'symfony'));
// ->clean()
$t->diag('->clean()');
$t->is($v->clean('symfony'), 'symfony', '->clean() checks that the token is valid');
try {
$v->clean('another');
$t->fail('->clean() throws an sfValidatorError if the token is not valid');
$t->skip('', 1);
} catch (sfValidatorError $e) {
$t->pass('->clean() throws an sfValidatorError if the token is not valid');
$t->is($e->getCode(), 'csrf_attack', '->clean() throws a sfValidatorError');
}
示例11: trim
}
$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 (InvalidArgumentException $e) {
$t->pass('YAML files must not contain tabs');
}
}
$yaml = <<<EOF
--- %YAML:1.0
foo
...
EOF;
$t->is('foo', $parser->parse($yaml));
// objects
$t->diag('Objects support');
class A
{
public $a = 'foo';
示例12: sfCommandOption
$t->is($option->isParameterOptional(), false, '__construct() can take "sfCommandOption::PARAMETER_NONE" as its mode');
$option = new sfCommandOption('foo', 'f', sfCommandOption::PARAMETER_NONE);
$t->is($option->acceptParameter(), false, '__construct() can take "sfCommandOption::PARAMETER_NONE" as its mode');
$t->is($option->isParameterRequired(), false, '__construct() can take "sfCommandOption::PARAMETER_NONE" as its mode');
$t->is($option->isParameterOptional(), false, '__construct() can take "sfCommandOption::PARAMETER_NONE" as its mode');
$option = new sfCommandOption('foo', 'f', sfCommandOption::PARAMETER_REQUIRED);
$t->is($option->acceptParameter(), true, '__construct() can take "sfCommandOption::PARAMETER_REQUIRED" as its mode');
$t->is($option->isParameterRequired(), true, '__construct() can take "sfCommandOption::PARAMETER_REQUIRED" as its mode');
$t->is($option->isParameterOptional(), false, '__construct() can take "sfCommandOption::PARAMETER_REQUIRED" as its mode');
$option = new sfCommandOption('foo', 'f', sfCommandOption::PARAMETER_OPTIONAL);
$t->is($option->acceptParameter(), true, '__construct() can take "sfCommandOption::PARAMETER_OPTIONAL" as its mode');
$t->is($option->isParameterRequired(), false, '__construct() can take "sfCommandOption::PARAMETER_OPTIONAL" as its mode');
$t->is($option->isParameterOptional(), true, '__construct() can take "sfCommandOption::PARAMETER_OPTIONAL" as its mode');
try {
$option = new sfCommandOption('foo', 'f', 'ANOTHER_ONE');
$t->fail('__construct() throws an sfCommandException if the mode is not valid');
} catch (sfCommandException $e) {
$t->pass('__construct() throws an sfCommandException if the mode is not valid');
}
// ->isArray()
$t->diag('->isArray()');
$option = new sfCommandOption('foo', null, sfCommandOption::IS_ARRAY);
$t->ok($option->isArray(), '->isArray() returns true if the option can be an array');
$option = new sfCommandOption('foo', null, sfCommandOption::PARAMETER_NONE | sfCommandOption::IS_ARRAY);
$t->ok($option->isArray(), '->isArray() returns true if the option can be an array');
$option = new sfCommandOption('foo', null, sfCommandOption::PARAMETER_NONE);
$t->ok(!$option->isArray(), '->isArray() returns false if the option can not be an array');
// ->getHelp()
$t->diag('->getHelp()');
$option = new sfCommandOption('foo', 'f', null, 'Some help');
$t->is($option->getHelp(), 'Some help', '->getHelp() returns the help message');
示例13: setup
$t = new lime_test(6);
class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
$this->enablePlugins(array('sfAutoloadPlugin', 'sfConfigPlugin'));
$this->setPluginPath('sfConfigPlugin', $this->rootDir . '/lib/plugins/sfConfigPlugin');
}
}
$configuration = new ProjectConfiguration(__DIR__ . '/../../functional/fixtures');
// ->setPlugins() ->disablePlugins() ->enablePlugins() ->enableAllPluginsExcept()
$t->diag('->setPlugins() ->disablePlugins() ->enablePlugins() ->enableAllPluginsExcept()');
foreach (array('setPlugins', 'disablePlugins', 'enablePlugins', 'enableAllPluginsExcept') as $method) {
try {
$configuration->{$method}(array());
$t->fail('->' . $method . '() throws an exception if called too late');
} catch (Exception $e) {
$t->pass('->' . $method . '() throws an exception if called too late');
}
}
class ProjectConfiguration2 extends sfProjectConfiguration
{
public function setup()
{
$this->enablePlugins('sfAutoloadPlugin', 'sfConfigPlugin');
}
}
$configuration = new ProjectConfiguration2(__DIR__ . '/../../functional/fixtures');
$t->is_deeply($configuration->getPlugins(), array('sfAutoloadPlugin', 'sfConfigPlugin'), '->enablePlugins() can enable plugins passed as arguments instead of array');
// ->__construct()
$t->diag('->__construct()');
示例14: stdClass
// ::switchTo();
$t->diag('::switchTo()');
sfContext::switchTo('i18n');
$t->is(sfContext::getInstance(), $context1, '::switchTo() changes the default context instance returned by ::getInstance()');
sfContext::switchTo('cache');
$t->is(sfContext::getInstance(), $context2, '::switchTo() changes the default context instance returned by ::getInstance()');
// ->get() ->set() ->has()
$t->diag('->get() ->set() ->has()');
$t->is($context1->has('object'), false, '->has() returns false if no object of the given name exist');
$object = new stdClass();
$context1->set('object', $object, '->set() stores an object in the current context instance');
$t->is($context1->has('object'), true, '->has() returns true if an object is stored for the given name');
$t->is($context1->get('object'), $object, '->get() returns the object associated with the given name');
try {
$context1->get('object1');
$t->fail('->get() throws an sfException if no object is stored for the given name');
} catch (sfException $e) {
$t->pass('->get() throws an sfException if no object is stored for the given name');
}
$context['foo'] = $frontend_context;
$t->diag('Array access for context objects');
$t->is(isset($context['foo']), true, '->offsetExists() returns true if context object exists');
$t->is(isset($context['foo2']), false, '->offsetExists() returns false if context object does not exist');
$t->isa_ok($context['foo'], 'sfContext', '->offsetGet() returns attribute by name');
$context['foo2'] = $i18n_context;
$t->isa_ok($context['foo2'], 'sfContext', '->offsetSet() sets object by name');
unset($context['foo2']);
$t->is(isset($context['foo2']), false, '->offsetUnset() unsets object by name');
$t->diag('->__call()');
$context->setFoo4($i18n_context);
$t->is($context->has('foo4'), true, '->__call() sets context objects by name using setName()');
示例15: catch
$t->is($n->isValid(1, '[1]'), true, '->isValid() determines if a given number belongs to the given set');
$t->is($n->isValid(2, '[1]'), false, '->isValid() determines if a given number belongs to the given set');
$t->is($n->isValid(1, '(1)'), false, '->isValid() determines if a given number belongs to the given set');
$t->is($n->isValid(1, '(1,10)'), false, '->isValid() determines if a given number belongs to the given set');
$t->is($n->isValid(10, '(1,10)'), false, '->isValid() determines if a given number belongs to the given set');
$t->is($n->isValid(4, '(1,10)'), true, '->isValid() determines if a given number belongs to the given set');
$t->is($n->isValid(1, '{1,2,4,5}'), true, '->isValid() determines if a given number belongs to the given set');
$t->is($n->isValid(3, '{1,2,4,5}'), false, '->isValid() determines if a given number belongs to the given set');
$t->is($n->isValid(4, '{1,2,4,5}'), true, '->isValid() determines if a given number belongs to the given set');
$t->is($n->isValid(1, '[0,+Inf]'), true, '->isValid() determines if a given number belongs to the given set');
$t->is($n->isValid(10000000, '[0,+Inf]'), true, '->isValid() determines if a given number belongs to the given set');
$t->is($n->isValid(10000000, '[0,Inf]'), true, '->isValid() determines if a given number belongs to the given set');
$t->is($n->isValid(-10000000, '[-Inf,+Inf]'), true, '->isValid() determines if a given number belongs to the given set');
try {
$n->isValid(1, '[1');
$t->fail('->isValid() throw an exception if the set is not valid');
} catch (sfException $e) {
$t->pass('->isValid() throw an exception if the set is not valid');
}
// ->format()
$t->diag('->format()');
$t->is($n->format($strings[0][0], 1), $strings[0][1][1][0], '->format() returns the string that match the number');
$t->is($n->format($strings[0][0], 4), false, '->format() returns the string that match the number');
$t->is($n->format($strings[4][0], 0), $strings[4][1][1][0], '->format() returns the string that match the number');
$t->is($n->format($strings[4][0], 1), $strings[4][1][1][1], '->format() returns the string that match the number');
$t->is($n->format($strings[4][0], 12), $strings[4][1][1][2], '->format() returns the string that match the number');
// test set notation
// tests adapted from Prado unit test suite
$t->diag('set notation');
$string = '{n: n%2 == 0} are even numbers |{n: n >= 5} are not even and greater than or equal to 5';
$t->is($n->format($string, 0), 'are even numbers', '->format() can takes a set notation in the format string');