Skip to content

Commit

Permalink
Merge pull request #18 from meritoo/bugfix/deprecations
Browse files Browse the repository at this point in the history
Fix deprecations when running PHPUnit tests
  • Loading branch information
meritoo authored Nov 16, 2024
2 parents b931805 + 01c7709 commit 8062c06
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 60 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

Common and useful classes, methods, exceptions etc.

# 1.3.1

1. Arguments passed to the `Meritoo\Common\Utilities\Miscellaneous::concatenatePaths()` should be `string`s. The method
does not accept `array` of strings anymore.

Before:

```php
$result = Miscellaneous::concatenatePaths([
'first/directory',
'second/one',
'and/the/third',
]);
```

After:

```php
$result = Miscellaneous::concatenatePaths(
'first/directory',
'second/one',
'and/the/third',
);
```

# 1.3.0

1. Support integers by the `BaseType::isCorrectType()` method
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.0
1.3.1
6 changes: 2 additions & 4 deletions src/Traits/Test/Base/BaseTestCaseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,12 @@ protected function getFilePathForTesting(string $fileName, string $directoryPath
{
$rootPath = Miscellaneous::getProjectRootPath();

$paths = [
return Miscellaneous::concatenatePaths(
$rootPath,
self::$testsDataDirPath,
$directoryPath,
$fileName,
];

return Miscellaneous::concatenatePaths($paths);
);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/Utilities/Arrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -1572,8 +1572,9 @@ public static function trimRecursive(array $array): array
/**
* Converts given array's rows to csv string
*
* @param array $array Data to be converted. It have to be an array that represents database table.
* @param array $array Data to be converted. It has to be an array that represents database table.
* @param string $separator (optional) Separator used between values. Default: ",".
*
* @return null|string
*/
public static function values2csv(array $array, string $separator = ','): ?string
Expand All @@ -1594,6 +1595,10 @@ public static function values2csv(array $array, string $separator = ','): ?strin

if (is_array($row) && !empty($row)) {
foreach ($row as $key => $value) {
if (empty($value)) {
continue;
}

$row[$key] = html_entity_decode($value);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ public static function getDayOfWeekName(int $year, int $month, int $day): string
$second = 0;

$time = mktime($hour, $minute, $second, $month, $day, $year);
$name = strftime('%A', $time);
$name = \date('l', $time);

$encoding = mb_detect_encoding($name);

Expand Down
25 changes: 3 additions & 22 deletions src/Utilities/Miscellaneous.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,33 +153,14 @@ public static function checkboxValue2Integer(string $checkboxValue): int
}

/**
* Returns concatenated given paths
* Returns given paths concatenated into one string
*
* The paths may be passed as:
* - an array of paths / strings
* - strings passed as following arguments
* @param string ...$paths Paths to concatenate
*
* Examples:
* - concatenatePaths(['path/first', 'path/second', 'path/third']);
* - concatenatePaths('path/first', 'path/second', 'path/third');
*
* @param array|string $paths Paths co concatenate. As described above: an array of paths / strings or strings
* passed as following arguments.
* @return string
*/
public static function concatenatePaths($paths): string
public static function concatenatePaths(string ...$paths): string
{
// If paths are not provided as array, get the paths from methods' arguments
if (!is_array($paths)) {
$paths = func_get_args();
}

// No paths provided?
// Nothing to do
if (empty($paths)) {
return '';
}

$concatenated = '';
$firstWindowsBased = false;
$separator = DIRECTORY_SEPARATOR;
Expand Down
9 changes: 1 addition & 8 deletions tests/Utilities/ArraysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3794,14 +3794,7 @@ public function testTrimRecursive()
self::assertEquals($result, Arrays::trimRecursive($array));
}

/**
* @param string $description Description of test
* @param string $expected Expected array converted to csv string
* @param array $array Data to be converted. It have to be an array that represents database table.
* @param string $separator (optional) Separator used between values. Default: ",".
*
* @dataProvider provideArrayValues2csv
*/
/** @dataProvider provideArrayValues2csv */
public function testValues2csv(string $description, ?string $expected, array $array, string $separator = ','): void
{
// Required to avoid failure:
Expand Down
45 changes: 22 additions & 23 deletions tests/Utilities/MiscellaneousTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1035,54 +1035,53 @@ public function testCheckboxValue2Integer()
self::assertEquals(0, Miscellaneous::checkboxValue2Integer(' off'));
}

public function testConcatenatePathsInNixOs()
public function testConcatenatePathsInNixOs(): void
{
// For *nix operating system
$paths1 = [
$result = Miscellaneous::concatenatePaths(
'first/directory',
'second/one',
'and/the/third',
];
);

self::assertEquals('/'.implode('/', $paths1), Miscellaneous::concatenatePaths($paths1));
self::assertEquals('/'.implode('/', $paths1), Miscellaneous::concatenatePaths($paths1[0], $paths1[1], $paths1[2]));
self::assertEquals('/first/directory/second/one/and/the/third', $result);
}

public function testConcatenatePathsInWindowsOs()
public function testConcatenatePathsInWindowsOs(): void
{
// For Windows operating system
$paths2 = [
$result = Miscellaneous::concatenatePaths(
'C:\first\directory',
'second\one',
'and\the\third',
];
);

self::assertEquals(implode('\\', $paths2), Miscellaneous::concatenatePaths($paths2));
self::assertEquals('C:\first\directory\second\one\and\the\third', $result);
}

/**
* @param mixed $emptyPaths Empty paths co concatenate
* @dataProvider provideEmptyValue
*/
public function testConcatenatePathsWithEmptyPaths($emptyPaths)
public function testConcatenatePathsWithEmptyPaths(): void
{
self::assertEquals('', Miscellaneous::concatenatePaths($emptyPaths));
self::assertEquals('', Miscellaneous::concatenatePaths());

self::assertEquals('', Miscellaneous::concatenatePaths(''));
self::assertEquals('', Miscellaneous::concatenatePaths('', ''));
self::assertEquals('', Miscellaneous::concatenatePaths('', '', ''));

self::assertEquals('', Miscellaneous::concatenatePaths(' '));
self::assertEquals('', Miscellaneous::concatenatePaths(' ', ' '));
self::assertEquals('', Miscellaneous::concatenatePaths(' ', ' ', ' '));
}

public function testConcatenatePathsWithOneEmptyPath()
public function testConcatenatePathsWithOneEmptyPath(): void
{
$paths = [
$result = Miscellaneous::concatenatePaths(
'first/directory',
'second/one',
'',
'and/the/third',
];

$concatenated = Miscellaneous::concatenatePaths($paths);
unset($paths[2]);
$imploded = implode('/', $paths);
);

self::assertEquals('/'.$imploded, $concatenated);
self::assertEquals('/first/directory/second/one/and/the/third', $result);
}

public function testConstructor()
Expand Down

0 comments on commit 8062c06

Please sign in to comment.