diff --git a/CHANGELOG.md b/CHANGELOG.md index e2eef17..836d922 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ Common and useful classes, methods, exceptions etc. 6. Implement [PHPStan](https://github.com/phpstan/phpstan) 7. PHPUnit > execute tests in random order 8. Implement [Psalm](https://github.com/vimeo/psalm) +9. Infection (Mutation Testing Framework) > fix bugs while running (generate proper code coverage, bugs while running +tests randomly) # 1.0.1 diff --git a/phing/properties.dist b/phing/properties.dist index b87a660..4627505 100644 --- a/phing/properties.dist +++ b/phing/properties.dist @@ -84,5 +84,5 @@ tests.database = ${dir.data.temporary}/database.sqlite # - PHPUnit (unit tests) # - Infection (mutation tests) # -tests.phpunit.command = ./vendor/bin/phpunit --verbose --no-coverage -tests.mutation.command = ./vendor/bin/infection --threads=5 +tests.phpunit.command = ./vendor/bin/phpunit --verbose +tests.mutation.command = ./vendor/bin/infection --ansi --threads=5 --coverage=build/reports/infection diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9981913..2478270 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -4,6 +4,7 @@ + + diff --git a/tests/Utilities/ArraysTest.php b/tests/Utilities/ArraysTest.php index 688edce..3fd87bf 100644 --- a/tests/Utilities/ArraysTest.php +++ b/tests/Utilities/ArraysTest.php @@ -10,6 +10,7 @@ namespace Meritoo\Test\Common\Utilities; use Meritoo\Common\Test\Base\BaseTestCase; use Meritoo\Common\Utilities\Arrays; +use Meritoo\Common\Utilities\Locale; use Meritoo\Test\Common\Utilities\Arrays\SimpleToString; /** @@ -42,6 +43,13 @@ class ArraysTest extends BaseTestCase */ public function testValues2string($description, $expected, array $array, $arrayColumnKey = '', $separator = ',') { + // Required to avoid failure: + // + // Failed asserting that two strings are identical + // 1,2,3,test 1,test 2,test 3,,test 4,,bbb,3.45 - expected + // 1,2,3,test 1,test 2,test 3,,test 4,,bbb,3,45 - actual + Locale::setLocale(LC_ALL, 'en', 'US'); + self::assertSame($expected, Arrays::values2string($array, $arrayColumnKey, $separator), $description); } @@ -64,6 +72,13 @@ class ArraysTest extends BaseTestCase $valuesKeysSeparator = '=', $valuesWrapper = '' ) { + // Required to avoid failure: + // + // Failed asserting that two strings are identical + // test_1=test test,test_2=2,test_3=3.45 - expected + // test_1=test test,test_2=2,test_3=3,45 - actual + Locale::setLocale(LC_ALL, 'en', 'US'); + self::assertSame( $expected, Arrays::valuesKeys2string($array, $separator, $valuesKeysSeparator, $valuesWrapper), @@ -111,6 +126,13 @@ class ArraysTest extends BaseTestCase */ public function testValues2csv($description, $expected, array $array, $separator = ',') { + // Required to avoid failure: + // + // Failed asserting that two strings are identical + // 1,2,3.45 - expected + // 1,2,3,45 - actual + Locale::setLocale(LC_ALL, 'en', 'US'); + self::assertSame($expected, Arrays::values2csv($array, $separator), $description); self::assertSame('', Arrays::values2csv($this->simpleArray), 'Simple array'); diff --git a/tests/Utilities/DateTest.php b/tests/Utilities/DateTest.php index 1af25bd..97b9f61 100644 --- a/tests/Utilities/DateTest.php +++ b/tests/Utilities/DateTest.php @@ -15,6 +15,7 @@ use Meritoo\Common\Exception\Type\UnknownDatePartTypeException; use Meritoo\Common\Test\Base\BaseTestCase; use Meritoo\Common\Type\DatePeriod; use Meritoo\Common\Utilities\Date; +use Meritoo\Common\Utilities\Locale; /** * Test case of the Date methods (only static functions) @@ -200,6 +201,12 @@ class DateTest extends BaseTestCase public function testGetCurrentDayOfWeekName() { + // Required to avoid failure: + // + // Failed asserting that 'giovedì' matches PCRE pattern + // "/^Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday$/" + Locale::setLocale(LC_ALL, 'en', 'US'); + $days = [ 'Monday', 'Tuesday', diff --git a/tests/Utilities/MiscellaneousTest.php b/tests/Utilities/MiscellaneousTest.php index 909bb11..20bcb8f 100644 --- a/tests/Utilities/MiscellaneousTest.php +++ b/tests/Utilities/MiscellaneousTest.php @@ -229,7 +229,7 @@ class MiscellaneousTest extends BaseTestCase * of strings or an array of patterns. * @param string|array $replacement The string or an array of strings to replace. It may be: string or an array * of strings. - * @param mixed $result Result of replacing + * @param mixed $result Result of replacing * * @dataProvider provideEmptyValuesToReplace */ @@ -245,7 +245,7 @@ class MiscellaneousTest extends BaseTestCase * strings or an array of patterns. * @param string $replacement The string or an array of strings to replace. It may be: string or an array of * strings. - * @param mixed $result Result of replacing + * @param mixed $result Result of replacing * * @dataProvider provideStringsToReplace */ @@ -261,7 +261,7 @@ class MiscellaneousTest extends BaseTestCase * strings or an array of patterns. * @param string $replacement The string or an array of strings to replace. It may be: string or an array of * strings. - * @param mixed $result Result of replacing + * @param mixed $result Result of replacing * * @dataProvider provideRegexToReplace */ @@ -277,7 +277,7 @@ class MiscellaneousTest extends BaseTestCase * strings or an array of patterns. * @param string $replacement The string or an array of strings to replace. It may be: string or an array of * strings. - * @param mixed $result Result of replacing + * @param mixed $result Result of replacing * * @dataProvider provideDataToReplaceWithQuoteStrings */ @@ -376,8 +376,17 @@ class MiscellaneousTest extends BaseTestCase $directory1Path = sys_get_temp_dir() . '/lorem/ipsum'; $directory2Path = sys_get_temp_dir() . '/lorem/dolor/sit'; - mkdir($directory1Path, 0777, true); - mkdir($directory2Path, 0777, true); + // Directory does not exist? Let's create it + // Required to avoid test failure + if (!file_exists($directory1Path)) { + mkdir($directory1Path, 0777, true); + } + + // Directory does not exist? Let's create it + // Required to avoid test failure + if (!file_exists($directory2Path)) { + mkdir($directory2Path, 0777, true); + } self::assertTrue(Miscellaneous::removeDirectory(sys_get_temp_dir() . '/lorem')); } diff --git a/tests/Utilities/ReflectionTest.php b/tests/Utilities/ReflectionTest.php index 09f9883..4c742f6 100644 --- a/tests/Utilities/ReflectionTest.php +++ b/tests/Utilities/ReflectionTest.php @@ -176,14 +176,22 @@ class ReflectionTest extends BaseTestCase public function testGetOneChildClassWithTooManyChildClasses() { - $this->expectException(TooManyChildClassesException::class); + // Required to get all classes by get_declared_classes() function and avoid failure: + // + // Failed asserting that exception of type "Meritoo\Common\Exception\Reflection\TooManyChildClassesException" + // is thrown + new C(); - self::assertEquals(B::class, Reflection::getOneChildClass(A::class)); - self::assertEquals(C::class, Reflection::getOneChildClass(A::class)); + $this->expectException(TooManyChildClassesException::class); + Reflection::getOneChildClass(A::class); } public function testGetOneChildClass() { + // Required to get all classes by get_declared_classes() function and avoid throw of + // Meritoo\Common\Exception\Reflection\MissingChildClassesException exception + new C(); + self::assertEquals(C::class, Reflection::getOneChildClass(B::class)); }