Tests > fix "Call to undefined method setExpectedException()" bug > make compatible with PHPUnit 8.0 (and PHP 7.2+)

This commit is contained in:
Meritoo
2019-04-02 08:31:24 +02:00
parent 8b5a530bbc
commit c89b6da0db
7 changed files with 20 additions and 20 deletions

View File

@@ -33,7 +33,7 @@ class UnknownTypeExceptionTest extends BaseTestCase
public function testTheException() public function testTheException()
{ {
$this->setExpectedException(UnknownTestTypeException::class); $this->expectException(UnknownTestTypeException::class);
self::assertEmpty((new TestService())->getTranslatedType('test_3')); self::assertEmpty((new TestService())->getTranslatedType('test_3'));
} }
} }

View File

@@ -49,8 +49,8 @@ class BundleTest extends BaseTestCase
$template = 'Name of bundle \'%s\' is incorrect. It should start with big letter and end with "Bundle". Is' $template = 'Name of bundle \'%s\' is incorrect. It should start with big letter and end with "Bundle". Is'
. ' there everything ok?'; . ' there everything ok?';
$message = sprintf($template, $bundleName); $this->expectException(IncorrectBundleNameException::class);
$this->setExpectedException(IncorrectBundleNameException::class, $message); $this->expectExceptionMessage(sprintf($template, $bundleName));
Bundle::getBundleViewPath($viewPath, $bundleName); Bundle::getBundleViewPath($viewPath, $bundleName);
} }
@@ -90,7 +90,7 @@ class BundleTest extends BaseTestCase
*/ */
public function testGetShortBundleNameUsingEmptyValue($emptyValue) public function testGetShortBundleNameUsingEmptyValue($emptyValue)
{ {
$this->setExpectedException(IncorrectBundleNameException::class); $this->expectException(IncorrectBundleNameException::class);
Bundle::getShortBundleName($emptyValue); Bundle::getShortBundleName($emptyValue);
} }
@@ -102,7 +102,7 @@ class BundleTest extends BaseTestCase
*/ */
public function testGetShortBundleNameUsingIncorrectBundleName($bundleName) public function testGetShortBundleNameUsingIncorrectBundleName($bundleName)
{ {
$this->setExpectedException(IncorrectBundleNameException::class); $this->expectException(IncorrectBundleNameException::class);
Bundle::getShortBundleName($bundleName); Bundle::getShortBundleName($bundleName);
} }

View File

@@ -224,7 +224,7 @@ class DateTest extends BaseTestCase
*/ */
public function testGetDayOfWeekIncorrectValues($year, $month, $day) public function testGetDayOfWeekIncorrectValues($year, $month, $day)
{ {
$this->setExpectedException(UnknownDatePartTypeException::class); $this->expectException(UnknownDatePartTypeException::class);
self::assertEmpty(Date::getDayOfWeek($year, $month, $day)); self::assertEmpty(Date::getDayOfWeek($year, $month, $day));
} }

View File

@@ -650,7 +650,7 @@ class MiscellaneousTest extends BaseTestCase
public function testGetInvertedColorWithIncorrectLength() public function testGetInvertedColorWithIncorrectLength()
{ {
$this->setExpectedException(IncorrectColorHexLengthException::class); $this->expectException(IncorrectColorHexLengthException::class);
Miscellaneous::getInvertedColor(null); Miscellaneous::getInvertedColor(null);
Miscellaneous::getInvertedColor(''); Miscellaneous::getInvertedColor('');
@@ -664,7 +664,7 @@ class MiscellaneousTest extends BaseTestCase
public function testGetInvertedColorWithInvalidValue() public function testGetInvertedColorWithInvalidValue()
{ {
$this->setExpectedException(InvalidColorHexValueException::class); $this->expectException(InvalidColorHexValueException::class);
Miscellaneous::getInvertedColor('0011zz'); Miscellaneous::getInvertedColor('0011zz');
Miscellaneous::getInvertedColor('001#zz'); Miscellaneous::getInvertedColor('001#zz');

View File

@@ -135,7 +135,7 @@ class ReflectionTest extends BaseTestCase
*/ */
public function testGetChildClassesInvalidClass($invalidClass) public function testGetChildClassesInvalidClass($invalidClass)
{ {
$this->setExpectedException(CannotResolveClassNameException::class); $this->expectException(CannotResolveClassNameException::class);
self::assertNull(Reflection::getChildClasses($invalidClass)); self::assertNull(Reflection::getChildClasses($invalidClass));
self::assertNull(Reflection::getChildClasses(123)); self::assertNull(Reflection::getChildClasses(123));
@@ -143,7 +143,7 @@ class ReflectionTest extends BaseTestCase
public function testGetChildClassesNotExistingClass() public function testGetChildClassesNotExistingClass()
{ {
$this->setExpectedException(CannotResolveClassNameException::class); $this->expectException(CannotResolveClassNameException::class);
self::assertEquals('', Reflection::getChildClasses('xyz')); self::assertEquals('', Reflection::getChildClasses('xyz'));
} }
@@ -174,13 +174,13 @@ class ReflectionTest extends BaseTestCase
public function testGetOneChildClassWithMissingChildClasses() public function testGetOneChildClassWithMissingChildClasses()
{ {
$this->setExpectedException(MissingChildClassesException::class); $this->expectException(MissingChildClassesException::class);
self::assertEquals('LoremIpsum', Reflection::getOneChildClass(C::class)); self::assertEquals('LoremIpsum', Reflection::getOneChildClass(C::class));
} }
public function testGetOneChildClassWithTooManyChildClasses() public function testGetOneChildClassWithTooManyChildClasses()
{ {
$this->setExpectedException(TooManyChildClassesException::class); $this->expectException(TooManyChildClassesException::class);
self::assertEquals(B::class, Reflection::getOneChildClass(A::class)); self::assertEquals(B::class, Reflection::getOneChildClass(A::class));
self::assertEquals(C::class, Reflection::getOneChildClass(A::class)); self::assertEquals(C::class, Reflection::getOneChildClass(A::class));
@@ -208,7 +208,7 @@ class ReflectionTest extends BaseTestCase
*/ */
public function testUsesTraitInvalidClass($class, $trait) public function testUsesTraitInvalidClass($class, $trait)
{ {
$this->setExpectedException(CannotResolveClassNameException::class); $this->expectException(CannotResolveClassNameException::class);
self::assertNull(Reflection::usesTrait($class, $trait)); self::assertNull(Reflection::usesTrait($class, $trait));
} }
@@ -218,7 +218,7 @@ class ReflectionTest extends BaseTestCase
*/ */
public function testUsesTraitInvalidTrait($trait) public function testUsesTraitInvalidTrait($trait)
{ {
$this->setExpectedException(CannotResolveClassNameException::class); $this->expectException(CannotResolveClassNameException::class);
self::assertNull(Reflection::usesTrait(DateTime::class, $trait)); self::assertNull(Reflection::usesTrait(DateTime::class, $trait));
} }
@@ -504,7 +504,7 @@ class ReflectionTest extends BaseTestCase
*/ */
public function testSetPropertyValueUsingNotExistingProperty($object, $property) public function testSetPropertyValueUsingNotExistingProperty($object, $property)
{ {
$this->setExpectedException(NotExistingPropertyException::class); $this->expectException(NotExistingPropertyException::class);
Reflection::setPropertyValue($object, $property, 'test test test'); Reflection::setPropertyValue($object, $property, 'test test test');
} }
@@ -542,7 +542,7 @@ class ReflectionTest extends BaseTestCase
*/ */
public function testSetPropertiesValuesUsingNotExistingProperties($object, array $propertiesValues) public function testSetPropertiesValuesUsingNotExistingProperties($object, array $propertiesValues)
{ {
$this->setExpectedException(NotExistingPropertyException::class); $this->expectException(NotExistingPropertyException::class);
Reflection::setPropertiesValues($object, $propertiesValues); Reflection::setPropertiesValues($object, $propertiesValues);
} }

View File

@@ -571,7 +571,7 @@ class RegexTest extends BaseTestCase
*/ */
public function testGetValidColorHexValueUsingEmptyValue($emptyValue) public function testGetValidColorHexValueUsingEmptyValue($emptyValue)
{ {
$this->setExpectedException(IncorrectColorHexLengthException::class); $this->expectException(IncorrectColorHexLengthException::class);
Regex::getValidColorHexValue($emptyValue); Regex::getValidColorHexValue($emptyValue);
} }
@@ -590,7 +590,7 @@ class RegexTest extends BaseTestCase
*/ */
public function testGetValidColorHexValueUsingIncorrectValue($incorrectColor) public function testGetValidColorHexValueUsingIncorrectValue($incorrectColor)
{ {
$this->setExpectedException(IncorrectColorHexLengthException::class); $this->expectException(IncorrectColorHexLengthException::class);
Regex::getValidColorHexValue($incorrectColor); Regex::getValidColorHexValue($incorrectColor);
} }
@@ -609,7 +609,7 @@ class RegexTest extends BaseTestCase
*/ */
public function testGetValidColorHexValueUsingInvalidValue($invalidColor) public function testGetValidColorHexValueUsingInvalidValue($invalidColor)
{ {
$this->setExpectedException(InvalidColorHexValueException::class); $this->expectException(InvalidColorHexValueException::class);
Regex::getValidColorHexValue($invalidColor); Regex::getValidColorHexValue($invalidColor);
} }

View File

@@ -131,7 +131,7 @@ class SizeTest extends BaseTestCase
*/ */
public function testFromArrayUsingInvalidSizeAsArray(array $size) public function testFromArrayUsingInvalidSizeAsArray(array $size)
{ {
$this->setExpectedException(InvalidSizeDimensionsException::class); $this->expectException(InvalidSizeDimensionsException::class);
Size::fromArray($size); Size::fromArray($size);
} }