diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php index 6456639af3..63efd719b5 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php @@ -145,13 +145,16 @@ class ArrayNodeDefinitionTest extends TestCase public function testNestedPrototypedArrayNodes() { - $node = new ArrayNodeDefinition('root'); - $node + $nodeDefinition = new ArrayNodeDefinition('root'); + $nodeDefinition ->addDefaultChildrenIfNoneSet() ->prototype('array') ->prototype('array') ; - $node->getNode(); + $node = $nodeDefinition->getNode(); + + $this->assertInstanceOf('Symfony\Component\Config\Definition\PrototypedArrayNode', $node); + $this->assertInstanceOf('Symfony\Component\Config\Definition\PrototypedArrayNode', $node->getPrototype()); } public function testEnabledNodeDefaults() diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php index 16a10227cc..13304fae36 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php @@ -71,6 +71,8 @@ class TreeBuilderTest extends TestCase $root = $builder->root('override', 'array', new CustomNodeBuilder()); $root->prototype('bar')->end(); + + $this->assertInstanceOf('Symfony\Component\Config\Tests\Fixtures\BarNode', $root->getNode(true)->getPrototype()); } public function testAnExtendedNodeBuilderGetsPropagatedToTheChildren() @@ -79,7 +81,7 @@ class TreeBuilderTest extends TestCase $builder->root('propagation') ->children() - ->setNodeClass('extended', 'Symfony\Component\Config\Tests\Definition\Builder\VariableNodeDefinition') + ->setNodeClass('extended', 'Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition') ->node('foo', 'extended')->end() ->arrayNode('child') ->children() @@ -88,6 +90,15 @@ class TreeBuilderTest extends TestCase ->end() ->end() ->end(); + + $node = $builder->buildTree(); + $children = $node->getChildren(); + + $this->assertInstanceOf('Symfony\Component\Config\Definition\BooleanNode', $children['foo']); + + $childChildren = $children['child']->getChildren(); + + $this->assertInstanceOf('Symfony\Component\Config\Definition\BooleanNode', $childChildren['foo']); } public function testDefinitionInfoGetsTransferredToNode() diff --git a/src/Symfony/Component/Config/Tests/Fixtures/BarNode.php b/src/Symfony/Component/Config/Tests/Fixtures/BarNode.php new file mode 100644 index 0000000000..0b9c32deda --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Fixtures/BarNode.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Config\Tests\Fixtures; + +use Symfony\Component\Config\Definition\ArrayNode; + +class BarNode extends ArrayNode +{ +} diff --git a/src/Symfony/Component/Config/Tests/Fixtures/Builder/BarNodeDefinition.php b/src/Symfony/Component/Config/Tests/Fixtures/Builder/BarNodeDefinition.php index 47701c1b29..0d46f3d2c8 100644 --- a/src/Symfony/Component/Config/Tests/Fixtures/Builder/BarNodeDefinition.php +++ b/src/Symfony/Component/Config/Tests/Fixtures/Builder/BarNodeDefinition.php @@ -12,10 +12,12 @@ namespace Symfony\Component\Config\Tests\Definition\Builder; use Symfony\Component\Config\Definition\Builder\NodeDefinition; +use Symfony\Component\Config\Tests\Fixtures\BarNode; class BarNodeDefinition extends NodeDefinition { protected function createNode() { + return new BarNode($this->name); } } diff --git a/src/Symfony/Component/Form/Tests/CompoundFormTest.php b/src/Symfony/Component/Form/Tests/CompoundFormTest.php index 3738a4c953..b9b93e54c1 100644 --- a/src/Symfony/Component/Form/Tests/CompoundFormTest.php +++ b/src/Symfony/Component/Form/Tests/CompoundFormTest.php @@ -299,6 +299,8 @@ class CompoundFormTest extends AbstractFormTest public function testRemoveIgnoresUnknownName() { $this->form->remove('notexisting'); + + $this->assertCount(0, $this->form); } public function testArrayAccess() diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index 983397b09d..3e36c7dd29 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -126,9 +126,9 @@ class ChoiceTypeTest extends BaseTypeTest public function testChoiceListAndChoicesCanBeEmpty() { - $this->factory->create(static::TESTED_TYPE, null, array( + $this->assertInstanceOf('Symfony\Component\Form\FormInterface', $this->factory->create(static::TESTED_TYPE, null, array( 'choices_as_values' => true, - )); + ))); } public function testExpandedChoicesOptionsTurnIntoChildren() @@ -2251,10 +2251,10 @@ class ChoiceTypeTest extends BaseTypeTest // https://github.com/symfony/symfony/issues/3298 public function testInitializeWithEmptyChoices() { - $this->factory->createNamed('name', static::TESTED_TYPE, null, array( + $this->assertInstanceOf('Symfony\Component\Form\FormInterface', $this->factory->createNamed('name', static::TESTED_TYPE, null, array( 'choices' => array(), 'choices_as_values' => true, - )); + ))); } public function testInitializeWithDefaultObjectChoice() diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php index 3d8e86defb..7765f4706d 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php @@ -43,11 +43,13 @@ class CountryTypeTest extends BaseTypeTest $choices = $this->factory->create(static::TESTED_TYPE, 'country') ->createView()->vars['choices']; + $countryCodes = array(); + foreach ($choices as $choice) { - if ('ZZ' === $choice->value) { - $this->fail('Should not contain choice "ZZ"'); - } + $countryCodes[] = $choice->value; } + + $this->assertNotContains('ZZ', $countryCodes); } public function testSubmitNull($expected = null, $norm = null, $view = null) diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php index dca17c3400..9a80bdd87b 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php @@ -273,7 +273,7 @@ class DateTimeTypeTest extends BaseTypeTest { // Throws an exception if "data_class" option is not explicitly set // to null in the type - $this->factory->create(static::TESTED_TYPE, new \DateTime()); + $this->assertInstanceOf('Symfony\Component\Form\FormInterface', $this->factory->create(static::TESTED_TYPE, new \DateTime())); } public function testSingleTextWidgetShouldUseTheRightInputType() diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php index 05fc63f055..6c3806d23c 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php @@ -711,7 +711,7 @@ class DateTypeTest extends BaseTypeTest { // Throws an exception if "data_class" option is not explicitly set // to null in the type - $this->factory->create(static::TESTED_TYPE, new \DateTime()); + $this->assertInstanceOf('Symfony\Component\Form\FormInterface', $this->factory->create(static::TESTED_TYPE, new \DateTime())); } public function testSingleTextWidgetShouldUseTheRightInputType() diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php index 5f5d5def69..1ff4057d5f 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php @@ -149,23 +149,23 @@ class FormTypeTest extends BaseTypeTest public function testDataClassMayBeNull() { - $this->factory->createBuilder(static::TESTED_TYPE, null, array( + $this->assertInstanceOf('Symfony\Component\Form\FormBuilderInterface', $this->factory->createBuilder(static::TESTED_TYPE, null, array( 'data_class' => null, - )); + ))); } public function testDataClassMayBeAbstractClass() { - $this->factory->createBuilder(static::TESTED_TYPE, null, array( + $this->assertInstanceOf('Symfony\Component\Form\FormBuilderInterface', $this->factory->createBuilder(static::TESTED_TYPE, null, array( 'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AbstractAuthor', - )); + ))); } public function testDataClassMayBeInterface() { - $this->factory->createBuilder(static::TESTED_TYPE, null, array( + $this->assertInstanceOf('Symfony\Component\Form\FormBuilderInterface', $this->factory->createBuilder(static::TESTED_TYPE, null, array( 'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AuthorInterface', - )); + ))); } /** @@ -652,7 +652,7 @@ class FormTypeTest extends BaseTypeTest $form = $builder->getForm(); //This method should not throw a Fatal Error Exception. - $form->getErrorsAsString(); + $this->assertInternalType('string', $form->getErrorsAsString()); } public function testSubmitNull($expected = null, $norm = null, $view = null) diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php index 8537c96fe0..48fd5964db 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php @@ -488,7 +488,7 @@ class TimeTypeTest extends BaseTypeTest { // Throws an exception if "data_class" option is not explicitly set // to null in the type - $this->factory->create(static::TESTED_TYPE, new \DateTime()); + $this->assertInstanceOf('Symfony\Component\Form\FormInterface', $this->factory->create(static::TESTED_TYPE, new \DateTime())); } public function testSingleTextWidgetShouldUseTheRightInputType() diff --git a/src/Symfony/Component/Form/Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php b/src/Symfony/Component/Form/Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php index 22f3f9d8e3..f04d092e87 100644 --- a/src/Symfony/Component/Form/Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php @@ -46,16 +46,21 @@ class DependencyInjectionExtensionTest extends TestCase public function testThrowExceptionForInvalidExtendedType() { + $formTypeExtension = $this->createFormTypeExtensionMock('unmatched'); + $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $container->expects($this->any()) ->method('get') ->with('extension') - ->willReturn($this->createFormTypeExtensionMock('unmatched')); + ->willReturn($formTypeExtension); $extension = new DependencyInjectionExtension($container, array(), array('test' => array('extension')), array()); - $extension->getTypeExtensions('test'); + $extensions = $extension->getTypeExtensions('test'); + + $this->assertCount(1, $extensions); + $this->assertSame($formTypeExtension, $extensions[0]); } public function testGetTypeGuesser() diff --git a/src/Symfony/Component/Form/Tests/FormBuilderTest.php b/src/Symfony/Component/Form/Tests/FormBuilderTest.php index fae2b1623d..4f0a813ccd 100644 --- a/src/Symfony/Component/Form/Tests/FormBuilderTest.php +++ b/src/Symfony/Component/Form/Tests/FormBuilderTest.php @@ -161,6 +161,8 @@ class FormBuilderTest extends TestCase { $this->builder->add(new ButtonBuilder('reset')); $this->builder->add(new SubmitButtonBuilder('submit')); + + $this->assertCount(2, $this->builder->all()); } public function testGetUnknown() diff --git a/src/Symfony/Component/Form/Tests/FormConfigTest.php b/src/Symfony/Component/Form/Tests/FormConfigTest.php index 21eabba871..bb922bf3d6 100644 --- a/src/Symfony/Component/Form/Tests/FormConfigTest.php +++ b/src/Symfony/Component/Form/Tests/FormConfigTest.php @@ -12,9 +12,7 @@ namespace Symfony\Component\Form\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Form\FormConfigBuilder; -use Symfony\Component\Form\Exception\InvalidArgumentException; /** * @author Bernhard Schussek @@ -24,72 +22,65 @@ class FormConfigTest extends TestCase public function getHtml4Ids() { return array( - array('z0', true), - array('A0', true), - array('A9', true), - array('Z0', true), - array('#', false), - array('a#', false), - array('a$', false), - array('a%', false), - array('a ', false), - array("a\t", false), - array("a\n", false), - array('a-', true), - array('a_', true), - array('a:', true), + array('z0'), + array('A0'), + array('A9'), + array('Z0'), + array('#', 'Symfony\Component\Form\Exception\InvalidArgumentException'), + array('a#', 'Symfony\Component\Form\Exception\InvalidArgumentException'), + array('a$', 'Symfony\Component\Form\Exception\InvalidArgumentException'), + array('a%', 'Symfony\Component\Form\Exception\InvalidArgumentException'), + array('a ', 'Symfony\Component\Form\Exception\InvalidArgumentException'), + array("a\t", 'Symfony\Component\Form\Exception\InvalidArgumentException'), + array("a\n", 'Symfony\Component\Form\Exception\InvalidArgumentException'), + array('a-'), + array('a_'), + array('a:'), // Periods are allowed by the HTML4 spec, but disallowed by us // because they break the generated property paths - array('a.', false), + array('a.', 'Symfony\Component\Form\Exception\InvalidArgumentException'), // Contrary to the HTML4 spec, we allow names starting with a // number, otherwise naming fields by collection indices is not // possible. // For root forms, leading digits will be stripped from the // "id" attribute to produce valid HTML4. - array('0', true), - array('9', true), + array('0'), + array('9'), // Contrary to the HTML4 spec, we allow names starting with an // underscore, since this is already a widely used practice in // Symfony. // For root forms, leading underscores will be stripped from the // "id" attribute to produce valid HTML4. - array('_', true), + array('_'), // Integers are allowed - array(0, true), - array(123, true), + array(0), + array(123), // NULL is allowed - array(null, true), + array(null), // Other types are not - array(1.23, false), - array(5., false), - array(true, false), - array(new \stdClass(), false), + array(1.23, 'Symfony\Component\Form\Exception\UnexpectedTypeException'), + array(5., 'Symfony\Component\Form\Exception\UnexpectedTypeException'), + array(true, 'Symfony\Component\Form\Exception\UnexpectedTypeException'), + array(new \stdClass(), 'Symfony\Component\Form\Exception\UnexpectedTypeException'), ); } /** * @dataProvider getHtml4Ids */ - public function testNameAcceptsOnlyNamesValidAsIdsInHtml4($name, $accepted) + public function testNameAcceptsOnlyNamesValidAsIdsInHtml4($name, $expectedException = null) { $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); - try { - new FormConfigBuilder($name, null, $dispatcher); - if (!$accepted) { - $this->fail(sprintf('The value "%s" should not be accepted', $name)); - } - } catch (UnexpectedTypeException $e) { - // if the value was not accepted, but should be, rethrow exception - if ($accepted) { - throw $e; - } - } catch (InvalidArgumentException $e) { - // if the value was not accepted, but should be, rethrow exception - if ($accepted) { - throw $e; - } + if (null !== $expectedException && method_exists($this, 'expectException')) { + $this->expectException($expectedException); + } elseif (null !== $expectedException) { + $this->setExpectedException($expectedException); } + + $formConfigBuilder = new FormConfigBuilder($name, null, $dispatcher); + + $this->assertSame((string) $name, $formConfigBuilder->getName()); } public function testGetRequestHandlerCreatesNativeRequestHandlerIfNotSet() @@ -109,27 +100,42 @@ class FormConfigTest extends TestCase public function testSetMethodAllowsGet() { - $this->getConfigBuilder()->setMethod('GET'); + $formConfigBuilder = $this->getConfigBuilder(); + $formConfigBuilder->setMethod('GET'); + + self::assertSame('GET', $formConfigBuilder->getMethod()); } public function testSetMethodAllowsPost() { - $this->getConfigBuilder()->setMethod('POST'); + $formConfigBuilder = $this->getConfigBuilder(); + $formConfigBuilder->setMethod('POST'); + + self::assertSame('POST', $formConfigBuilder->getMethod()); } public function testSetMethodAllowsPut() { - $this->getConfigBuilder()->setMethod('PUT'); + $formConfigBuilder = $this->getConfigBuilder(); + $formConfigBuilder->setMethod('PUT'); + + self::assertSame('PUT', $formConfigBuilder->getMethod()); } public function testSetMethodAllowsDelete() { - $this->getConfigBuilder()->setMethod('DELETE'); + $formConfigBuilder = $this->getConfigBuilder(); + $formConfigBuilder->setMethod('DELETE'); + + self::assertSame('DELETE', $formConfigBuilder->getMethod()); } public function testSetMethodAllowsPatch() { - $this->getConfigBuilder()->setMethod('PATCH'); + $formConfigBuilder = $this->getConfigBuilder(); + $formConfigBuilder->setMethod('PATCH'); + + self::assertSame('PATCH', $formConfigBuilder->getMethod()); } /** diff --git a/src/Symfony/Component/Form/Tests/SimpleFormTest.php b/src/Symfony/Component/Form/Tests/SimpleFormTest.php index 62c94c7490..6fd9e36648 100644 --- a/src/Symfony/Component/Form/Tests/SimpleFormTest.php +++ b/src/Symfony/Component/Form/Tests/SimpleFormTest.php @@ -919,12 +919,11 @@ class SimpleFormTest extends AbstractFormTest public function testSubmittingWrongDataIsIgnored() { - $test = $this; + $called = 0; $child = $this->getBuilder('child', $this->dispatcher); - $child->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($test) { - // child form doesn't receive the wrong data that is submitted on parent - $test->assertNull($event->getData()); + $child->addEventListener(FormEvents::PRE_SUBMIT, function () use (&$called) { + ++$called; }); $parent = $this->getBuilder('parent', new EventDispatcher()) @@ -934,6 +933,8 @@ class SimpleFormTest extends AbstractFormTest ->getForm(); $parent->submit('not-an-array'); + + $this->assertSame(0, $called, 'PRE_SUBMIT event listeners are not called for wrong data'); } public function testHandleRequestForwardsToRequestHandler() @@ -1037,15 +1038,17 @@ class SimpleFormTest extends AbstractFormTest public function testSubmitIsNeverFiredIfInheritData() { - $test = $this; + $called = 0; $form = $this->getBuilder() - ->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) use ($test) { - $test->fail('The SUBMIT event should not be fired'); + ->addEventListener(FormEvents::SUBMIT, function () use (&$called) { + ++$called; }) ->setInheritData(true) ->getForm(); $form->submit('foo'); + + $this->assertSame(0, $called, 'The SUBMIT event is not fired when data are inherited from the parent form'); } public function testInitializeSetsDefaultData() diff --git a/src/Symfony/Component/Form/Tests/Util/OrderedHashMapTest.php b/src/Symfony/Component/Form/Tests/Util/OrderedHashMapTest.php index 4328919651..89735ea618 100644 --- a/src/Symfony/Component/Form/Tests/Util/OrderedHashMapTest.php +++ b/src/Symfony/Component/Form/Tests/Util/OrderedHashMapTest.php @@ -114,8 +114,11 @@ class OrderedHashMapTest extends TestCase public function testUnsetNonExistingSucceeds() { $map = new OrderedHashMap(); + $map['second'] = 2; unset($map['first']); + + $this->assertSame(array('second' => 2), iterator_to_array($map)); } public function testEmptyIteration() diff --git a/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php b/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php index 61aa74861d..297ee3d8d3 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php @@ -17,14 +17,14 @@ use Symfony\Component\HttpFoundation\IpUtils; class IpUtilsTest extends TestCase { /** - * @dataProvider testIpv4Provider + * @dataProvider getIpv4Data */ public function testIpv4($matches, $remoteAddr, $cidr) { $this->assertSame($matches, IpUtils::checkIp($remoteAddr, $cidr)); } - public function testIpv4Provider() + public function getIpv4Data() { return array( array(true, '192.168.1.1', '192.168.1.1'), @@ -43,7 +43,7 @@ class IpUtilsTest extends TestCase } /** - * @dataProvider testIpv6Provider + * @dataProvider getIpv6Data */ public function testIpv6($matches, $remoteAddr, $cidr) { @@ -54,7 +54,7 @@ class IpUtilsTest extends TestCase $this->assertSame($matches, IpUtils::checkIp($remoteAddr, $cidr)); } - public function testIpv6Provider() + public function getIpv6Data() { return array( array(true, '2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'), diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestMatcherTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestMatcherTest.php index 6f864d4468..b5d80048ff 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestMatcherTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestMatcherTest.php @@ -18,7 +18,7 @@ use Symfony\Component\HttpFoundation\Request; class RequestMatcherTest extends TestCase { /** - * @dataProvider testMethodFixtures + * @dataProvider getMethodData */ public function testMethod($requestMethod, $matcherMethod, $isMatch) { @@ -32,7 +32,7 @@ class RequestMatcherTest extends TestCase $this->assertSame($isMatch, $matcher->matches($request)); } - public function testMethodFixtures() + public function getMethodData() { return array( array('get', 'get', true), @@ -64,7 +64,7 @@ class RequestMatcherTest extends TestCase } /** - * @dataProvider testHostFixture + * @dataProvider getHostData */ public function testHost($pattern, $isMatch) { @@ -78,7 +78,7 @@ class RequestMatcherTest extends TestCase $this->assertSame($isMatch, $matcher->matches($request)); } - public function testHostFixture() + public function getHostData() { return array( array('.*\.example\.com', true), diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 2d8baa7142..6f9d76b483 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -306,6 +306,10 @@ class RequestTest extends TestCase $request->setFormat($format, $mimeTypes); foreach ($mimeTypes as $mime) { $this->assertEquals($format, $request->getFormat($mime)); + + if (null !== $format) { + $this->assertEquals($mimeTypes[0], $request->getMimeType($format)); + } } } @@ -315,17 +319,6 @@ class RequestTest extends TestCase $this->assertEquals('json', $request->getFormat('application/json; charset=utf-8')); } - /** - * @dataProvider getFormatToMimeTypeMapProvider - */ - public function testGetMimeTypeFromFormat($format, $mimeTypes) - { - if (null !== $format) { - $request = new Request(); - $this->assertEquals($mimeTypes[0], $request->getMimeType($format)); - } - } - public function testGetFormatWithCustomMimeType() { $request = new Request(); @@ -821,7 +814,7 @@ class RequestTest extends TestCase } /** - * @dataProvider testGetClientIpsProvider + * @dataProvider getClientIpsProvider */ public function testGetClientIp($expected, $remoteAddr, $httpForwardedFor, $trustedProxies) { @@ -833,7 +826,7 @@ class RequestTest extends TestCase } /** - * @dataProvider testGetClientIpsProvider + * @dataProvider getClientIpsProvider */ public function testGetClientIps($expected, $remoteAddr, $httpForwardedFor, $trustedProxies) { @@ -845,7 +838,7 @@ class RequestTest extends TestCase } /** - * @dataProvider testGetClientIpsForwardedProvider + * @dataProvider getClientIpsForwardedProvider */ public function testGetClientIpsForwarded($expected, $remoteAddr, $httpForwarded, $trustedProxies) { @@ -856,7 +849,7 @@ class RequestTest extends TestCase Request::setTrustedProxies(array()); } - public function testGetClientIpsForwardedProvider() + public function getClientIpsForwardedProvider() { // $expected $remoteAddr $httpForwarded $trustedProxies return array( @@ -869,7 +862,7 @@ class RequestTest extends TestCase ); } - public function testGetClientIpsProvider() + public function getClientIpsProvider() { // $expected $remoteAddr $httpForwardedFor $trustedProxies return array( @@ -926,7 +919,7 @@ class RequestTest extends TestCase /** * @expectedException \Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException - * @dataProvider testGetClientIpsWithConflictingHeadersProvider + * @dataProvider getClientIpsWithConflictingHeadersProvider */ public function testGetClientIpsWithConflictingHeaders($httpForwarded, $httpXForwardedFor) { @@ -945,7 +938,7 @@ class RequestTest extends TestCase $request->getClientIps(); } - public function testGetClientIpsWithConflictingHeadersProvider() + public function getClientIpsWithConflictingHeadersProvider() { // $httpForwarded $httpXForwardedFor return array( @@ -958,9 +951,9 @@ class RequestTest extends TestCase } /** - * @dataProvider testGetClientIpsWithAgreeingHeadersProvider + * @dataProvider getClientIpsWithAgreeingHeadersProvider */ - public function testGetClientIpsWithAgreeingHeaders($httpForwarded, $httpXForwardedFor) + public function testGetClientIpsWithAgreeingHeaders($httpForwarded, $httpXForwardedFor, $expectedIps) { $request = new Request(); @@ -974,21 +967,23 @@ class RequestTest extends TestCase $request->initialize(array(), array(), array(), array(), array(), $server); - $request->getClientIps(); + $clientIps = $request->getClientIps(); Request::setTrustedProxies(array()); + + $this->assertSame($expectedIps, $clientIps); } - public function testGetClientIpsWithAgreeingHeadersProvider() + public function getClientIpsWithAgreeingHeadersProvider() { // $httpForwarded $httpXForwardedFor return array( - array('for="192.0.2.60"', '192.0.2.60'), - array('for=192.0.2.60, for=87.65.43.21', '192.0.2.60,87.65.43.21'), - array('for="[::face]", for=192.0.2.60', '::face,192.0.2.60'), - array('for="192.0.2.60:80"', '192.0.2.60'), - array('for=192.0.2.60;proto=http;by=203.0.113.43', '192.0.2.60'), - array('for="[2001:db8:cafe::17]:4711"', '2001:db8:cafe::17'), + array('for="192.0.2.60"', '192.0.2.60', array('192.0.2.60')), + array('for=192.0.2.60, for=87.65.43.21', '192.0.2.60,87.65.43.21', array('87.65.43.21', '192.0.2.60')), + array('for="[::face]", for=192.0.2.60', '::face,192.0.2.60', array('192.0.2.60', '::face')), + array('for="192.0.2.60:80"', '192.0.2.60', array('192.0.2.60')), + array('for=192.0.2.60;proto=http;by=203.0.113.43', '192.0.2.60', array('192.0.2.60')), + array('for="[2001:db8:cafe::17]:4711"', '2001:db8:cafe::17', array('2001:db8:cafe::17')), ); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php index 4d5d337a3c..fa93507a41 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php @@ -177,6 +177,8 @@ class SessionTest extends TestCase { $this->session->start(); $this->session->save(); + + $this->assertFalse($this->session->isStarted()); } public function testGetId() diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MetadataBagTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MetadataBagTest.php index 1f55a2d5c4..159e62114e 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MetadataBagTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MetadataBagTest.php @@ -103,6 +103,9 @@ class MetadataBagTest extends TestCase public function testClear() { $this->bag->clear(); + + // the clear method has no side effects, we just want to ensure it doesn't trigger any exceptions + $this->addToAssertionCount(1); } public function testSkipLastUsedUpdate() diff --git a/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php index 844274b1e7..5874145348 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php @@ -51,10 +51,12 @@ class StreamedResponseTest extends TestCase public function testPrepareWithHeadRequest() { - $response = new StreamedResponse(function () { echo 'foo'; }); + $response = new StreamedResponse(function () { echo 'foo'; }, 200, array('Content-Length' => '123')); $request = Request::create('/', 'HEAD'); $response->prepare($request); + + $this->assertSame('123', $response->headers->get('Content-Length')); } public function testPrepareWithCacheHeaders() diff --git a/src/Symfony/Component/Security/Acl/Tests/Dbal/MutableAclProviderTest.php b/src/Symfony/Component/Security/Acl/Tests/Dbal/MutableAclProviderTest.php index e7de0b5487..f119168221 100644 --- a/src/Symfony/Component/Security/Acl/Tests/Dbal/MutableAclProviderTest.php +++ b/src/Symfony/Component/Security/Acl/Tests/Dbal/MutableAclProviderTest.php @@ -19,8 +19,6 @@ use Symfony\Component\Security\Acl\Model\EntryInterface; use Symfony\Component\Security\Acl\Domain\Entry; use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity; use Symfony\Component\Security\Acl\Domain\Acl; -use Symfony\Component\Security\Acl\Exception\AclNotFoundException; -use Symfony\Component\Security\Acl\Exception\ConcurrentModificationException; use Symfony\Component\Security\Acl\Dbal\AclProvider; use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy; use Symfony\Component\Security\Acl\Dbal\MutableAclProvider; @@ -79,23 +77,25 @@ class MutableAclProviderTest extends TestCase $this->assertTrue($acl->getObjectIdentity()->equals($oid)); } + /** + * @expectedException \Symfony\Component\Security\Acl\Exception\AclNotFoundException + */ public function testDeleteAcl() { $provider = $this->getProvider(); $oid = new ObjectIdentity(1, 'Foo'); - $acl = $provider->createAcl($oid); + $provider->createAcl($oid); $provider->deleteAcl($oid); $loadedAcls = $this->getField($provider, 'loadedAcls'); $this->assertCount(0, $loadedAcls['Foo']); - try { - $provider->findAcl($oid); - $this->fail('ACL has not been properly deleted.'); - } catch (AclNotFoundException $e) { - } + $provider->findAcl($oid); } + /** + * @expectedException \Symfony\Component\Security\Acl\Exception\AclNotFoundException + */ public function testDeleteAclDeletesChildren() { $provider = $this->getProvider(); @@ -105,11 +105,7 @@ class MutableAclProviderTest extends TestCase $provider->updateAcl($acl); $provider->deleteAcl($parentAcl->getObjectIdentity()); - try { - $provider->findAcl(new ObjectIdentity(1, 'Foo')); - $this->fail('Child-ACLs have not been deleted.'); - } catch (AclNotFoundException $e) { - } + $provider->findAcl(new ObjectIdentity(1, 'Foo')); } public function testFindAclsAddsPropertyListener() @@ -273,6 +269,9 @@ class MutableAclProviderTest extends TestCase $provider->updateAcl($acl); } + /** + * @expectedException \Symfony\Component\Security\Acl\Exception\ConcurrentModificationException + */ public function testUpdateAclThrowsExceptionOnConcurrentModificationOfSharedProperties() { $provider = $this->getProvider(); @@ -291,11 +290,7 @@ class MutableAclProviderTest extends TestCase $acl1->insertClassAce($sid, 3); $acl2->insertClassAce($sid, 5); - try { - $provider->updateAcl($acl1); - $this->fail('Provider failed to detect a concurrent modification.'); - } catch (ConcurrentModificationException $e) { - } + $provider->updateAcl($acl1); } public function testUpdateAcl() @@ -366,7 +361,7 @@ class MutableAclProviderTest extends TestCase $this->assertEquals($newParentParentAcl->getId(), $reloadedAcl->getParentAcl()->getParentAcl()->getId()); } - public function testUpdateAclInsertingMultipleObjectFieldAcesThrowsDBConstraintViolations() + public function testUpdateAclInsertingMultipleObjectFieldAcesDoesNotThrowDBConstraintViolations() { $provider = $this->getProvider(); $oid = new ObjectIdentity(1, 'Foo'); @@ -386,9 +381,11 @@ class MutableAclProviderTest extends TestCase $acl = $provider->findAcl($oid); $acl->insertObjectFieldAce($fieldName, $sid3, 4); $provider->updateAcl($acl); + + $this->assertCount(3, $provider->findAcl($oid)->getObjectFieldAces($fieldName)); } - public function testUpdateAclDeletingObjectFieldAcesThrowsDBConstraintViolations() + public function testUpdateAclDeletingObjectFieldAcesDoesNotThrowDBConstraintViolations() { $provider = $this->getProvider(); $oid = new ObjectIdentity(1, 'Foo'); @@ -412,6 +409,8 @@ class MutableAclProviderTest extends TestCase $acl = $provider->findAcl($oid); $acl->insertObjectFieldAce($fieldName, $sid3, 4); $provider->updateAcl($acl); + + $this->assertCount(2, $provider->findAcl($oid)->getObjectFieldAces($fieldName)); } public function testUpdateUserSecurityIdentity() diff --git a/src/Symfony/Component/Security/Acl/Tests/Domain/PermissionGrantingStrategyTest.php b/src/Symfony/Component/Security/Acl/Tests/Domain/PermissionGrantingStrategyTest.php index f77262654f..abb89eceac 100644 --- a/src/Symfony/Component/Security/Acl/Tests/Domain/PermissionGrantingStrategyTest.php +++ b/src/Symfony/Component/Security/Acl/Tests/Domain/PermissionGrantingStrategyTest.php @@ -17,7 +17,6 @@ use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity; use Symfony\Component\Security\Acl\Domain\Acl; use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity; use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy; -use Symfony\Component\Security\Acl\Exception\NoAceFoundException; class PermissionGrantingStrategyTest extends TestCase { @@ -152,11 +151,13 @@ class PermissionGrantingStrategyTest extends TestCase $acl->insertObjectAce($sid, $aceMask, 0, true, $maskStrategy); if (false === $result) { - try { - $strategy->isGranted($acl, array($requiredMask), array($sid)); - $this->fail('The ACE is not supposed to match.'); - } catch (NoAceFoundException $e) { + if (method_exists($this, 'expectException')) { + $this->expectException('Symfony\Component\Security\Acl\Exception\NoAceFoundException'); + } else { + $this->setExpectedException('Symfony\Component\Security\Acl\Exception\NoAceFoundException'); } + + $strategy->isGranted($acl, array($requiredMask), array($sid)); } else { $this->assertTrue($strategy->isGranted($acl, array($requiredMask), array($sid))); } diff --git a/src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php b/src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php index 10c8da692a..b6b6ab8c80 100644 --- a/src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php @@ -39,11 +39,20 @@ class BCryptPasswordEncoderTest extends TestCase new BCryptPasswordEncoder(32); } - public function testCostInRange() + /** + * @dataProvider validRangeData + */ + public function testCostInRange($cost) { - for ($cost = 4; $cost <= 31; ++$cost) { - new BCryptPasswordEncoder($cost); - } + $this->assertInstanceOf('Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder', new BCryptPasswordEncoder($cost)); + } + + public function validRangeData() + { + $costs = range(4, 31); + array_walk($costs, function (&$cost) { $cost = array($cost); }); + + return $costs; } public function testResultLength() diff --git a/src/Symfony/Component/Security/Core/Tests/LegacySecurityContextTest.php b/src/Symfony/Component/Security/Core/Tests/LegacySecurityContextTest.php index 3661c7be95..3c842aae76 100644 --- a/src/Symfony/Component/Security/Core/Tests/LegacySecurityContextTest.php +++ b/src/Symfony/Component/Security/Core/Tests/LegacySecurityContextTest.php @@ -86,7 +86,8 @@ class LegacySecurityContextTest extends TestCase { $authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(); $accessDecisionManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')->getMock(); - new SecurityContext($authenticationManager, $accessDecisionManager); + + $this->assertInstanceOf('Symfony\Component\Security\Core\SecurityContext', new SecurityContext($authenticationManager, $accessDecisionManager)); } /** diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/DigestDataTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/DigestDataTest.php index 2238a74188..7317e2f83c 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/DigestDataTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/DigestDataTest.php @@ -100,6 +100,9 @@ class DigestDataTest extends TestCase $this->assertEquals('"u\\ser"', $digestAuth->getUsername()); } + /** + * @group time-sensitive + */ public function testValidateAndDecode() { $time = microtime(true); @@ -112,11 +115,11 @@ class DigestDataTest extends TestCase 'response="b52938fc9e6d7c01be7702ece9031b42"' ); - try { - $digestAuth->validateAndDecode($key, 'Welcome, robot!'); - } catch (\Exception $e) { - $this->fail(sprintf('testValidateAndDecode fail with message: %s', $e->getMessage())); - } + $digestAuth->validateAndDecode($key, 'Welcome, robot!'); + + sleep(1); + + $this->assertTrue($digestAuth->isNonceExpired()); } public function testCalculateServerDigest()