mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 01:31:45 +01:00
Infection (Mutation Testing Framework) > fix bugs while running (generate proper code coverage, bugs while running tests randomly)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<phpunit
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.0/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true"
|
||||
executionOrder="random"
|
||||
@@ -27,6 +28,8 @@
|
||||
|
||||
<logging>
|
||||
<log type="coverage-html" target="build/reports/phpunit-coverage/html"/>
|
||||
<log type="coverage-xml" target="build/reports/infection/coverage-xml"/>
|
||||
<log type="junit" target="build/reports/infection/phpunit.junit.xml"/>
|
||||
<log type="coverage-clover" target="build/reports/coveralls/clover.xml"/>
|
||||
</logging>
|
||||
</phpunit>
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user