From c89b6da0db3fb07885170355edb634f6f6dd653e Mon Sep 17 00:00:00 2001 From: Meritoo Date: Tue, 2 Apr 2019 08:31:24 +0200 Subject: [PATCH] Tests > fix "Call to undefined method setExpectedException()" bug > make compatible with PHPUnit 8.0 (and PHP 7.2+) --- .../Exception/Base/UnknownTypeExceptionTest.php | 2 +- tests/Utilities/BundleTest.php | 8 ++++---- tests/Utilities/DateTest.php | 2 +- tests/Utilities/MiscellaneousTest.php | 4 ++-- tests/Utilities/ReflectionTest.php | 16 ++++++++-------- tests/Utilities/RegexTest.php | 6 +++--- tests/ValueObject/SizeTest.php | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/Exception/Base/UnknownTypeExceptionTest.php b/tests/Exception/Base/UnknownTypeExceptionTest.php index ce910d3..9dc6113 100644 --- a/tests/Exception/Base/UnknownTypeExceptionTest.php +++ b/tests/Exception/Base/UnknownTypeExceptionTest.php @@ -33,7 +33,7 @@ class UnknownTypeExceptionTest extends BaseTestCase public function testTheException() { - $this->setExpectedException(UnknownTestTypeException::class); + $this->expectException(UnknownTestTypeException::class); self::assertEmpty((new TestService())->getTranslatedType('test_3')); } } diff --git a/tests/Utilities/BundleTest.php b/tests/Utilities/BundleTest.php index 92dd655..03e9340 100644 --- a/tests/Utilities/BundleTest.php +++ b/tests/Utilities/BundleTest.php @@ -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' . ' there everything ok?'; - $message = sprintf($template, $bundleName); - $this->setExpectedException(IncorrectBundleNameException::class, $message); + $this->expectException(IncorrectBundleNameException::class); + $this->expectExceptionMessage(sprintf($template, $bundleName)); Bundle::getBundleViewPath($viewPath, $bundleName); } @@ -90,7 +90,7 @@ class BundleTest extends BaseTestCase */ public function testGetShortBundleNameUsingEmptyValue($emptyValue) { - $this->setExpectedException(IncorrectBundleNameException::class); + $this->expectException(IncorrectBundleNameException::class); Bundle::getShortBundleName($emptyValue); } @@ -102,7 +102,7 @@ class BundleTest extends BaseTestCase */ public function testGetShortBundleNameUsingIncorrectBundleName($bundleName) { - $this->setExpectedException(IncorrectBundleNameException::class); + $this->expectException(IncorrectBundleNameException::class); Bundle::getShortBundleName($bundleName); } diff --git a/tests/Utilities/DateTest.php b/tests/Utilities/DateTest.php index 5fca3fe..1af25bd 100644 --- a/tests/Utilities/DateTest.php +++ b/tests/Utilities/DateTest.php @@ -224,7 +224,7 @@ class DateTest extends BaseTestCase */ public function testGetDayOfWeekIncorrectValues($year, $month, $day) { - $this->setExpectedException(UnknownDatePartTypeException::class); + $this->expectException(UnknownDatePartTypeException::class); self::assertEmpty(Date::getDayOfWeek($year, $month, $day)); } diff --git a/tests/Utilities/MiscellaneousTest.php b/tests/Utilities/MiscellaneousTest.php index 86e7670..909bb11 100644 --- a/tests/Utilities/MiscellaneousTest.php +++ b/tests/Utilities/MiscellaneousTest.php @@ -650,7 +650,7 @@ class MiscellaneousTest extends BaseTestCase public function testGetInvertedColorWithIncorrectLength() { - $this->setExpectedException(IncorrectColorHexLengthException::class); + $this->expectException(IncorrectColorHexLengthException::class); Miscellaneous::getInvertedColor(null); Miscellaneous::getInvertedColor(''); @@ -664,7 +664,7 @@ class MiscellaneousTest extends BaseTestCase public function testGetInvertedColorWithInvalidValue() { - $this->setExpectedException(InvalidColorHexValueException::class); + $this->expectException(InvalidColorHexValueException::class); Miscellaneous::getInvertedColor('0011zz'); Miscellaneous::getInvertedColor('001#zz'); diff --git a/tests/Utilities/ReflectionTest.php b/tests/Utilities/ReflectionTest.php index 2507d7e..9c1baf3 100644 --- a/tests/Utilities/ReflectionTest.php +++ b/tests/Utilities/ReflectionTest.php @@ -135,7 +135,7 @@ class ReflectionTest extends BaseTestCase */ public function testGetChildClassesInvalidClass($invalidClass) { - $this->setExpectedException(CannotResolveClassNameException::class); + $this->expectException(CannotResolveClassNameException::class); self::assertNull(Reflection::getChildClasses($invalidClass)); self::assertNull(Reflection::getChildClasses(123)); @@ -143,7 +143,7 @@ class ReflectionTest extends BaseTestCase public function testGetChildClassesNotExistingClass() { - $this->setExpectedException(CannotResolveClassNameException::class); + $this->expectException(CannotResolveClassNameException::class); self::assertEquals('', Reflection::getChildClasses('xyz')); } @@ -174,13 +174,13 @@ class ReflectionTest extends BaseTestCase public function testGetOneChildClassWithMissingChildClasses() { - $this->setExpectedException(MissingChildClassesException::class); + $this->expectException(MissingChildClassesException::class); self::assertEquals('LoremIpsum', Reflection::getOneChildClass(C::class)); } public function testGetOneChildClassWithTooManyChildClasses() { - $this->setExpectedException(TooManyChildClassesException::class); + $this->expectException(TooManyChildClassesException::class); self::assertEquals(B::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) { - $this->setExpectedException(CannotResolveClassNameException::class); + $this->expectException(CannotResolveClassNameException::class); self::assertNull(Reflection::usesTrait($class, $trait)); } @@ -218,7 +218,7 @@ class ReflectionTest extends BaseTestCase */ public function testUsesTraitInvalidTrait($trait) { - $this->setExpectedException(CannotResolveClassNameException::class); + $this->expectException(CannotResolveClassNameException::class); self::assertNull(Reflection::usesTrait(DateTime::class, $trait)); } @@ -504,7 +504,7 @@ class ReflectionTest extends BaseTestCase */ public function testSetPropertyValueUsingNotExistingProperty($object, $property) { - $this->setExpectedException(NotExistingPropertyException::class); + $this->expectException(NotExistingPropertyException::class); Reflection::setPropertyValue($object, $property, 'test test test'); } @@ -542,7 +542,7 @@ class ReflectionTest extends BaseTestCase */ public function testSetPropertiesValuesUsingNotExistingProperties($object, array $propertiesValues) { - $this->setExpectedException(NotExistingPropertyException::class); + $this->expectException(NotExistingPropertyException::class); Reflection::setPropertiesValues($object, $propertiesValues); } diff --git a/tests/Utilities/RegexTest.php b/tests/Utilities/RegexTest.php index 469bbb0..ba9bcf2 100644 --- a/tests/Utilities/RegexTest.php +++ b/tests/Utilities/RegexTest.php @@ -571,7 +571,7 @@ class RegexTest extends BaseTestCase */ public function testGetValidColorHexValueUsingEmptyValue($emptyValue) { - $this->setExpectedException(IncorrectColorHexLengthException::class); + $this->expectException(IncorrectColorHexLengthException::class); Regex::getValidColorHexValue($emptyValue); } @@ -590,7 +590,7 @@ class RegexTest extends BaseTestCase */ public function testGetValidColorHexValueUsingIncorrectValue($incorrectColor) { - $this->setExpectedException(IncorrectColorHexLengthException::class); + $this->expectException(IncorrectColorHexLengthException::class); Regex::getValidColorHexValue($incorrectColor); } @@ -609,7 +609,7 @@ class RegexTest extends BaseTestCase */ public function testGetValidColorHexValueUsingInvalidValue($invalidColor) { - $this->setExpectedException(InvalidColorHexValueException::class); + $this->expectException(InvalidColorHexValueException::class); Regex::getValidColorHexValue($invalidColor); } diff --git a/tests/ValueObject/SizeTest.php b/tests/ValueObject/SizeTest.php index b3dbbbd..ed52f00 100644 --- a/tests/ValueObject/SizeTest.php +++ b/tests/ValueObject/SizeTest.php @@ -131,7 +131,7 @@ class SizeTest extends BaseTestCase */ public function testFromArrayUsingInvalidSizeAsArray(array $size) { - $this->setExpectedException(InvalidSizeDimensionsException::class); + $this->expectException(InvalidSizeDimensionsException::class); Size::fromArray($size); }