minor #22066 fix some risky tests (xabbuh)

This PR was merged into the 2.7 branch.

Discussion
----------

fix some risky tests

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

PHPUnit 6 marks tests as risky when they have no assertions (and are not marked as skipped or incomplete). This PR will update our test suite accordingly.

Component that still need to be covered:

- [ ] Config
- [ ] Form
- [ ] HttpFoundation
- [ ] Security
- [ ] Workflow

Commits
-------

abf1787dcc fix some risky tests
This commit is contained in:
Fabien Potencier 2017-03-21 14:36:30 -07:00
commit 65260bc346
36 changed files with 206 additions and 128 deletions

View File

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

View File

@ -118,36 +118,36 @@ class FormExtensionBootstrap3HorizontalLayoutTest extends AbstractBootstrap3Hori
public function testRange() public function testRange()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testRangeWithMinMaxValues() public function testRangeWithMinMaxValues()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testLabelWithoutTranslationOnButton() public function testLabelWithoutTranslationOnButton()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testSingleChoiceWithPlaceholderWithoutTranslation() public function testSingleChoiceWithPlaceholderWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation() public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testButtonlabelWithoutTranslation() public function testButtonlabelWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testAttributesNotTranslatedWhenTranslationDomainIsFalse() public function testAttributesNotTranslatedWhenTranslationDomainIsFalse()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
} }

View File

@ -118,36 +118,36 @@ class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest
public function testRange() public function testRange()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testRangeWithMinMaxValues() public function testRangeWithMinMaxValues()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testLabelWithoutTranslationOnButton() public function testLabelWithoutTranslationOnButton()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testSingleChoiceWithPlaceholderWithoutTranslation() public function testSingleChoiceWithPlaceholderWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation() public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testButtonlabelWithoutTranslation() public function testButtonlabelWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testAttributesNotTranslatedWhenTranslationDomainIsFalse() public function testAttributesNotTranslatedWhenTranslationDomainIsFalse()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
} }

View File

@ -105,7 +105,11 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
$renderer = $this->extension->renderer; $renderer = $this->extension->renderer;
$renderer->setTheme($view, array('page_dynamic_extends.html.twig')); $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() public function isSelectedChoiceProvider()
@ -211,36 +215,36 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
public function testRange() public function testRange()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testRangeWithMinMaxValues() public function testRangeWithMinMaxValues()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testLabelWithoutTranslationOnButton() public function testLabelWithoutTranslationOnButton()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testSingleChoiceWithPlaceholderWithoutTranslation() public function testSingleChoiceWithPlaceholderWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation() public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testButtonlabelWithoutTranslation() public function testButtonlabelWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testAttributesNotTranslatedWhenTranslationDomainIsFalse() public function testAttributesNotTranslatedWhenTranslationDomainIsFalse()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
} }

View File

@ -119,36 +119,36 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
public function testRange() public function testRange()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testRangeWithMinMaxValues() public function testRangeWithMinMaxValues()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testLabelWithoutTranslationOnButton() public function testLabelWithoutTranslationOnButton()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testSingleChoiceWithPlaceholderWithoutTranslation() public function testSingleChoiceWithPlaceholderWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation() public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testButtonlabelWithoutTranslation() public function testButtonlabelWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testAttributesNotTranslatedWhenTranslationDomainIsFalse() public function testAttributesNotTranslatedWhenTranslationDomainIsFalse()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
} }

View File

@ -131,36 +131,36 @@ class FormHelperDivLayoutTest extends AbstractDivLayoutTest
public function testRange() public function testRange()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testRangeWithMinMaxValues() public function testRangeWithMinMaxValues()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testLabelWithoutTranslationOnButton() public function testLabelWithoutTranslationOnButton()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testSingleChoiceWithPlaceholderWithoutTranslation() public function testSingleChoiceWithPlaceholderWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation() public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testButtonlabelWithoutTranslation() public function testButtonlabelWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testAttributesNotTranslatedWhenTranslationDomainIsFalse() public function testAttributesNotTranslatedWhenTranslationDomainIsFalse()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
} }

View File

@ -118,36 +118,36 @@ class FormHelperTableLayoutTest extends AbstractTableLayoutTest
public function testRange() public function testRange()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testRangeWithMinMaxValues() public function testRangeWithMinMaxValues()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testLabelWithoutTranslationOnButton() public function testLabelWithoutTranslationOnButton()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testSingleChoiceWithPlaceholderWithoutTranslation() public function testSingleChoiceWithPlaceholderWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation() public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testButtonlabelWithoutTranslation() public function testButtonlabelWithoutTranslation()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
public function testAttributesNotTranslatedWhenTranslationDomainIsFalse() public function testAttributesNotTranslatedWhenTranslationDomainIsFalse()
{ {
// No-op for forward compatibility with AbstractLayoutTest 2.8 $this->markTestIncomplete('No-op for forward compatibility with AbstractLayoutTest 2.8');
} }
} }

View File

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

View File

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

View File

@ -704,8 +704,12 @@ class ApplicationTest extends TestCase
$input = new ArgvInput(array('cli.php', '-v', 'foo:bar')); $input = new ArgvInput(array('cli.php', '-v', 'foo:bar'));
$application->run($input, $output); $application->run($input, $output);
$this->addToAssertionCount(1);
$input = new ArgvInput(array('cli.php', '--verbose', 'foo:bar')); $input = new ArgvInput(array('cli.php', '--verbose', 'foo:bar'));
$application->run($input, $output); $application->run($input, $output);
$this->addToAssertionCount(1);
} }
public function testRunReturnsIntegerExitCode() 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) 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) 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) public function testRenderAddRowsOneByOne($headers, $rows, $style, $expected, $decorated = false)
{ {
@ -83,7 +83,7 @@ class TableTest extends TestCase
$this->assertEquals($expected, $this->getOutputContent($output)); $this->assertEquals($expected, $this->getOutputContent($output));
} }
public function testRenderProvider() public function renderProvider()
{ {
$books = array( $books = array(
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'), array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),

View File

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

View File

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

View File

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

View File

@ -27,6 +27,8 @@ class CheckReferenceValidityPassTest extends TestCase
$container->register('b')->setScope('prototype'); $container->register('b')->setScope('prototype');
$this->process($container); $this->process($container);
$this->addToAssertionCount(1);
} }
/** /**
@ -39,6 +41,8 @@ class CheckReferenceValidityPassTest extends TestCase
$container->register('b')->setScope('prototype'); $container->register('b')->setScope('prototype');
$this->process($container); $this->process($container);
$this->addToAssertionCount(1);
} }
public function testProcessIgnoresCrossScopeHierarchyReferenceIfNotStrict() public function testProcessIgnoresCrossScopeHierarchyReferenceIfNotStrict()
@ -51,6 +55,8 @@ class CheckReferenceValidityPassTest extends TestCase
$container->register('b')->setScope('b'); $container->register('b')->setScope('b');
$this->process($container); $this->process($container);
$this->addToAssertionCount(1);
} }
/** /**
@ -88,6 +94,8 @@ class CheckReferenceValidityPassTest extends TestCase
$container->register('b'); $container->register('b');
$this->process($container); $this->process($container);
$this->addToAssertionCount(1);
} }
protected function process(ContainerBuilder $container) protected function process(ContainerBuilder $container)

View File

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

View File

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

View File

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

View File

@ -442,14 +442,22 @@ class FilesystemTest extends FilesystemTestCase
$this->assertFilePermissions(400, $file); $this->assertFilePermissions(400, $file);
} }
public function testChmodWrongMod() public function testChmodWithWrongModLeavesPreviousPermissionsUntouched()
{ {
$this->markAsSkippedIfChmodIsMissing(); $this->markAsSkippedIfChmodIsMissing();
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('chmod() changes permissions even when passing invalid modes on HHVM');
}
$dir = $this->workspace.DIRECTORY_SEPARATOR.'file'; $dir = $this->workspace.DIRECTORY_SEPARATOR.'file';
touch($dir); touch($dir);
$permissions = fileperms($dir);
$this->filesystem->chmod($dir, 'Wrongmode'); $this->filesystem->chmod($dir, 'Wrongmode');
$this->assertSame($permissions, fileperms($dir));
} }
public function testChmodRecursive() public function testChmodRecursive()
@ -536,7 +544,10 @@ class FilesystemTest extends FilesystemTestCase
$dir = $this->workspace.DIRECTORY_SEPARATOR.'dir'; $dir = $this->workspace.DIRECTORY_SEPARATOR.'dir';
mkdir($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() public function testChownRecursive()
@ -548,7 +559,10 @@ class FilesystemTest extends FilesystemTestCase
$file = $dir.DIRECTORY_SEPARATOR.'file'; $file = $dir.DIRECTORY_SEPARATOR.'file';
touch($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() public function testChownSymlink()
@ -562,7 +576,10 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->symlink($file, $link); $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'; $dir = $this->workspace.DIRECTORY_SEPARATOR.'dir';
mkdir($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() public function testChgrpRecursive()
@ -614,7 +634,10 @@ class FilesystemTest extends FilesystemTestCase
$file = $dir.DIRECTORY_SEPARATOR.'file'; $file = $dir.DIRECTORY_SEPARATOR.'file';
touch($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() public function testChgrpSymlink()
@ -628,7 +651,10 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->symlink($file, $link); $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> // strip away <root> and </root>
substr($dom->saveHTML(), 6, -8) substr($dom->saveHTML(), 6, -8)
)); ));
} else {
$this->addToAssertionCount(1);
} }
} }

View File

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

View File

@ -22,6 +22,18 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
class InlineFragmentRendererTest extends TestCase 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() public function testRender()
{ {
$strategy = new InlineFragmentRenderer($this->getKernel($this->returnValue(new Response('foo')))); $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 = 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() public function testRenderWithObjectsAsAttributesPassedAsObjectsInTheController()
@ -70,14 +82,10 @@ class InlineFragmentRendererTest extends TestCase
public function testRenderWithTrustedHeaderDisabled() public function testRenderWithTrustedHeaderDisabled()
{ {
$trustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP);
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, ''); Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, '');
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest(Request::create('/'))); $strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest(Request::create('/')));
$strategy->render('/', Request::create('/')); $this->assertSame('foo', $strategy->render('/', Request::create('/'))->getContent());
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, $trustedHeaderName);
} }
/** /**
@ -125,22 +133,6 @@ class InlineFragmentRendererTest extends TestCase
return $kernel; 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() public function testExceptionInSubRequestsDoesNotMangleOutputBuffers()
{ {
$resolver = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface')->getMock(); $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' => '*')); $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); $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 class Bar

View File

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

View File

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

View File

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

View File

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

View File

@ -25,6 +25,8 @@ class TranslationFilesTest extends TestCase
} else { } else {
\PHPUnit\Util\XML::loadfile($filePath, false, false, true); \PHPUnit\Util\XML::loadfile($filePath, false, false, true);
} }
$this->addToAssertionCount(1);
} }
public function provideTranslationFiles() 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\Tests\Fixtures\ScalarDummy;
use Symfony\Component\Serializer\Encoder\XmlEncoder; use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
use Symfony\Component\Serializer\Normalizer\CustomNormalizer; use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
@ -435,23 +434,12 @@ XML;
$this->encoder->decode('<?xml version="1.0"?><invalid><xml>', 'xml'); $this->encoder->decode('<?xml version="1.0"?><invalid><xml>', 'xml');
} }
/**
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
*/
public function testPreventsComplexExternalEntities() public function testPreventsComplexExternalEntities()
{ {
$oldCwd = getcwd(); $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(__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');
}
}
} }
public function testDecodeEmptyXml() 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('2', array('nl', 'fr', 'en', 'de', 'de_GE', 'hy', 'hy_AM')),
array('3', array('be', 'bs', 'cs', 'hr')), array('3', array('be', 'bs', 'cs', 'hr')),
array('4', array('cy', 'mt', 'sl')), array('4', array('cy', 'mt', 'sl')),
array('5', array()),
array('6', array('ar')), array('6', array('ar')),
); );
} }
@ -86,7 +85,6 @@ class PluralizationRulesTest extends TestCase
array('3', array('cbs')), array('3', array('cbs')),
array('4', array('gd', 'kw')), array('4', array('gd', 'kw')),
array('5', array('ga')), array('5', array('ga')),
array('6', array()),
); );
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -245,19 +245,23 @@ class ClassMetadataTest extends TestCase
public function testGroupSequencesWorkIfContainingDefaultGroup() public function testGroupSequencesWorkIfContainingDefaultGroup()
{ {
$this->metadata->setGroupSequence(array('Foo', $this->metadata->getDefaultGroup())); $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() public function testGroupSequencesFailIfNotContainingDefaultGroup()
{ {
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\GroupDefinitionException');
$this->metadata->setGroupSequence(array('Foo', 'Bar')); $this->metadata->setGroupSequence(array('Foo', 'Bar'));
} }
/**
* @expectedException \Symfony\Component\Validator\Exception\GroupDefinitionException
*/
public function testGroupSequencesFailIfContainingDefault() 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)); $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 = $factory->getMetadataFor(self::PARENT_CLASS);
$metadata->addConstraint(new Callback(function () {})); $metadata->addConstraint(new Callback(function () {}));
$this->assertCount(3, $metadata->getConstraints());
$metadata = $factory->getMetadataFor(self::CLASS_NAME); $metadata = $factory->getMetadataFor(self::CLASS_NAME);
$this->assertCount(6, $metadata->getConstraints());
} }
public function testGroupsFromParent() public function testGroupsFromParent()

View File

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