Merge branch '2.7' into 2.8

* 2.7:
  [HttpKernel] Fixed bug with purging of HTTPS URLs
  fix some risky tests
  [DI] [YamlFileLoader] change error message of a non existing file
  [Security] Added option to return true in the method isRememberMeRequested
This commit is contained in:
Fabien Potencier 2017-03-21 14:39:01 -07:00
commit 295a8e0a82
37 changed files with 221 additions and 117 deletions

View File

@ -25,5 +25,7 @@ class DbalSessionHandlerTest extends TestCase
{
$connection = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock();
$handler = new DbalSessionHandler($connection);
$this->assertInstanceOf('Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler', $handler);
}
}

View File

@ -105,7 +105,11 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
$renderer = $this->extension->renderer;
$renderer->setTheme($view, array('page_dynamic_extends.html.twig'));
$renderer->searchAndRenderBlock($view, 'row');
$this->assertMatchesXpath(
$renderer->searchAndRenderBlock($view, 'row'),
'/div/label[text()="child"]'
);
}
public function isSelectedChoiceProvider()

View File

@ -30,11 +30,10 @@ class StopwatchHelperTest extends TestCase
public function testProdEnvironment()
{
$helper = new StopwatchHelper(null);
$helper->start('foo');
try {
$helper->start('foo');
} catch (\BadMethodCallException $e) {
$this->fail('Assumed stopwatch is not called when not provided');
}
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
$this->addToAssertionCount(1);
}
}

View File

@ -19,21 +19,9 @@ class TemplateTest extends TestCase
/**
* @dataProvider getTemplateToPathProvider
*/
public function testGetPathForTemplatesInABundle($template, $path)
public function testGetPathForTemplate($template, $path)
{
if ($template->get('bundle')) {
$this->assertEquals($template->getPath(), $path);
}
}
/**
* @dataProvider getTemplateToPathProvider
*/
public function testGetPathForTemplatesOutOfABundle($template, $path)
{
if (!$template->get('bundle')) {
$this->assertEquals($template->getPath(), $path);
}
$this->assertSame($template->getPath(), $path);
}
public function getTemplateToPathProvider()

View File

@ -708,8 +708,12 @@ class ApplicationTest extends TestCase
$input = new ArgvInput(array('cli.php', '-v', 'foo:bar'));
$application->run($input, $output);
$this->addToAssertionCount(1);
$input = new ArgvInput(array('cli.php', '--verbose', 'foo:bar'));
$application->run($input, $output);
$this->addToAssertionCount(1);
}
public function testRunReturnsIntegerExitCode()

View File

@ -34,7 +34,7 @@ class TableTest extends TestCase
}
/**
* @dataProvider testRenderProvider
* @dataProvider renderProvider
*/
public function testRender($headers, $rows, $style, $expected, $decorated = false)
{
@ -50,7 +50,7 @@ class TableTest extends TestCase
}
/**
* @dataProvider testRenderProvider
* @dataProvider renderProvider
*/
public function testRenderAddRows($headers, $rows, $style, $expected, $decorated = false)
{
@ -66,7 +66,7 @@ class TableTest extends TestCase
}
/**
* @dataProvider testRenderProvider
* @dataProvider renderProvider
*/
public function testRenderAddRowsOneByOne($headers, $rows, $style, $expected, $decorated = false)
{
@ -83,7 +83,7 @@ class TableTest extends TestCase
$this->assertEquals($expected, $this->getOutputContent($output));
}
public function testRenderProvider()
public function renderProvider()
{
$books = array(
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),

View File

@ -353,7 +353,7 @@ class YamlFileLoader extends FileLoader
}
if (!file_exists($file)) {
throw new InvalidArgumentException(sprintf('The service file "%s" is not valid.', $file));
throw new InvalidArgumentException(sprintf('The file "%s" does not exist.', $file));
}
if (null === $this->yamlParser) {

View File

@ -114,6 +114,8 @@ class CheckCircularReferencesPassTest extends TestCase
$container->register('b')->addMethodCall('setA', array(new Reference('a')));
$this->process($container);
$this->addToAssertionCount(1);
}
protected function process(ContainerBuilder $container)

View File

@ -85,6 +85,8 @@ class CheckDefinitionValidityPassTest extends TestCase
$container->register('d', 'class')->setSynthetic(true);
$this->process($container);
$this->addToAssertionCount(1);
}
public function testValidTags()
@ -96,6 +98,8 @@ class CheckDefinitionValidityPassTest extends TestCase
$container->register('d', 'class')->addTag('foo', array('bar' => 1.1));
$this->process($container);
$this->addToAssertionCount(1);
}
/**

View File

@ -28,6 +28,10 @@ class CheckExceptionOnInvalidReferenceBehaviorPassTest extends TestCase
->addArgument(new Reference('b'))
;
$container->register('b', '\stdClass');
$this->process($container);
$this->addToAssertionCount(1);
}
/**

View File

@ -30,6 +30,8 @@ class CheckReferenceValidityPassTest extends TestCase
$container->register('b')->setScope('prototype');
$this->process($container);
$this->addToAssertionCount(1);
}
/**
@ -43,6 +45,8 @@ class CheckReferenceValidityPassTest extends TestCase
$container->register('b')->setScope('prototype');
$this->process($container);
$this->addToAssertionCount(1);
}
/**
@ -58,6 +62,8 @@ class CheckReferenceValidityPassTest extends TestCase
$container->register('b')->setScope('b');
$this->process($container);
$this->addToAssertionCount(1);
}
/**
@ -96,6 +102,8 @@ class CheckReferenceValidityPassTest extends TestCase
$container->register('b');
$this->process($container);
$this->addToAssertionCount(1);
}
protected function process(ContainerBuilder $container)

View File

@ -305,6 +305,8 @@ class PhpDumperTest extends TestCase
$dumper = new PhpDumper($container);
$dumper->dump();
$this->addToAssertionCount(1);
}
public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServices()
@ -342,5 +344,7 @@ class PhpDumperTest extends TestCase
$dumper->setProxyDumper(new DummyProxyDumper());
$dumper->dump();
$this->addToAssertionCount(1);
}
}

View File

@ -162,6 +162,8 @@ class XmlDumperTest extends TestCase
$container->compile();
$dumper = new XmlDumper($container);
$dumper->dump();
$this->addToAssertionCount(1);
}
public function provideCompiledContainerData()

View File

@ -33,40 +33,33 @@ class YamlFileLoaderTest extends TestCase
require_once self::$fixturesPath.'/includes/ProjectExtension.php';
}
public function testLoadFile()
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /The file ".+" does not exist./
*/
public function testLoadUnExistFile()
{
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/ini'));
$r = new \ReflectionObject($loader);
$m = $r->getMethod('loadFile');
$m->setAccessible(true);
try {
$m->invoke($loader, 'foo.yml');
$this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not exist');
$this->assertEquals('The service file "foo.yml" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not exist');
}
$m->invoke($loader, 'foo.yml');
}
try {
$m->invoke($loader, 'parameters.ini');
$this->fail('->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file');
$this->assertEquals('The service file "parameters.ini" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file');
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /The file ".+" does not contain valid YAML./
*/
public function testLoadInvalidYamlFile()
{
$path = self::$fixturesPath.'/ini';
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator($path));
$r = new \ReflectionObject($loader);
$m = $r->getMethod('loadFile');
$m->setAccessible(true);
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
foreach (array('nonvalid1', 'nonvalid2') as $fixture) {
try {
$m->invoke($loader, $fixture.'.yml');
$this->fail('->load() throws an InvalidArgumentException if the loaded file does not validate');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not validate');
$this->assertStringMatchesFormat('The service file "nonvalid%d.yml" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not validate');
}
}
$m->invoke($loader, $path.'/parameters.ini');
}
/**
@ -90,6 +83,8 @@ class YamlFileLoaderTest extends TestCase
array('bad_service'),
array('bad_calls'),
array('bad_format'),
array('nonvalid1'),
array('nonvalid2'),
);
}

View File

@ -178,14 +178,20 @@ class TraceableEventDispatcherTest extends TestCase
{
$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
$loop = 1;
$dispatchedEvents = 0;
$dispatcher->addListener('foo', $listener1 = function () use ($dispatcher, &$loop) {
++$loop;
if (2 == $loop) {
$dispatcher->dispatch('foo');
}
});
$dispatcher->addListener('foo', function () use (&$dispatchedEvents) {
++$dispatchedEvents;
});
$dispatcher->dispatch('foo');
$this->assertSame(2, $dispatchedEvents);
}
public function testDispatchReusedEventNested()

View File

@ -442,14 +442,22 @@ class FilesystemTest extends FilesystemTestCase
$this->assertFilePermissions(400, $file);
}
public function testChmodWrongMod()
public function testChmodWithWrongModLeavesPreviousPermissionsUntouched()
{
$this->markAsSkippedIfChmodIsMissing();
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('chmod() changes permissions even when passing invalid modes on HHVM');
}
$dir = $this->workspace.DIRECTORY_SEPARATOR.'file';
touch($dir);
$permissions = fileperms($dir);
$this->filesystem->chmod($dir, 'Wrongmode');
$this->assertSame($permissions, fileperms($dir));
}
public function testChmodRecursive()
@ -536,7 +544,10 @@ class FilesystemTest extends FilesystemTestCase
$dir = $this->workspace.DIRECTORY_SEPARATOR.'dir';
mkdir($dir);
$this->filesystem->chown($dir, $this->getFileOwner($dir));
$owner = $this->getFileOwner($dir);
$this->filesystem->chown($dir, $owner);
$this->assertSame($owner, $this->getFileOwner($dir));
}
public function testChownRecursive()
@ -548,7 +559,10 @@ class FilesystemTest extends FilesystemTestCase
$file = $dir.DIRECTORY_SEPARATOR.'file';
touch($file);
$this->filesystem->chown($dir, $this->getFileOwner($dir), true);
$owner = $this->getFileOwner($dir);
$this->filesystem->chown($dir, $owner, true);
$this->assertSame($owner, $this->getFileOwner($file));
}
public function testChownSymlink()
@ -562,7 +576,10 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->symlink($file, $link);
$this->filesystem->chown($link, $this->getFileOwner($link));
$owner = $this->getFileOwner($link);
$this->filesystem->chown($link, $owner);
$this->assertSame($owner, $this->getFileOwner($link));
}
/**
@ -602,7 +619,10 @@ class FilesystemTest extends FilesystemTestCase
$dir = $this->workspace.DIRECTORY_SEPARATOR.'dir';
mkdir($dir);
$this->filesystem->chgrp($dir, $this->getFileGroup($dir));
$group = $this->getFileGroup($dir);
$this->filesystem->chgrp($dir, $group);
$this->assertSame($group, $this->getFileGroup($dir));
}
public function testChgrpRecursive()
@ -614,7 +634,10 @@ class FilesystemTest extends FilesystemTestCase
$file = $dir.DIRECTORY_SEPARATOR.'file';
touch($file);
$this->filesystem->chgrp($dir, $this->getFileGroup($dir), true);
$group = $this->getFileGroup($dir);
$this->filesystem->chgrp($dir, $group, true);
$this->assertSame($group, $this->getFileGroup($file));
}
public function testChgrpSymlink()
@ -628,7 +651,10 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->symlink($file, $link);
$this->filesystem->chgrp($link, $this->getFileGroup($link));
$group = $this->getFileGroup($link);
$this->filesystem->chgrp($link, $group);
$this->assertSame($group, $this->getFileGroup($link));
}
/**

View File

@ -83,6 +83,8 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
// strip away <root> and </root>
substr($dom->saveHTML(), 6, -8)
));
} else {
$this->addToAssertionCount(1);
}
}

View File

@ -25,6 +25,8 @@ class TranslationFilesTest extends TestCase
} else {
\PHPUnit\Util\XML::loadfile($filePath, false, false, true);
}
$this->addToAssertionCount(1);
}
public function provideTranslationFiles()

View File

@ -325,10 +325,13 @@ class Store implements StoreInterface
*/
public function purge($url)
{
$http = preg_replace('#^https#', 'http', $url);
$https = preg_replace('#^http#', 'https', $url);
$http = preg_replace('#^https:#', 'http:', $url);
$https = preg_replace('#^http:#', 'https:', $url);
return $this->doPurge($http) || $this->doPurge($https);
$purgedHttp = $this->doPurge($http);
$purgedHttps = $this->doPurge($https);
return $purgedHttp || $purgedHttps;
}
/**

View File

@ -22,6 +22,18 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
class InlineFragmentRendererTest extends TestCase
{
private $originalTrustedHeaderName;
protected function setUp()
{
$this->originalTrustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP);
}
protected function tearDown()
{
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, $this->originalTrustedHeaderName);
}
public function testRender()
{
$strategy = new InlineFragmentRenderer($this->getKernel($this->returnValue(new Response('foo'))));
@ -47,7 +59,7 @@ class InlineFragmentRendererTest extends TestCase
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($subRequest));
$strategy->render(new ControllerReference('main_controller', array('object' => $object), array()), Request::create('/'));
$this->assertSame('foo', $strategy->render(new ControllerReference('main_controller', array('object' => $object), array()), Request::create('/'))->getContent());
}
public function testRenderWithObjectsAsAttributesPassedAsObjectsInTheController()
@ -70,14 +82,10 @@ class InlineFragmentRendererTest extends TestCase
public function testRenderWithTrustedHeaderDisabled()
{
$trustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP);
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, '');
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest(Request::create('/')));
$strategy->render('/', Request::create('/'));
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, $trustedHeaderName);
$this->assertSame('foo', $strategy->render('/', Request::create('/'))->getContent());
}
/**
@ -125,22 +133,6 @@ class InlineFragmentRendererTest extends TestCase
return $kernel;
}
/**
* Creates a Kernel expecting a request equals to $request
* Allows delta in comparison in case REQUEST_TIME changed by 1 second.
*/
private function getKernelExpectingRequest(Request $request)
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$kernel
->expects($this->any())
->method('handle')
->with($this->equalTo($request, 1))
;
return $kernel;
}
public function testExceptionInSubRequestsDoesNotMangleOutputBuffers()
{
$resolver = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface')->getMock();
@ -211,6 +203,22 @@ class InlineFragmentRendererTest extends TestCase
$request = Request::create('/', 'GET', array(), array(), array(), array('HTTP_IF_MODIFIED_SINCE' => 'Fri, 01 Jan 2016 00:00:00 GMT', 'HTTP_IF_NONE_MATCH' => '*'));
$strategy->render('/', $request);
}
/**
* Creates a Kernel expecting a request equals to $request
* Allows delta in comparison in case REQUEST_TIME changed by 1 second.
*/
private function getKernelExpectingRequest(Request $request, $strict = false)
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$kernel
->expects($this->once())
->method('handle')
->with($this->equalTo($request, 1))
->willReturn(new Response('foo'));
return $kernel;
}
}
class Bar

View File

@ -236,6 +236,33 @@ class StoreTest extends TestCase
$this->assertFalse($this->store->isLocked($req));
}
public function testPurgeHttps()
{
$request = Request::create('https://example.com/foo');
$this->store->write($request, new Response('foo'));
$this->assertNotEmpty($this->getStoreMetadata($request));
$this->assertTrue($this->store->purge('https://example.com/foo'));
$this->assertEmpty($this->getStoreMetadata($request));
}
public function testPurgeHttpAndHttps()
{
$requestHttp = Request::create('https://example.com/foo');
$this->store->write($requestHttp, new Response('foo'));
$requestHttps = Request::create('http://example.com/foo');
$this->store->write($requestHttps, new Response('foo'));
$this->assertNotEmpty($this->getStoreMetadata($requestHttp));
$this->assertNotEmpty($this->getStoreMetadata($requestHttps));
$this->assertTrue($this->store->purge('http://example.com/foo'));
$this->assertEmpty($this->getStoreMetadata($requestHttp));
$this->assertEmpty($this->getStoreMetadata($requestHttps));
}
protected function storeSimpleEntry($path = null, $headers = array())
{
if (null === $path) {

View File

@ -89,9 +89,9 @@ class LegacyOptionsResolverTest extends TestCase
'force' => 'boolean',
));
$this->resolver->resolve(array(
$this->assertSame(array('force' => true), $this->resolver->resolve(array(
'force' => true,
));
)));
}
public function testResolveLazyDependencyOnOptional()

View File

@ -1102,7 +1102,7 @@ class OptionsResolver2Dot6Test extends TestCase
$this->resolver->resolve();
}
public function testCatchedExceptionFromNormalizerDoesNotCrashOptionResolver()
public function testCaughtExceptionFromNormalizerDoesNotCrashOptionResolver()
{
$throw = true;
@ -1116,7 +1116,7 @@ class OptionsResolver2Dot6Test extends TestCase
}
});
$this->resolver->setNormalizer('thrower', function (Options $options) use (&$throw) {
$this->resolver->setNormalizer('thrower', function () use (&$throw) {
if ($throw) {
$throw = false;
throw new \UnexpectedValueException('throwing');
@ -1125,10 +1125,10 @@ class OptionsResolver2Dot6Test extends TestCase
return true;
});
$this->resolver->resolve();
$this->assertSame(array('catcher' => false, 'thrower' => true), $this->resolver->resolve());
}
public function testCatchedExceptionFromLazyDoesNotCrashOptionResolver()
public function testCaughtExceptionFromLazyDoesNotCrashOptionResolver()
{
$throw = true;
@ -1149,7 +1149,7 @@ class OptionsResolver2Dot6Test extends TestCase
return true;
});
$this->resolver->resolve();
$this->assertSame(array('catcher' => false, 'thrower' => true), $this->resolver->resolve());
}
public function testInvokeEachNormalizerOnlyOnce()

View File

@ -87,7 +87,9 @@ class PropertyPathTest extends TestCase
public function testZeroIsValidPropertyPath()
{
new PropertyPath('0');
$propertyPath = new PropertyPath('0');
$this->assertSame('0', (string) $propertyPath);
}
public function testGetParentWithDot()

View File

@ -25,6 +25,8 @@ class TranslationFilesTest extends TestCase
} else {
\PHPUnit\Util\XML::loadfile($filePath, false, false, true);
}
$this->addToAssertionCount(1);
}
public function provideTranslationFiles()

View File

@ -329,6 +329,6 @@ abstract class AbstractRememberMeServices implements RememberMeServicesInterface
$this->logger->debug('Did not send remember-me cookie.', array('parameter' => $this->options['remember_me_parameter']));
}
return $parameter === 'true' || $parameter === 'on' || $parameter === '1' || $parameter === 'yes';
return $parameter === 'true' || $parameter === 'on' || $parameter === '1' || $parameter === 'yes' || $parameter === true;
}
}

View File

@ -251,6 +251,7 @@ class AbstractRememberMeServicesTest extends TestCase
array('1'),
array('on'),
array('yes'),
array(true),
);
}

View File

@ -25,6 +25,8 @@ class TranslationFilesTest extends TestCase
} else {
\PHPUnit\Util\XML::loadfile($filePath, false, false, true);
}
$this->addToAssertionCount(1);
}
public function provideTranslationFiles()

View File

@ -17,7 +17,6 @@ use Symfony\Component\Serializer\Tests\Fixtures\NormalizableTraversableDummy;
use Symfony\Component\Serializer\Tests\Fixtures\ScalarDummy;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
@ -435,23 +434,12 @@ XML;
$this->encoder->decode('<?xml version="1.0"?><invalid><xml>', 'xml');
}
/**
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
*/
public function testPreventsComplexExternalEntities()
{
$oldCwd = getcwd();
chdir(__DIR__);
try {
$this->encoder->decode('<?xml version="1.0"?><!DOCTYPE scan[<!ENTITY test SYSTEM "php://filter/read=convert.base64-encode/resource=XmlEncoderTest.php">]><scan>&test;</scan>', 'xml');
chdir($oldCwd);
$this->fail('No exception was thrown.');
} catch (\Exception $e) {
chdir($oldCwd);
if (!$e instanceof UnexpectedValueException) {
$this->fail('Expected UnexpectedValueException');
}
}
$this->encoder->decode('<?xml version="1.0"?><!DOCTYPE scan[<!ENTITY test SYSTEM "php://filter/read=convert.base64-encode/resource=XmlEncoderTest.php">]><scan>&test;</scan>', 'xml');
}
public function testDecodeEmptyXml()

View File

@ -65,7 +65,6 @@ class PluralizationRulesTest extends TestCase
array('2', array('nl', 'fr', 'en', 'de', 'de_GE', 'hy', 'hy_AM')),
array('3', array('be', 'bs', 'cs', 'hr')),
array('4', array('cy', 'mt', 'sl')),
array('5', array()),
array('6', array('ar')),
);
}
@ -86,7 +85,6 @@ class PluralizationRulesTest extends TestCase
array('3', array('cbs')),
array('4', array('gd', 'kw')),
array('5', array('ga')),
array('6', array()),
);
}

View File

@ -156,6 +156,7 @@ class TranslatorTest extends TestCase
$translator = new Translator($locale, new MessageSelector());
$translator->setFallbackLocales(array('fr', $locale));
// no assertion. this method just asserts that no exception is thrown
$this->addToAssertionCount(1);
}
public function testTransWithFallbackLocale()
@ -187,6 +188,7 @@ class TranslatorTest extends TestCase
$translator = new Translator('fr', new MessageSelector());
$translator->addResource('array', array('foo' => 'foofoo'), $locale);
// no assertion. this method just asserts that no exception is thrown
$this->addToAssertionCount(1);
}
public function testAddResourceAfterTrans()
@ -390,6 +392,7 @@ class TranslatorTest extends TestCase
$translator->transChoice('foo', 1, array(), '', $locale);
// no assertion. this method just asserts that no exception is thrown
$this->addToAssertionCount(1);
}
public function getTransFileTests()

View File

@ -115,7 +115,9 @@ class ConstraintTest extends TestCase
public function testRequiredOptionsPassed()
{
new ConstraintC(array('option1' => 'default'));
$constraint = new ConstraintC(array('option1' => 'default'));
$this->assertSame('default', $constraint->option1);
}
public function testGroupsAreConvertedToArray()
@ -140,7 +142,9 @@ class ConstraintTest extends TestCase
public function testCanCreateConstraintWithNoDefaultOptionAndEmptyArray()
{
new ConstraintB(array());
$constraint = new ConstraintB(array());
$this->assertSame(array(Constraint::PROPERTY_CONSTRAINT, Constraint::CLASS_CONSTRAINT), $constraint->getTargets());
}
public function testGetTargetsCanBeString()

View File

@ -330,7 +330,9 @@ class CallbackValidatorTest extends AbstractConstraintValidatorTest
// Should succeed. Needed when defining constraints as annotations.
public function testNoConstructorArguments()
{
new Callback();
$constraint = new Callback();
$this->assertSame(array(Constraint::CLASS_CONSTRAINT, Constraint::PROPERTY_CONSTRAINT), $constraint->getTargets());
}
public function testAnnotationInvocationSingleValued()

View File

@ -94,5 +94,7 @@ class GroupSequenceTest extends TestCase
// should not fail
unset($sequence[2]);
$this->assertCount(2, $sequence);
}
}

View File

@ -245,19 +245,23 @@ class ClassMetadataTest extends TestCase
public function testGroupSequencesWorkIfContainingDefaultGroup()
{
$this->metadata->setGroupSequence(array('Foo', $this->metadata->getDefaultGroup()));
$this->assertInstanceOf('Symfony\Component\Validator\Constraints\GroupSequence', $this->metadata->getGroupSequence());
}
/**
* @expectedException \Symfony\Component\Validator\Exception\GroupDefinitionException
*/
public function testGroupSequencesFailIfNotContainingDefaultGroup()
{
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\GroupDefinitionException');
$this->metadata->setGroupSequence(array('Foo', 'Bar'));
}
/**
* @expectedException \Symfony\Component\Validator\Exception\GroupDefinitionException
*/
public function testGroupSequencesFailIfContainingDefault()
{
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\GroupDefinitionException');
$this->metadata->setGroupSequence(array('Foo', $this->metadata->getDefaultGroup(), Constraint::DEFAULT_GROUP));
}

View File

@ -167,7 +167,11 @@ class LazyLoadingMetadataFactoryTest extends TestCase
$metadata = $factory->getMetadataFor(self::PARENT_CLASS);
$metadata->addConstraint(new Callback(function () {}));
$this->assertCount(3, $metadata->getConstraints());
$metadata = $factory->getMetadataFor(self::CLASS_NAME);
$this->assertCount(6, $metadata->getConstraints());
}
public function testGroupsFromParent()

View File

@ -25,6 +25,8 @@ class TranslationFilesTest extends TestCase
} else {
\PHPUnit\Util\XML::loadfile($filePath, false, false, true);
}
$this->addToAssertionCount(1);
}
public function provideTranslationFiles()