minor #21696 Refactored other PHPUnit method calls to work with namespaced PHPUnit 6 (peterrehm)

This PR was squashed before being merged into the 3.2 branch (closes #21696).

Discussion
----------

Refactored other PHPUnit method calls to work with namespaced PHPUnit 6

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

Continued work to make Symfony PHPUnit 6 compatible.

Commits
-------

9eeec8d Refactored other PHPUnit method calls to work with namespaced PHPUnit 6
This commit is contained in:
Nicolas Grekas 2017-02-21 11:04:39 +01:00
commit 94146f9b09
14 changed files with 66 additions and 27 deletions

View File

@ -39,6 +39,11 @@ class CachePoolsTest extends WebTestCase
{ {
try { try {
$this->doTestCachePools(array('root_config' => 'redis_config.yml', 'environment' => 'redis_cache'), RedisAdapter::class); $this->doTestCachePools(array('root_config' => 'redis_config.yml', 'environment' => 'redis_cache'), RedisAdapter::class);
} catch (\PHPUnit\Framework\Error\Warning $e) {
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
throw $e;
}
$this->markTestSkipped($e->getMessage());
} catch (\PHPUnit_Framework_Error_Warning $e) { } catch (\PHPUnit_Framework_Error_Warning $e) {
if (0 !== strpos($e->getMessage(), 'unable to connect to')) { if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
throw $e; throw $e;
@ -59,6 +64,11 @@ class CachePoolsTest extends WebTestCase
{ {
try { try {
$this->doTestCachePools(array('root_config' => 'redis_custom_config.yml', 'environment' => 'custom_redis_cache'), RedisAdapter::class); $this->doTestCachePools(array('root_config' => 'redis_custom_config.yml', 'environment' => 'custom_redis_cache'), RedisAdapter::class);
} catch (\PHPUnit\Framework\Error\Warning $e) {
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
throw $e;
}
$this->markTestSkipped($e->getMessage());
} catch (\PHPUnit_Framework_Error_Warning $e) { } catch (\PHPUnit_Framework_Error_Warning $e) {
if (0 !== strpos($e->getMessage(), 'unable to connect to')) { if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
throw $e; throw $e;

View File

@ -23,7 +23,7 @@ class PdoAdapterTest extends AdapterTestCase
public static function setupBeforeClass() public static function setupBeforeClass()
{ {
if (!extension_loaded('pdo_sqlite')) { if (!extension_loaded('pdo_sqlite')) {
throw new \PHPUnit_Framework_SkippedTestError('Extension pdo_sqlite required.'); self::markTestSkipped('Extension pdo_sqlite required.');
} }
self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache'); self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache');

View File

@ -24,7 +24,7 @@ class PdoDbalAdapterTest extends AdapterTestCase
public static function setupBeforeClass() public static function setupBeforeClass()
{ {
if (!extension_loaded('pdo_sqlite')) { if (!extension_loaded('pdo_sqlite')) {
throw new \PHPUnit_Framework_SkippedTestError('Extension pdo_sqlite required.'); self::markTestSkipped('Extension pdo_sqlite required.');
} }
self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache'); self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache');

View File

@ -112,7 +112,12 @@ class FactoryReturnTypePassTest extends TestCase
$factory->setFactory(array(FactoryDummy::class, 'createFactory')); $factory->setFactory(array(FactoryDummy::class, 'createFactory'));
if (!method_exists(\ReflectionMethod::class, 'getReturnType')) { if (!method_exists(\ReflectionMethod::class, 'getReturnType')) {
$this->setExpectedException(\RuntimeException::class, 'Please add the class to service "factory" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.'); if (method_exists($this, 'expectException')) {
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Please add the class to service "factory" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.');
} else {
$this->setExpectedException(\RuntimeException::class, 'Please add the class to service "factory" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.');
}
} }
$container->compile(); $container->compile();

View File

@ -84,7 +84,12 @@ class ParameterBagTest extends TestCase
'fiz' => array('bar' => array('boo' => 12)), 'fiz' => array('bar' => array('boo' => 12)),
)); ));
$this->setExpectedException('Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException', $exceptionMessage); if (method_exists($this, 'expectException')) {
$this->expectException(ParameterNotFoundException::class);
$this->expectExceptionMessage($exceptionMessage);
} else {
$this->setExpectedException(ParameterNotFoundException::class, $exceptionMessage);
}
$bag->get($parameterKey); $bag->get($parameterKey);
} }

View File

@ -75,7 +75,7 @@ class ParserCacheAdapterTest extends TestCase
{ {
$poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock(); $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
$parserCacheAdapter = new ParserCacheAdapter($poolMock); $parserCacheAdapter = new ParserCacheAdapter($poolMock);
$this->setExpectedException(\BadMethodCallException::class); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
$parserCacheAdapter->getItems(); $parserCacheAdapter->getItems();
} }
@ -85,7 +85,7 @@ class ParserCacheAdapterTest extends TestCase
$poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock(); $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
$key = 'key'; $key = 'key';
$parserCacheAdapter = new ParserCacheAdapter($poolMock); $parserCacheAdapter = new ParserCacheAdapter($poolMock);
$this->setExpectedException(\BadMethodCallException::class); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
$parserCacheAdapter->hasItem($key); $parserCacheAdapter->hasItem($key);
} }
@ -94,7 +94,7 @@ class ParserCacheAdapterTest extends TestCase
{ {
$poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock(); $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
$parserCacheAdapter = new ParserCacheAdapter($poolMock); $parserCacheAdapter = new ParserCacheAdapter($poolMock);
$this->setExpectedException(\BadMethodCallException::class); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
$parserCacheAdapter->clear(); $parserCacheAdapter->clear();
} }
@ -104,7 +104,7 @@ class ParserCacheAdapterTest extends TestCase
$poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock(); $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
$key = 'key'; $key = 'key';
$parserCacheAdapter = new ParserCacheAdapter($poolMock); $parserCacheAdapter = new ParserCacheAdapter($poolMock);
$this->setExpectedException(\BadMethodCallException::class); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
$parserCacheAdapter->deleteItem($key); $parserCacheAdapter->deleteItem($key);
} }
@ -114,7 +114,7 @@ class ParserCacheAdapterTest extends TestCase
$poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock(); $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
$keys = array('key'); $keys = array('key');
$parserCacheAdapter = new ParserCacheAdapter($poolMock); $parserCacheAdapter = new ParserCacheAdapter($poolMock);
$this->setExpectedException(\BadMethodCallException::class); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
$parserCacheAdapter->deleteItems($keys); $parserCacheAdapter->deleteItems($keys);
} }
@ -124,7 +124,7 @@ class ParserCacheAdapterTest extends TestCase
$poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock(); $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
$parserCacheAdapter = new ParserCacheAdapter($poolMock); $parserCacheAdapter = new ParserCacheAdapter($poolMock);
$cacheItemMock = $this->getMockBuilder('Psr\Cache\CacheItemInterface')->getMock(); $cacheItemMock = $this->getMockBuilder('Psr\Cache\CacheItemInterface')->getMock();
$this->setExpectedException(\BadMethodCallException::class); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
$parserCacheAdapter->saveDeferred($cacheItemMock); $parserCacheAdapter->saveDeferred($cacheItemMock);
} }
@ -133,7 +133,7 @@ class ParserCacheAdapterTest extends TestCase
{ {
$poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock(); $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
$parserCacheAdapter = new ParserCacheAdapter($poolMock); $parserCacheAdapter = new ParserCacheAdapter($poolMock);
$this->setExpectedException(\BadMethodCallException::class); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
$parserCacheAdapter->commit(); $parserCacheAdapter->commit();
} }

View File

@ -12,6 +12,8 @@
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer; namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateIntervalToArrayTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateIntervalToArrayTransformer;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
/** /**
* @author Steffen Roßkamp <steffen.rosskamp@gimmickmedia.de> * @author Steffen Roßkamp <steffen.rosskamp@gimmickmedia.de>
@ -159,7 +161,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
{ {
$transformer = new DateIntervalToArrayTransformer(); $transformer = new DateIntervalToArrayTransformer();
$this->assertNull($transformer->reverseTransform(null)); $this->assertNull($transformer->reverseTransform(null));
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException'); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(UnexpectedTypeException::class);
$transformer->reverseTransform('12345'); $transformer->reverseTransform('12345');
} }
@ -167,7 +169,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
{ {
$transformer = new DateIntervalToArrayTransformer(); $transformer = new DateIntervalToArrayTransformer();
$input = array('years' => '1'); $input = array('years' => '1');
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class);
$transformer->reverseTransform($input); $transformer->reverseTransform($input);
} }
@ -179,7 +181,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
'minutes' => '', 'minutes' => '',
'seconds' => '6', 'seconds' => '6',
); );
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException', 'This amount of "minutes" is invalid'); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class, 'This amount of "minutes" is invalid');
$transformer->reverseTransform($input); $transformer->reverseTransform($input);
} }
@ -189,7 +191,7 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
$input = array( $input = array(
'invert' => '1', 'invert' => '1',
); );
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException', 'The value of "invert" must be boolean'); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class, 'The value of "invert" must be boolean');
$transformer->reverseTransform($input); $transformer->reverseTransform($input);
} }

View File

@ -12,6 +12,8 @@
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer; namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateIntervalToStringTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateIntervalToStringTransformer;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
/** /**
* @author Steffen Roßkamp <steffen.rosskamp@gimmickmedia.de> * @author Steffen Roßkamp <steffen.rosskamp@gimmickmedia.de>
@ -73,7 +75,7 @@ class DateIntervalToStringTransformerTest extends DateIntervalTestCase
public function testTransformExpectsDateTime() public function testTransformExpectsDateTime()
{ {
$transformer = new DateIntervalToStringTransformer(); $transformer = new DateIntervalToStringTransformer();
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException'); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(UnexpectedTypeException::class);
$transformer->transform('1234'); $transformer->transform('1234');
} }
@ -94,7 +96,7 @@ class DateIntervalToStringTransformerTest extends DateIntervalTestCase
{ {
$reverseTransformer = new DateIntervalToStringTransformer($format, true); $reverseTransformer = new DateIntervalToStringTransformer($format, true);
$interval = new \DateInterval($output); $interval = new \DateInterval($output);
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class);
$this->assertDateIntervalEquals($interval, $reverseTransformer->reverseTransform($input)); $this->assertDateIntervalEquals($interval, $reverseTransformer->reverseTransform($input));
} }
@ -107,14 +109,14 @@ class DateIntervalToStringTransformerTest extends DateIntervalTestCase
public function testReverseTransformExpectsString() public function testReverseTransformExpectsString()
{ {
$reverseTransformer = new DateIntervalToStringTransformer(); $reverseTransformer = new DateIntervalToStringTransformer();
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException'); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(UnexpectedTypeException::class);
$reverseTransformer->reverseTransform(1234); $reverseTransformer->reverseTransform(1234);
} }
public function testReverseTransformExpectsValidIntervalString() public function testReverseTransformExpectsValidIntervalString()
{ {
$reverseTransformer = new DateIntervalToStringTransformer(); $reverseTransformer = new DateIntervalToStringTransformer();
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException'); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class);
$reverseTransformer->reverseTransform('10Y'); $reverseTransformer->reverseTransform('10Y');
} }
} }

View File

@ -74,6 +74,8 @@ class ClientTest extends TestCase
$domResponse = $m->invoke($client, $response); $domResponse = $m->invoke($client, $response);
try { try {
$this->assertEquals($expected31[0], $domResponse->getHeader('Set-Cookie')); $this->assertEquals($expected31[0], $domResponse->getHeader('Set-Cookie'));
} catch (\PHPUnit\Framework\ExpectationFailedException $e) {
$this->assertEquals($expected33[0], $domResponse->getHeader('Set-Cookie'));
} catch (\PHPUnit_Framework_ExpectationFailedException $e) { } catch (\PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertEquals($expected33[0], $domResponse->getHeader('Set-Cookie')); $this->assertEquals($expected33[0], $domResponse->getHeader('Set-Cookie'));
} }
@ -84,11 +86,15 @@ class ClientTest extends TestCase
$domResponse = $m->invoke($client, $response); $domResponse = $m->invoke($client, $response);
try { try {
$this->assertEquals($expected31[0], $domResponse->getHeader('Set-Cookie')); $this->assertEquals($expected31[0], $domResponse->getHeader('Set-Cookie'));
} catch (\PHPUnit\Framework\ExpectationFailedException $e) {
$this->assertEquals($expected33[0], $domResponse->getHeader('Set-Cookie'));
} catch (\PHPUnit_Framework_ExpectationFailedException $e) { } catch (\PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertEquals($expected33[0], $domResponse->getHeader('Set-Cookie')); $this->assertEquals($expected33[0], $domResponse->getHeader('Set-Cookie'));
} }
try { try {
$this->assertEquals($expected31, $domResponse->getHeader('Set-Cookie', false)); $this->assertEquals($expected31, $domResponse->getHeader('Set-Cookie', false));
} catch (\PHPUnit\Framework\ExpectationFailedException $e) {
$this->assertEquals($expected33, $domResponse->getHeader('Set-Cookie', false));
} catch (\PHPUnit_Framework_ExpectationFailedException $e) { } catch (\PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertEquals($expected33, $domResponse->getHeader('Set-Cookie', false)); $this->assertEquals($expected33, $domResponse->getHeader('Set-Cookie', false));
} }

View File

@ -118,7 +118,12 @@ class ControllerResolverTest extends TestCase
public function testGetControllerOnNonUndefinedFunction($controller, $exceptionName = null, $exceptionMessage = null) public function testGetControllerOnNonUndefinedFunction($controller, $exceptionName = null, $exceptionMessage = null)
{ {
$resolver = $this->createControllerResolver(); $resolver = $this->createControllerResolver();
$this->setExpectedException($exceptionName, $exceptionMessage); if (method_exists($this, 'expectException')) {
$this->expectException($exceptionName);
$this->expectExceptionMessage($exceptionMessage);
} else {
$this->setExpectedException($exceptionName, $exceptionMessage);
}
$request = Request::create('/'); $request = Request::create('/');
$request->attributes->set('_controller', $controller); $request->attributes->set('_controller', $controller);

View File

@ -73,7 +73,7 @@ class AdapterTest extends LdapTestCase
public function testLdapQueryWithoutBind() public function testLdapQueryWithoutBind()
{ {
$ldap = new Adapter($this->getLdapConfig()); $ldap = new Adapter($this->getLdapConfig());
$this->setExpectedException(NotBoundException::class); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(NotBoundException::class);
$query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', array()); $query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', array());
$query->execute(); $query->execute();
} }

View File

@ -59,7 +59,7 @@ class LdapManagerTest extends LdapTestCase
*/ */
public function testLdapAddInvalidEntry() public function testLdapAddInvalidEntry()
{ {
$this->setExpectedException(LdapException::class); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(LdapException::class);
$this->executeSearchQuery(1); $this->executeSearchQuery(1);
// The entry is missing a subject name // The entry is missing a subject name
@ -105,7 +105,7 @@ class LdapManagerTest extends LdapTestCase
public function testLdapUnboundAdd() public function testLdapUnboundAdd()
{ {
$this->adapter = new Adapter($this->getLdapConfig()); $this->adapter = new Adapter($this->getLdapConfig());
$this->setExpectedException(NotBoundException::class); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(NotBoundException::class);
$em = $this->adapter->getEntryManager(); $em = $this->adapter->getEntryManager();
$em->add(new Entry('')); $em->add(new Entry(''));
} }
@ -116,7 +116,7 @@ class LdapManagerTest extends LdapTestCase
public function testLdapUnboundRemove() public function testLdapUnboundRemove()
{ {
$this->adapter = new Adapter($this->getLdapConfig()); $this->adapter = new Adapter($this->getLdapConfig());
$this->setExpectedException(NotBoundException::class); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(NotBoundException::class);
$em = $this->adapter->getEntryManager(); $em = $this->adapter->getEntryManager();
$em->remove(new Entry('')); $em->remove(new Entry(''));
} }
@ -127,7 +127,7 @@ class LdapManagerTest extends LdapTestCase
public function testLdapUnboundUpdate() public function testLdapUnboundUpdate()
{ {
$this->adapter = new Adapter($this->getLdapConfig()); $this->adapter = new Adapter($this->getLdapConfig());
$this->setExpectedException(NotBoundException::class); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(NotBoundException::class);
$em = $this->adapter->getEntryManager(); $em = $this->adapter->getEntryManager();
$em->update(new Entry('')); $em->update(new Entry(''));
} }

View File

@ -78,7 +78,7 @@ class LdapTest extends TestCase
public function testCreateWithInvalidAdapterName() public function testCreateWithInvalidAdapterName()
{ {
$this->setExpectedException(DriverNotFoundException::class); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(DriverNotFoundException::class);
Ldap::create('foo'); Ldap::create('foo');
} }
} }

View File

@ -41,7 +41,11 @@ class ParserTest extends TestCase
if (E_USER_DEPRECATED !== $type) { if (E_USER_DEPRECATED !== $type) {
restore_error_handler(); restore_error_handler();
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args()); if (class_exists('PHPUnit_Util_ErrorHandler')) {
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
}
return call_user_func_array('PHPUnit\Util\ErrorHandler::handleError', func_get_args());
} }
$deprecations[] = $msg; $deprecations[] = $msg;