mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ffa3fbffe7 | ||
|
|
48aa27fb86 | ||
|
|
86cc5ff79b | ||
|
|
633696ebc0 | ||
|
|
a0d28b326e | ||
|
|
318a635ffd | ||
|
|
6c70fdd673 | ||
|
|
204e8793ac | ||
|
|
3dd37ae202 | ||
|
|
ef017c9d6a | ||
|
|
5030dc2062 | ||
|
|
2c76158093 | ||
|
|
0b560fdf18 | ||
|
|
284d403061 | ||
|
|
7dbb3f9b2e | ||
|
|
fba821b798 | ||
|
|
3985c70076 | ||
|
|
921d4e6106 | ||
|
|
7aa2239dbd | ||
|
|
e1fefcdeae | ||
|
|
94a464cb4d | ||
|
|
463ee751b2 | ||
|
|
89af7145f6 | ||
|
|
09c8569938 |
@@ -1 +1,8 @@
|
||||
preset: symfony
|
||||
|
||||
disabled:
|
||||
- phpdoc_annotation_without_dot
|
||||
- cast_spaces
|
||||
- concat_without_spaces
|
||||
- blank_line_before_return
|
||||
- trim_array_spaces
|
||||
|
||||
@@ -2,5 +2,11 @@ language: php
|
||||
|
||||
php:
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
- nightly
|
||||
|
||||
install:
|
||||
- composer install
|
||||
|
||||
script:
|
||||
- php ./vendor/bin/phpunit
|
||||
|
||||
14
README.md
14
README.md
@@ -1,13 +1,15 @@
|
||||
# Meritoo Common Library [](https://travis-ci.org/meritoo/common-library) [](https://packagist.org/packages/meritoo/common-library) [](https://styleci.io/repos/101790028) [](https://github.com/meritoo/common-library) [](https://github.com/meritoo/common-library) [](https://coveralls.io/github/meritoo/common-library?branch=master)
|
||||
Useful classes, methods, extensions etc.
|
||||
# Meritoo Common Library
|
||||
Common and useful classes, methods, exceptions etc.
|
||||
|
||||
[](https://travis-ci.org/meritoo/common-library) [](https://packagist.org/packages/meritoo/common-library) [](https://styleci.io/repos/101790028) [](https://github.com/meritoo/common-library) [](https://github.com/meritoo/common-library) [](https://coveralls.io/github/meritoo/common-library?branch=master)
|
||||
|
||||
## Installation
|
||||
|
||||
Run [Composer](https://getcomposer.org) to install new package:
|
||||
Run [Composer](https://getcomposer.org) to install this package in your project:
|
||||
|
||||
```bash
|
||||
$ composer require meritoo/common-library
|
||||
```
|
||||
```bash
|
||||
$ composer require meritoo/common-library
|
||||
```
|
||||
|
||||
> How to install Composer: https://getcomposer.org/download
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "meritoo/common-library",
|
||||
"description": "Useful classes, methods, extensions etc.",
|
||||
"license": "MIT",
|
||||
"version": "0.0.6",
|
||||
"version": "0.0.12",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Meritoo.pl",
|
||||
@@ -17,13 +17,13 @@
|
||||
"symfony/http-foundation": "^3.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8 || ^5.0",
|
||||
"squizlabs/php_codesniffer": "^2.8",
|
||||
"phpunit/phpunit": "^5.7",
|
||||
"squizlabs/php_codesniffer": "^2.9",
|
||||
"phpmd/phpmd": "^2.6",
|
||||
"sebastian/phpcpd": "^3.0",
|
||||
"pdepend/pdepend": "^2.5",
|
||||
"phploc/phploc": "^3.0",
|
||||
"friendsofphp/php-cs-fixer": "^2.1"
|
||||
"phploc/phploc": "^4.0",
|
||||
"friendsofphp/php-cs-fixer": "^2.6"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
||||
550
composer.lock
generated
550
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -109,7 +109,7 @@ class Collection implements Countable, ArrayAccess, IteratorAggregate
|
||||
*/
|
||||
public function add($element, $index = null)
|
||||
{
|
||||
if ($index === null) {
|
||||
if (null === $index) {
|
||||
$this->elements[] = $element;
|
||||
} else {
|
||||
$this->elements[$index] = $element;
|
||||
@@ -216,7 +216,7 @@ class Collection implements Countable, ArrayAccess, IteratorAggregate
|
||||
{
|
||||
$index = Arrays::getIndexOf($this->elements, $element);
|
||||
|
||||
return $index !== null && $index !== false;
|
||||
return null !== $index && false !== $index;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
31
src/Meritoo/Common/Exception/File/EmptyFileException.php
Normal file
31
src/Meritoo/Common/Exception/File/EmptyFileException.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Common\Exception\File;
|
||||
|
||||
/**
|
||||
* An exception used while file with given path is empty (has no content)
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class EmptyFileException extends \Exception
|
||||
{
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $emptyFilePath Path of the empty file
|
||||
*/
|
||||
public function __construct($emptyFilePath)
|
||||
{
|
||||
$template = 'File with path \'%s\' is empty (has no content). Did you provide path of proper file?';
|
||||
$message = sprintf($template, $emptyFilePath);
|
||||
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
26
src/Meritoo/Common/Exception/File/EmptyFilePathException.php
Normal file
26
src/Meritoo/Common/Exception/File/EmptyFilePathException.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Common\Exception\File;
|
||||
|
||||
/**
|
||||
* An exception used while path of given file is empty
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class EmptyFilePathException extends \Exception
|
||||
{
|
||||
/**
|
||||
* Class constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('Path of the file is empty. Did you provide path of proper file?');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Common\Exception\File;
|
||||
|
||||
/**
|
||||
* An exception used while file with given path does not exist
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class NotExistingFileException extends \Exception
|
||||
{
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $notExistingFilePath Path of not existing (or not readable) file
|
||||
*/
|
||||
public function __construct($notExistingFilePath)
|
||||
{
|
||||
$template = 'File with path \'%s\' does not exist (or is not readable). Did you provide path of proper file?';
|
||||
$message = sprintf($template, $notExistingFilePath);
|
||||
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Common\Exception\Method;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* An exception used while method cannot be called, because is disabled
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class DisabledMethodException extends Exception
|
||||
{
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $disabledMethod Name of the disabled method
|
||||
* @param string $alternativeMethod (optional) Name of the alternative method
|
||||
*/
|
||||
public function __construct($disabledMethod, $alternativeMethod = '')
|
||||
{
|
||||
$template = 'Method %s() cannot be called, because is disabled.';
|
||||
|
||||
if (!empty($alternativeMethod)) {
|
||||
$template .= ' Use %s() instead.';
|
||||
}
|
||||
|
||||
$message = sprintf($template, $disabledMethod, $alternativeMethod);
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ class CannotResolveClassNameException extends Exception
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array|object|string $source Source of the class's / trait's name. It cane be an array of objects,
|
||||
* @param array|object|string $source Source of the class's / trait's name. It can be an array of objects,
|
||||
* namespaces, object or namespace.
|
||||
* @param bool $forClass (optional) If is set to true, message of this exception for class is
|
||||
* prepared. Otherwise - for trait.
|
||||
|
||||
@@ -12,7 +12,8 @@ use DateTime;
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use Meritoo\Common\Utilities\Miscellaneous;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
|
||||
@@ -22,7 +23,7 @@ use ReflectionMethod;
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
abstract class BaseTestCase extends PHPUnit_Framework_TestCase
|
||||
abstract class BaseTestCase extends TestCase
|
||||
{
|
||||
/**
|
||||
* Provides an empty value
|
||||
@@ -105,11 +106,16 @@ abstract class BaseTestCase extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function getFilePathToTests($fileName, $directoryPath = '')
|
||||
{
|
||||
if (!empty($directoryPath)) {
|
||||
$directoryPath = '/' . $directoryPath;
|
||||
}
|
||||
$rootPath = Miscellaneous::getProjectRootPath();
|
||||
|
||||
return sprintf('%s/../../../../../data/tests/%s%s', __DIR__, $fileName, $directoryPath);
|
||||
$paths = [
|
||||
$rootPath,
|
||||
'data/tests',
|
||||
$directoryPath,
|
||||
$fileName,
|
||||
];
|
||||
|
||||
return Miscellaneous::concatenatePaths($paths);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,7 +135,7 @@ abstract class BaseTestCase extends PHPUnit_Framework_TestCase
|
||||
* - string - name of the method
|
||||
* - instance of ReflectionMethod - just the method (provided by ReflectionClass::getMethod() method)
|
||||
*/
|
||||
protected function verifyMethodVisibilityAndArguments(
|
||||
protected static function assertMethodVisibilityAndArguments(
|
||||
$classNamespace,
|
||||
$method,
|
||||
$visibilityType,
|
||||
@@ -174,7 +180,7 @@ abstract class BaseTestCase extends PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Verifies visibility and arguments of class constructor
|
||||
*
|
||||
* @param string $classNamespace Namespace of class that contains method to verify
|
||||
* @param string $classNamespace Namespace of class that contains constructor to verify
|
||||
* @param string $visibilityType Expected visibility of verified method. One of OopVisibilityType class
|
||||
* constants.
|
||||
* @param int $argumentsCount (optional) Expected count/amount of arguments of the verified method
|
||||
@@ -182,7 +188,7 @@ abstract class BaseTestCase extends PHPUnit_Framework_TestCase
|
||||
* method
|
||||
* @throws UnknownOopVisibilityTypeException
|
||||
*/
|
||||
protected function verifyConstructorVisibilityAndArguments(
|
||||
protected static function assertConstructorVisibilityAndArguments(
|
||||
$classNamespace,
|
||||
$visibilityType,
|
||||
$argumentsCount = 0,
|
||||
@@ -194,6 +200,22 @@ abstract class BaseTestCase extends PHPUnit_Framework_TestCase
|
||||
$reflection = new ReflectionClass($classNamespace);
|
||||
$method = $reflection->getConstructor();
|
||||
|
||||
return $this->verifyMethodVisibilityAndArguments($classNamespace, $method, $visibilityType, $argumentsCount, $requiredArgumentsCount);
|
||||
return static::assertMethodVisibilityAndArguments($classNamespace, $method, $visibilityType, $argumentsCount, $requiredArgumentsCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that class with given namespace has no constructor
|
||||
*
|
||||
* @param string $classNamespace Namespace of class that contains constructor to verify
|
||||
*/
|
||||
protected static function assertHasNoConstructor($classNamespace)
|
||||
{
|
||||
/*
|
||||
* Let's grab the constructor
|
||||
*/
|
||||
$reflection = new ReflectionClass($classNamespace);
|
||||
$constructor = $reflection->getConstructor();
|
||||
|
||||
static::assertNull($constructor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ abstract class BaseType
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
if ($this->all === null) {
|
||||
if (null === $this->all) {
|
||||
$this->all = Reflection::getConstants($this);
|
||||
}
|
||||
|
||||
|
||||
@@ -415,7 +415,7 @@ class Arrays
|
||||
* var autoGeneratedVariable = new Array(...);autoGeneratedVariable[0] = new Array(...);
|
||||
* autoGeneratedVariable[1] = new Array(...);
|
||||
*/
|
||||
if ($counter === 1) {
|
||||
if (1 === $counter) {
|
||||
$effect .= "\n";
|
||||
}
|
||||
|
||||
@@ -758,7 +758,7 @@ class Arrays
|
||||
foreach ($exploded as $item) {
|
||||
$exploded2 = explode($valuesKeysSeparator, $item);
|
||||
|
||||
if (count($exploded2) == 2) {
|
||||
if (2 == count($exploded2)) {
|
||||
$key = trim($exploded2[0]);
|
||||
$value = trim($exploded2[1]);
|
||||
|
||||
@@ -1124,7 +1124,7 @@ class Arrays
|
||||
if (!empty($array)) {
|
||||
$childPosition = 1;
|
||||
|
||||
if ($startPosition !== null) {
|
||||
if (null !== $startPosition) {
|
||||
$array[$keyName] = $startPosition;
|
||||
}
|
||||
|
||||
@@ -1316,7 +1316,7 @@ class Arrays
|
||||
*
|
||||
* If one of the above is true, not all elements of given array are empty
|
||||
*/
|
||||
if ((!is_array($element) && $strictNull && $element !== null) || !empty($element)) {
|
||||
if ((!is_array($element) && $strictNull && null !== $element) || !empty($element)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1353,7 +1353,7 @@ class Arrays
|
||||
* Values should be compared only and both arrays are one-dimensional?
|
||||
* Let's find difference by using simple function
|
||||
*/
|
||||
if ($valuesOnly && self::getDimensionsCount($array1) == 1 && self::getDimensionsCount($array2) == 1) {
|
||||
if ($valuesOnly && 1 == self::getDimensionsCount($array1) && 1 == self::getDimensionsCount($array2)) {
|
||||
return array_diff($array1, $array2);
|
||||
}
|
||||
|
||||
@@ -1381,7 +1381,7 @@ class Arrays
|
||||
}
|
||||
}
|
||||
|
||||
if ($difference !== null) {
|
||||
if (null !== $difference) {
|
||||
$effect[] = $difference;
|
||||
}
|
||||
} else {
|
||||
@@ -1472,7 +1472,7 @@ class Arrays
|
||||
* Start index not provided?
|
||||
* Let's look for the first index / key of given array
|
||||
*/
|
||||
if ($startIndex === null) {
|
||||
if (null === $startIndex) {
|
||||
$startIndex = self::getFirstKey($array);
|
||||
}
|
||||
|
||||
@@ -1617,7 +1617,7 @@ class Arrays
|
||||
* Index of element or of element's key is unknown?
|
||||
* Probably the element does not exist in given array, so... nothing to do
|
||||
*/
|
||||
if ($elementKey === null || $indexOfKey === null) {
|
||||
if (null === $elementKey || null === $indexOfKey) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class Composer
|
||||
* Unknown data from the composer.json file or there is no node with given name?
|
||||
* Nothing to do
|
||||
*/
|
||||
if ($data === null || !isset($data->{$nodeName})) {
|
||||
if (null === $data || !isset($data->{$nodeName})) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -129,10 +129,10 @@ class Date
|
||||
$dateStart = new DateTime();
|
||||
$dateEnd = new DateTime();
|
||||
|
||||
if ($period == DatePeriod::LAST_YEAR || $period == DatePeriod::NEXT_YEAR) {
|
||||
if (DatePeriod::LAST_YEAR == $period || DatePeriod::NEXT_YEAR == $period) {
|
||||
$yearDifference = 1;
|
||||
|
||||
if ($period == DatePeriod::LAST_YEAR) {
|
||||
if (DatePeriod::LAST_YEAR == $period) {
|
||||
$yearDifference *= -1;
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ class Date
|
||||
break;
|
||||
}
|
||||
|
||||
if ($dateStart !== null && $dateEnd !== null) {
|
||||
if (null !== $dateStart && null !== $dateEnd) {
|
||||
$dateStart->setTime(0, 0, 0);
|
||||
$dateEnd->setTime(23, 59, 59);
|
||||
|
||||
@@ -311,7 +311,7 @@ class Date
|
||||
|
||||
$encoding = mb_detect_encoding($name);
|
||||
|
||||
if ($encoding === false) {
|
||||
if (false === $encoding) {
|
||||
$name = mb_convert_encoding($name, 'UTF-8', 'ISO-8859-2');
|
||||
}
|
||||
|
||||
@@ -378,46 +378,46 @@ class Date
|
||||
self::DATE_DIFFERENCE_UNIT_MINUTES,
|
||||
];
|
||||
|
||||
if ($differenceUnit === null || $differenceUnit == self::DATE_DIFFERENCE_UNIT_YEARS) {
|
||||
if (null === $differenceUnit || self::DATE_DIFFERENCE_UNIT_YEARS == $differenceUnit) {
|
||||
$diff = $dateEnd->diff($dateStart);
|
||||
|
||||
/*
|
||||
* Difference between dates in years should be returned only?
|
||||
*/
|
||||
if ($differenceUnit == self::DATE_DIFFERENCE_UNIT_YEARS) {
|
||||
if (self::DATE_DIFFERENCE_UNIT_YEARS == $differenceUnit) {
|
||||
return $diff->y;
|
||||
}
|
||||
|
||||
$difference[self::DATE_DIFFERENCE_UNIT_YEARS] = $diff->y;
|
||||
}
|
||||
|
||||
if ($differenceUnit === null || $differenceUnit == self::DATE_DIFFERENCE_UNIT_MONTHS) {
|
||||
if (null === $differenceUnit || self::DATE_DIFFERENCE_UNIT_MONTHS == $differenceUnit) {
|
||||
$diff = $dateEnd->diff($dateStart);
|
||||
|
||||
/*
|
||||
* Difference between dates in months should be returned only?
|
||||
*/
|
||||
if ($differenceUnit == self::DATE_DIFFERENCE_UNIT_MONTHS) {
|
||||
if (self::DATE_DIFFERENCE_UNIT_MONTHS == $differenceUnit) {
|
||||
return $diff->m;
|
||||
}
|
||||
|
||||
$difference[self::DATE_DIFFERENCE_UNIT_MONTHS] = $diff->m;
|
||||
}
|
||||
|
||||
if ($differenceUnit === null || in_array($differenceUnit, $relatedUnits)) {
|
||||
if (null === $differenceUnit || in_array($differenceUnit, $relatedUnits)) {
|
||||
$days = (int)floor($dateDiff / $daySeconds);
|
||||
|
||||
/*
|
||||
* Difference between dates in days should be returned only?
|
||||
*/
|
||||
if ($differenceUnit == self::DATE_DIFFERENCE_UNIT_DAYS) {
|
||||
if (self::DATE_DIFFERENCE_UNIT_DAYS == $differenceUnit) {
|
||||
return $days;
|
||||
}
|
||||
|
||||
/*
|
||||
* All units should be returned?
|
||||
*/
|
||||
if ($differenceUnit === null) {
|
||||
if (null === $differenceUnit) {
|
||||
$difference[self::DATE_DIFFERENCE_UNIT_DAYS] = $days;
|
||||
}
|
||||
|
||||
@@ -427,20 +427,20 @@ class Date
|
||||
$daysInSeconds = $days * $daySeconds;
|
||||
}
|
||||
|
||||
if ($differenceUnit === null || in_array($differenceUnit, $relatedUnits)) {
|
||||
if (null === $differenceUnit || in_array($differenceUnit, $relatedUnits)) {
|
||||
$hours = (int)floor(($dateDiff - $daysInSeconds) / $hourSeconds);
|
||||
|
||||
/*
|
||||
* Difference between dates in hours should be returned only?
|
||||
*/
|
||||
if ($differenceUnit == self::DATE_DIFFERENCE_UNIT_HOURS) {
|
||||
if (self::DATE_DIFFERENCE_UNIT_HOURS == $differenceUnit) {
|
||||
return $hours;
|
||||
}
|
||||
|
||||
/*
|
||||
* All units should be returned?
|
||||
*/
|
||||
if ($differenceUnit === null) {
|
||||
if (null === $differenceUnit) {
|
||||
$difference[self::DATE_DIFFERENCE_UNIT_HOURS] = $hours;
|
||||
}
|
||||
|
||||
@@ -450,13 +450,13 @@ class Date
|
||||
$hoursInSeconds = $hours * $hourSeconds;
|
||||
}
|
||||
|
||||
if ($differenceUnit === null || $differenceUnit == self::DATE_DIFFERENCE_UNIT_MINUTES) {
|
||||
if (null === $differenceUnit || self::DATE_DIFFERENCE_UNIT_MINUTES == $differenceUnit) {
|
||||
$minutes = (int)floor(($dateDiff - $daysInSeconds - $hoursInSeconds) / 60);
|
||||
|
||||
/*
|
||||
* Difference between dates in minutes should be returned only?
|
||||
*/
|
||||
if ($differenceUnit == self::DATE_DIFFERENCE_UNIT_MINUTES) {
|
||||
if (self::DATE_DIFFERENCE_UNIT_MINUTES == $differenceUnit) {
|
||||
return $minutes;
|
||||
}
|
||||
|
||||
@@ -524,7 +524,7 @@ class Date
|
||||
*/
|
||||
public static function getRandomDate(DateTime $startDate = null, $start = 1, $end = 100, $intervalTemplate = 'P%sD')
|
||||
{
|
||||
if ($startDate === null) {
|
||||
if (null === $startDate) {
|
||||
$startDate = new DateTime();
|
||||
}
|
||||
|
||||
@@ -590,7 +590,7 @@ class Date
|
||||
*/
|
||||
$dateFromFormat = DateTime::createFromFormat($dateFormat, $value);
|
||||
|
||||
if ($dateFromFormat === false) {
|
||||
if (false === $dateFromFormat) {
|
||||
/*
|
||||
* Nothing to do more, because:
|
||||
* a) instance of the DateTime was created
|
||||
|
||||
@@ -140,7 +140,7 @@ class DatePeriod
|
||||
/*
|
||||
* Unknown date or format is invalid?
|
||||
*/
|
||||
if ($date === null || !Date::isValidDateFormat($format)) {
|
||||
if (null === $date || !Date::isValidDateFormat($format)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ class Miscellaneous
|
||||
|
||||
if (!empty($directoryContent)) {
|
||||
foreach ($directoryContent as $fileName) {
|
||||
if ($fileName != '.' && $fileName != '..') {
|
||||
if ('.' != $fileName && '..' != $fileName) {
|
||||
$content = null;
|
||||
|
||||
if (!empty($startFileName) && !$startFileFound) {
|
||||
@@ -80,7 +80,7 @@ class Miscellaneous
|
||||
$content = self::getDirectoryContent($directoryPath . $fileName, true, $maxFilesCount - $count);
|
||||
}
|
||||
|
||||
if ($content !== null) {
|
||||
if (null !== $content) {
|
||||
$files[$fileName] = $content;
|
||||
|
||||
if (!empty($maxFilesCount)) {
|
||||
@@ -365,7 +365,7 @@ class Miscellaneous
|
||||
* Oops, cannot instantiate converter
|
||||
* Nothing to do
|
||||
*/
|
||||
if ($converter === null) {
|
||||
if (null === $converter) {
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -460,7 +460,7 @@ class Miscellaneous
|
||||
* Value to find is neither a string nor an array OR it's an empty string?
|
||||
* Nothing to do
|
||||
*/
|
||||
if ((!$searchIsString && !$searchIsArray) || ($searchIsString && strlen($search) == 0)) {
|
||||
if ((!$searchIsString && !$searchIsArray) || ($searchIsString && 0 == strlen($search))) {
|
||||
return $effect;
|
||||
}
|
||||
|
||||
@@ -612,7 +612,7 @@ class Miscellaneous
|
||||
$effect = mb_substr($text, 0, $maxLength, 'utf-8');
|
||||
$lastSpacePosition = mb_strrpos($effect, ' ', 'utf-8');
|
||||
|
||||
if ($lastSpacePosition !== false) {
|
||||
if (false !== $lastSpacePosition) {
|
||||
$effect = mb_substr($effect, 0, $lastSpacePosition, 'utf-8');
|
||||
}
|
||||
|
||||
@@ -730,7 +730,7 @@ class Miscellaneous
|
||||
}
|
||||
|
||||
foreach (scandir($directoryPath) as $item) {
|
||||
if ($item == '.' || $item == '..') {
|
||||
if ('.' == $item || '..' == $item) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -776,7 +776,7 @@ class Miscellaneous
|
||||
foreach ($members as $key => $value) {
|
||||
$value = mb_strtolower($value);
|
||||
|
||||
if ($key == 0) {
|
||||
if (0 == $key) {
|
||||
$effect .= self::lowercaseFirst($value);
|
||||
} else {
|
||||
$effect .= self::uppercaseFirst($value);
|
||||
@@ -812,7 +812,7 @@ class Miscellaneous
|
||||
|
||||
if ($restLowercase) {
|
||||
$effect = mb_strtolower($effect);
|
||||
} elseif ($restLowercase === false) {
|
||||
} elseif (false === $restLowercase) {
|
||||
$effect = mb_strtoupper($effect);
|
||||
}
|
||||
|
||||
@@ -850,7 +850,7 @@ class Miscellaneous
|
||||
|
||||
if ($restLowercase) {
|
||||
$effect = mb_strtolower($effect);
|
||||
} elseif ($restLowercase === false) {
|
||||
} elseif (false === $restLowercase) {
|
||||
$effect = mb_strtoupper($effect);
|
||||
}
|
||||
|
||||
@@ -1032,6 +1032,8 @@ class Miscellaneous
|
||||
$separator = DIRECTORY_SEPARATOR;
|
||||
|
||||
foreach ($paths as $path) {
|
||||
$path = trim($path);
|
||||
|
||||
/*
|
||||
* Empty paths are useless
|
||||
*/
|
||||
@@ -1153,7 +1155,7 @@ class Miscellaneous
|
||||
{
|
||||
$value = filter_input($globalSourceType, $variableName);
|
||||
|
||||
if ($value === null) {
|
||||
if (null === $value) {
|
||||
$globalSource = null;
|
||||
|
||||
switch ($globalSourceType) {
|
||||
@@ -1178,7 +1180,7 @@ class Miscellaneous
|
||||
break;
|
||||
}
|
||||
|
||||
if ($globalSource !== null && isset($globalSource[$variableName])) {
|
||||
if (null !== $globalSource && isset($globalSource[$variableName])) {
|
||||
$value = $globalSource[$variableName];
|
||||
|
||||
if (!ini_get('magic_quotes_gpc')) {
|
||||
@@ -1232,7 +1234,7 @@ class Miscellaneous
|
||||
/*
|
||||
* First line is only HTTP status and is unneeded so skip it
|
||||
*/
|
||||
if ($i === 0) {
|
||||
if (0 === $i) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1242,7 +1244,7 @@ class Miscellaneous
|
||||
/*
|
||||
* If the header is a "set-cookie" let's save it to "cookies" array
|
||||
*/
|
||||
if ($key === 'Set-Cookie') {
|
||||
if ('Set-Cookie' === $key) {
|
||||
$cookieParameters = explode(';', $value);
|
||||
|
||||
$name = '';
|
||||
@@ -1260,7 +1262,7 @@ class Miscellaneous
|
||||
* First parameter will be always a cookie name and it's value. It is not needed to run
|
||||
* further actions for them, so save the values and move to next parameter.
|
||||
*/
|
||||
if ($j === 0) {
|
||||
if (0 === $j) {
|
||||
$name = trim($param[0]);
|
||||
$value = trim($param[1]);
|
||||
continue;
|
||||
@@ -1416,7 +1418,7 @@ class Miscellaneous
|
||||
if ($asHexadecimal) {
|
||||
$hexadecimal = dechex($colorComponent);
|
||||
|
||||
if (strlen($hexadecimal) == 1) {
|
||||
if (1 == strlen($hexadecimal)) {
|
||||
return sprintf('0%s', $hexadecimal, $hexadecimal);
|
||||
}
|
||||
|
||||
@@ -1471,4 +1473,37 @@ class Miscellaneous
|
||||
|
||||
return $invertedColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns project's root path.
|
||||
* Looks for directory that contains composer.json.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getProjectRootPath()
|
||||
{
|
||||
$projectRootPath = '';
|
||||
|
||||
$fileName = 'composer.json';
|
||||
$directoryPath = __DIR__;
|
||||
|
||||
/*
|
||||
* Path of directory it's not the path of last directory?
|
||||
*/
|
||||
while (DIRECTORY_SEPARATOR !== $directoryPath) {
|
||||
$filePath = static::concatenatePaths($directoryPath, $fileName);
|
||||
|
||||
/*
|
||||
* Is here file we are looking for?
|
||||
* Maybe it's a project's root path
|
||||
*/
|
||||
if (file_exists($filePath)) {
|
||||
$projectRootPath = $directoryPath;
|
||||
}
|
||||
|
||||
$directoryPath = dirname($directoryPath);
|
||||
}
|
||||
|
||||
return $projectRootPath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class QueryBuilderUtility
|
||||
$compareOperator = '=';
|
||||
|
||||
if (is_array($value) && !empty($value)) {
|
||||
if (count($value) == 2) {
|
||||
if (2 == count($value)) {
|
||||
$compareOperator = $value[1];
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ class QueryBuilderUtility
|
||||
|
||||
$predicate = sprintf('%s.%s %s :%s', $alias, $column, $compareOperator, $column);
|
||||
|
||||
if ($value === null) {
|
||||
if (null === $value) {
|
||||
$predicate = $queryBuilder->expr()->isNull(sprintf('%s.%s', $alias, $column));
|
||||
unset($criteria[$column]);
|
||||
} else {
|
||||
|
||||
@@ -201,7 +201,7 @@ class Reflection
|
||||
* Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* 2016-11-07
|
||||
*/
|
||||
if ($object !== null) {
|
||||
if (null !== $object) {
|
||||
unset($exploded[0]);
|
||||
|
||||
$property = implode('.', $exploded);
|
||||
@@ -246,7 +246,7 @@ class Reflection
|
||||
}
|
||||
}
|
||||
|
||||
if (!$valueFound && $reflectionProperty !== null) {
|
||||
if (!$valueFound && null !== $reflectionProperty) {
|
||||
/*
|
||||
* Oops, we have got exception.
|
||||
*
|
||||
@@ -285,7 +285,7 @@ class Reflection
|
||||
foreach ($objects as $entity) {
|
||||
$value = self::getPropertyValue($entity, $property, $force);
|
||||
|
||||
if ($value !== null) {
|
||||
if (null !== $value) {
|
||||
$values[] = $value;
|
||||
}
|
||||
}
|
||||
@@ -345,7 +345,7 @@ class Reflection
|
||||
if ($withoutNamespace) {
|
||||
$classOnly = Miscellaneous::getLastElementOfString($name, '\\');
|
||||
|
||||
if ($classOnly !== null) {
|
||||
if (null !== $classOnly) {
|
||||
$name = $classOnly;
|
||||
}
|
||||
|
||||
@@ -417,31 +417,45 @@ class Reflection
|
||||
/**
|
||||
* Returns given object properties
|
||||
*
|
||||
* @param array|object|string $source An array of objects, namespaces, object or namespace
|
||||
* @param int $filter (optional) Filter of properties. Uses ReflectionProperty class constants.
|
||||
* By default all properties are returned.
|
||||
* @param array|object|string $source An array of objects, namespaces, object or namespace
|
||||
* @param int $filter (optional) Filter of properties. Uses ReflectionProperty class
|
||||
* constants. By default all properties are returned.
|
||||
* @param bool $includeParents (optional) If is set to true, properties of parent classes are
|
||||
* included (recursively). Otherwise - not.
|
||||
* @return array|ReflectionProperty
|
||||
*/
|
||||
public static function getProperties($source, $filter = null)
|
||||
public static function getProperties($source, $filter = null, $includeParents = false)
|
||||
{
|
||||
$className = self::getClassName($source);
|
||||
$reflection = new ReflectionClass($className);
|
||||
|
||||
if ($filter === null) {
|
||||
if (null === $filter) {
|
||||
$filter = ReflectionProperty::IS_PRIVATE
|
||||
+ ReflectionProperty::IS_PROTECTED
|
||||
+ ReflectionProperty::IS_PUBLIC
|
||||
+ ReflectionProperty::IS_STATIC;
|
||||
}
|
||||
|
||||
return $reflection->getProperties($filter);
|
||||
$properties = $reflection->getProperties($filter);
|
||||
$parentProperties = [];
|
||||
|
||||
if ($includeParents) {
|
||||
$parent = self::getParentClass($source);
|
||||
|
||||
if (false !== $parent) {
|
||||
$parentClass = $parent->getName();
|
||||
$parentProperties = self::getProperties($parentClass, $filter, $includeParents);
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge($properties, $parentProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a parent class
|
||||
* Returns a parent class or false if there is no parent class
|
||||
*
|
||||
* @param array|object|string $source An array of objects, namespaces, object or namespace
|
||||
* @return ReflectionClass
|
||||
* @return ReflectionClass|bool
|
||||
*/
|
||||
public static function getParentClass($source)
|
||||
{
|
||||
@@ -477,7 +491,7 @@ class Reflection
|
||||
/*
|
||||
* Oops, cannot resolve class
|
||||
*/
|
||||
if ($className === null) {
|
||||
if (null === $className) {
|
||||
throw new CannotResolveClassNameException($class);
|
||||
}
|
||||
|
||||
@@ -603,7 +617,7 @@ class Reflection
|
||||
if (!$uses && $verifyParents) {
|
||||
$parentClassName = self::getParentClassName($className);
|
||||
|
||||
if ($parentClassName !== null) {
|
||||
if (null !== $parentClassName) {
|
||||
return self::usesTrait($parentClassName, $trait, true);
|
||||
}
|
||||
}
|
||||
@@ -624,7 +638,7 @@ class Reflection
|
||||
$reflection = new ReflectionClass($className);
|
||||
$parentClass = $reflection->getParentClass();
|
||||
|
||||
if ($parentClass === null || $parentClass === false) {
|
||||
if (null === $parentClass || false === $parentClass) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class Regex
|
||||
$taxid = preg_replace('/[\s-]/', '', $taxidString);
|
||||
$sum = 0;
|
||||
|
||||
if (strlen($taxid) == 10 && is_numeric($taxid)) {
|
||||
if (10 == strlen($taxid) && is_numeric($taxid)) {
|
||||
for ($x = 0; $x <= 8; ++$x) {
|
||||
$sum += $taxid[$x] * $weights[$x];
|
||||
}
|
||||
@@ -185,9 +185,9 @@ class Regex
|
||||
$pattern = '|' . $filterExpression . '|';
|
||||
$matchesCount = preg_match($pattern, $value, $matches);
|
||||
|
||||
$remove = $matchesCount == 0;
|
||||
$remove = 0 == $matchesCount;
|
||||
} else {
|
||||
if ($value == '') {
|
||||
if ('' == $value) {
|
||||
$value = '\'\'';
|
||||
} elseif (is_string($value)) {
|
||||
$value = '\'' . $value . '\'';
|
||||
@@ -431,7 +431,7 @@ class Regex
|
||||
public static function startsWith($string, $beginning)
|
||||
{
|
||||
if (!empty($string) && !empty($beginning)) {
|
||||
if (strlen($beginning) == 1 && !self::isLetterOrDigit($beginning)) {
|
||||
if (1 == strlen($beginning) && !self::isLetterOrDigit($beginning)) {
|
||||
$beginning = '\\' . $beginning;
|
||||
}
|
||||
|
||||
@@ -452,7 +452,7 @@ class Regex
|
||||
*/
|
||||
public static function endsWith($string, $ending)
|
||||
{
|
||||
if (strlen($ending) == 1 && !self::isLetterOrDigit($ending)) {
|
||||
if (1 == strlen($ending) && !self::isLetterOrDigit($ending)) {
|
||||
$ending = '\\' . $ending;
|
||||
}
|
||||
|
||||
@@ -537,7 +537,7 @@ class Regex
|
||||
*/
|
||||
public static function contains($haystack, $needle)
|
||||
{
|
||||
if (strlen($needle) == 1 && !self::isLetterOrDigit($needle)) {
|
||||
if (1 == strlen($needle) && !self::isLetterOrDigit($needle)) {
|
||||
$needle = '\\' . $needle;
|
||||
}
|
||||
|
||||
@@ -653,7 +653,7 @@ class Regex
|
||||
}
|
||||
|
||||
$modulo = $sum % 11;
|
||||
$numberControl = ($modulo == 10) ? 0 : $modulo;
|
||||
$numberControl = (10 == $modulo) ? 0 : $modulo;
|
||||
|
||||
return $numberControl == $nip[9];
|
||||
}
|
||||
@@ -698,10 +698,10 @@ class Regex
|
||||
$color = Miscellaneous::replace($color, '/#/', '');
|
||||
$length = strlen($color);
|
||||
|
||||
if ($length === 3) {
|
||||
if (3 === $length) {
|
||||
$color = Miscellaneous::replace($color, '/(.)(.)(.)/', '$1$1$2$2$3$3');
|
||||
} else {
|
||||
if ($length !== 6) {
|
||||
if (6 !== $length) {
|
||||
if ($throwException) {
|
||||
throw new IncorrectColorHexLengthException($color);
|
||||
}
|
||||
|
||||
@@ -31,14 +31,14 @@ class Repository
|
||||
{
|
||||
$position = self::getExtremePosition($items, $asLast);
|
||||
|
||||
if ($position === null && $force) {
|
||||
if (null === $position && $force) {
|
||||
$position = 0;
|
||||
}
|
||||
|
||||
if ($position !== null && !empty($items)) {
|
||||
if (null !== $position && !empty($items)) {
|
||||
foreach ($items as $item) {
|
||||
if (method_exists($item, 'getPosition')) {
|
||||
if ($item->getPosition() === null) {
|
||||
if (null === $item->getPosition()) {
|
||||
if ($asLast) {
|
||||
++$position;
|
||||
} else {
|
||||
|
||||
@@ -40,7 +40,7 @@ class Xml
|
||||
$query = $path->query('/*/*');
|
||||
$nodesCount = $query->length;
|
||||
|
||||
if ($nodesCount == 0) {
|
||||
if (0 == $nodesCount) {
|
||||
return $element1;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
|
||||
/**
|
||||
* Tests of the collection of elements
|
||||
* Test case of the collection of elements
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
@@ -306,7 +306,7 @@ class CollectionTest extends BaseTestCase
|
||||
|
||||
public function testExistsVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyMethodVisibilityAndArguments(Collection::class, 'exists', OopVisibilityType::IS_PRIVATE, 1, 1);
|
||||
static::assertMethodVisibilityAndArguments(Collection::class, 'exists', OopVisibilityType::IS_PRIVATE, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,17 +9,23 @@
|
||||
namespace Meritoo\Common\Test\Exception\Base;
|
||||
|
||||
use Meritoo\Common\Exception\Base\UnknownTypeException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\Base\BaseType;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
|
||||
/**
|
||||
* Tests of the exception used while type of something is unknown
|
||||
* Test case of the exception used while type of something is unknown
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class UnknownTypeExceptionTest extends PHPUnit_Framework_TestCase
|
||||
class UnknownTypeExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(UnknownTestTypeException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
public function testWithoutException()
|
||||
{
|
||||
self::assertEquals('Test 2', (new TestService())->getTranslatedType('test_2'));
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Common\Test\Exception\Date;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Date\UnknownDatePartTypeException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\DatePartType;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while type of date part, e.g. "year", is unknown
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class UnknownDatePartTypeExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(UnknownDatePartTypeException::class, OopVisibilityType::IS_PUBLIC, 2, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $unknownDatePart Type of date part, e.g. "year". One of DatePartType class constants.
|
||||
* @param string $value Incorrect value
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideDatePartAndValue
|
||||
*/
|
||||
public function testConstructorMessage($unknownDatePart, $value, $expectedMessage)
|
||||
{
|
||||
$exception = new UnknownDatePartTypeException($unknownDatePart, $value);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides type of date part, incorrect value and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDatePartAndValue()
|
||||
{
|
||||
$template = 'The \'%s\' type of date part (with value %s) is unknown. Probably doesn\'t exist or there is a'
|
||||
. ' typo. You should use one of these types: day, hour, minute, month, second, year.';
|
||||
|
||||
yield[
|
||||
DatePartType::DAY,
|
||||
'44',
|
||||
sprintf($template, DatePartType::DAY, '44'),
|
||||
];
|
||||
|
||||
yield[
|
||||
DatePartType::MONTH,
|
||||
'22',
|
||||
sprintf($template, DatePartType::MONTH, '22'),
|
||||
];
|
||||
|
||||
yield[
|
||||
DatePartType::MINUTE,
|
||||
'77',
|
||||
sprintf($template, DatePartType::MINUTE, '77'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Common\Test\Exception\File;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\File\EmptyFileException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while file with given path is empty (has no content)
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class EmptyFileExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(EmptyFileException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emptyFilePath Path of the empty file
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider providePathOfFile
|
||||
*/
|
||||
public function testConstructorMessage($emptyFilePath, $expectedMessage)
|
||||
{
|
||||
$exception = new EmptyFileException($emptyFilePath);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides path of the empty file and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function providePathOfFile()
|
||||
{
|
||||
$template = 'File with path \'%s\' is empty (has no content). Did you provide path of proper file?';
|
||||
|
||||
yield[
|
||||
'aa/bb/cc',
|
||||
sprintf($template, 'aa/bb/cc'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'images/show/car.jpg',
|
||||
sprintf($template, 'images/show/car.jpg'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Common\Test\Exception\File;
|
||||
|
||||
use Meritoo\Common\Exception\File\EmptyFilePathException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while path of given file is empty
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class EmptyFilePathExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(EmptyFilePathException::class, OopVisibilityType::IS_PUBLIC);
|
||||
}
|
||||
|
||||
public function testConstructorMessage()
|
||||
{
|
||||
$exception = new EmptyFilePathException();
|
||||
static::assertEquals('Path of the file is empty. Did you provide path of proper file?', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Common\Test\Exception\File;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\File\NotExistingFileException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while file with given path does not exist
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class NotExistingFileExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(NotExistingFileException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $notExistingFilePath Path of not existing (or not readable) file
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider providePathOfFile
|
||||
*/
|
||||
public function testConstructorMessage($notExistingFilePath, $expectedMessage)
|
||||
{
|
||||
$exception = new NotExistingFileException($notExistingFilePath);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides path of not existing file and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function providePathOfFile()
|
||||
{
|
||||
$template = 'File with path \'%s\' does not exist (or is not readable). Did you provide path of proper file?';
|
||||
|
||||
yield[
|
||||
'aa/bb/cc',
|
||||
sprintf($template, 'aa/bb/cc'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'images/show/car.jpg',
|
||||
sprintf($template, 'images/show/car.jpg'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Common\Test\Exception\Method;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Method\DisabledMethodException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while method cannot be called, because is disabled
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class DisabledMethodExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(DisabledMethodException::class, OopVisibilityType::IS_PUBLIC, 2, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $disabledMethod Name of the disabled method
|
||||
* @param string $alternativeMethod Name of the alternative method
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @internal param string $emptyFilePath Path of the empty file
|
||||
* @dataProvider provideMethodsNames
|
||||
*/
|
||||
public function testConstructorMessage($disabledMethod, $alternativeMethod, $expectedMessage)
|
||||
{
|
||||
$exception = new DisabledMethodException($disabledMethod, $alternativeMethod);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of the disabled method, name of the alternative method and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideMethodsNames()
|
||||
{
|
||||
$templateShort = 'Method %s() cannot be called, because is disabled.';
|
||||
$templateLong = $templateShort . ' Use %s() instead.';
|
||||
|
||||
yield[
|
||||
'FooBar::loremIpsum',
|
||||
'',
|
||||
sprintf($templateShort, 'FooBar::loremIpsum'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'FooBar::loremIpsum',
|
||||
'AnotherClass::alternativeMethod',
|
||||
sprintf($templateLong, 'FooBar::loremIpsum', 'AnotherClass::alternativeMethod'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Common\Test\Exception\Reflection;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Reflection\CannotResolveClassNameException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while name of class or trait cannot be resolved
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class CannotResolveClassNameExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(CannotResolveClassNameException::class, OopVisibilityType::IS_PUBLIC, 2, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|object|string $source Source of the class's / trait's name. It can be an array of objects,
|
||||
* namespaces, object or namespace.
|
||||
* @param bool $forClass If is set to true, message of this exception for class is prepared.
|
||||
* Otherwise - for trait.
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideClassName
|
||||
*/
|
||||
public function testConstructorMessage($source, $forClass, $expectedMessage)
|
||||
{
|
||||
$exception = new CannotResolveClassNameException($source, $forClass);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides source of the class's / trait's name, information if message of this exception should be prepared for
|
||||
* class and the expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideClassName()
|
||||
{
|
||||
yield[
|
||||
'Not\Existing\Class',
|
||||
true,
|
||||
'Name of class from given \'string\' Not\Existing\Class cannot be resolved. Is there everything ok?',
|
||||
];
|
||||
|
||||
yield[
|
||||
'Not\Existing\Trait',
|
||||
false,
|
||||
'Name of trait from given \'string\' Not\Existing\Trait cannot be resolved. Is there everything ok?',
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
new \stdClass(),
|
||||
new \stdClass(),
|
||||
],
|
||||
true,
|
||||
'Name of class from given \'array\' cannot be resolved. Is there everything ok?',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Common\Test\Exception\Reflection;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Reflection\MissingChildClassesException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while given class has no child classes
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class MissingChildClassesExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(MissingChildClassesException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|object|string $parentClass Class that hasn't child classes, but it should. An array of objects,
|
||||
* strings, object or string.
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideParentClass
|
||||
*/
|
||||
public function testConstructorMessage($parentClass, $expectedMessage)
|
||||
{
|
||||
$exception = new MissingChildClassesException($parentClass);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of class that hasn't child classes, but it should, and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideParentClass()
|
||||
{
|
||||
$template = 'The \'%s\' class requires one child class at least who will extend her (maybe is an abstract'
|
||||
. ' class), but the child classes are missing. Did you forget to extend this class?';
|
||||
|
||||
yield[
|
||||
MissingChildClassesException::class,
|
||||
sprintf($template, MissingChildClassesException::class),
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
new \stdClass(),
|
||||
new \stdClass(),
|
||||
],
|
||||
sprintf($template, \stdClass::class),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Common\Test\Exception\Reflection;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Reflection\TooManyChildClassesException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while given class has more than one child class
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class TooManyChildClassesExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(TooManyChildClassesException::class, OopVisibilityType::IS_PUBLIC, 2, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|object|string $parentClass Class that has more than one child class, but it shouldn't. An array
|
||||
* of objects, strings, object or string.
|
||||
* @param array $childClasses Child classes
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideParentAndChildClasses
|
||||
*/
|
||||
public function testConstructorMessage($parentClass, array $childClasses, $expectedMessage)
|
||||
{
|
||||
$exception = new TooManyChildClassesException($parentClass, $childClasses);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of class that has more than one child class, but it shouldn't, child classes, and expected
|
||||
* exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideParentAndChildClasses()
|
||||
{
|
||||
$template = "The '%s' class requires one child class at most who will extend her, but more than one child"
|
||||
. " class was found:\n- %s\n\nWhy did you create more than one classes that extend '%s' class?";
|
||||
|
||||
yield[
|
||||
BaseTestCase::class,
|
||||
[
|
||||
\stdClass::class,
|
||||
OopVisibilityType::class,
|
||||
],
|
||||
sprintf($template, BaseTestCase::class, implode("\n- ", [
|
||||
\stdClass::class,
|
||||
OopVisibilityType::class,
|
||||
]), BaseTestCase::class),
|
||||
];
|
||||
|
||||
yield[
|
||||
TooManyChildClassesException::class,
|
||||
[
|
||||
\stdClass::class,
|
||||
],
|
||||
sprintf($template, TooManyChildClassesException::class, implode("\n- ", [\stdClass::class]), TooManyChildClassesException::class),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Common\Test\Exception\Regex;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Regex\IncorrectColorHexLengthException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while length of given hexadecimal value of color is incorrect
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class IncorrectColorHexLengthExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(IncorrectColorHexLengthException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $color Incorrect hexadecimal value of color
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideColor
|
||||
*/
|
||||
public function testConstructorMessage($color, $expectedMessage)
|
||||
{
|
||||
$exception = new IncorrectColorHexLengthException($color);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides incorrect hexadecimal value of color and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideColor()
|
||||
{
|
||||
$template = 'Length of hexadecimal value of color \'%s\' is incorrect. It\'s %d, but it should be 3 or 6. Is there everything ok?';
|
||||
|
||||
yield[
|
||||
'',
|
||||
sprintf($template, '', strlen('')),
|
||||
];
|
||||
|
||||
yield[
|
||||
'aa-bb-cc',
|
||||
sprintf($template, 'aa-bb-cc', strlen('aa-bb-cc')),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Common\Test\Exception\Regex;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Regex\InvalidColorHexValueException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while given hexadecimal value of color is invalid
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class InvalidColorHexValueExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(InvalidColorHexValueException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $color Invalid hexadecimal value of color
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideColor
|
||||
*/
|
||||
public function testConstructorMessage($color, $expectedMessage)
|
||||
{
|
||||
$exception = new InvalidColorHexValueException($color);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides invalid hexadecimal value of color and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideColor()
|
||||
{
|
||||
$template = 'Hexadecimal value of color \'%s\' is invalid. Is there everything ok?';
|
||||
|
||||
yield[
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield[
|
||||
'aa-bb-cc',
|
||||
sprintf($template, 'aa-bb-cc'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Common\Test\Exception\Regex;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Regex\InvalidUrlException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while url is invalid
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class InvalidUrlExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(InvalidUrlException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url Invalid url
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideUrl
|
||||
*/
|
||||
public function testConstructorMessage($url, $expectedMessage)
|
||||
{
|
||||
$exception = new InvalidUrlException($url);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides invalid url and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideUrl()
|
||||
{
|
||||
$template = 'Url \'%s\' is invalid. Is there everything ok?';
|
||||
|
||||
yield[
|
||||
'aa/bb/cc',
|
||||
sprintf($template, 'aa/bb/cc'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'http:/images\show\car.jpg',
|
||||
sprintf($template, 'http:/images\show\car.jpg'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Common\Test\Exception\Type;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while the visibility of a property, a method or (as of PHP 7.1.0) a constant is
|
||||
* unknown
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class UnknownOopVisibilityTypeExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(UnknownOopVisibilityTypeException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $unknownType Unknown OOP-related visibility
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideUnknownType
|
||||
*/
|
||||
public function testConstructorMessage($unknownType, $expectedMessage)
|
||||
{
|
||||
$exception = new UnknownOopVisibilityTypeException($unknownType);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides path of the empty file and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideUnknownType()
|
||||
{
|
||||
$allTypes = (new OopVisibilityType())->getAll();
|
||||
|
||||
$template = 'The \'%s\' type of OOP-related visibility is unknown. Probably doesn\'t exist or there is a typo.'
|
||||
. ' You should use one of these types: %s.';
|
||||
|
||||
yield[
|
||||
'',
|
||||
sprintf($template, '', implode(', ', $allTypes)),
|
||||
];
|
||||
|
||||
yield[
|
||||
123,
|
||||
sprintf($template, 123, implode(', ', $allTypes)),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -10,15 +10,15 @@ namespace Meritoo\Common\Test\Type\Base;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Type\Base\BaseType;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests of the base / abstract type of something
|
||||
* Test case of the base / abstract type of something
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class BaseTypeTest extends PHPUnit_Framework_TestCase
|
||||
class BaseTypeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param BaseType $type Type of something
|
||||
|
||||
@@ -12,7 +12,7 @@ use Meritoo\Common\Test\Base\BaseTypeTestCase;
|
||||
use Meritoo\Common\Type\DatePartType;
|
||||
|
||||
/**
|
||||
* Tests of the type of date part, e.g. "year"
|
||||
* Test case of the type of date part, e.g. "year"
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
|
||||
@@ -8,16 +8,16 @@
|
||||
|
||||
namespace Meritoo\Common\Test\Utilities;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Utilities\Arrays;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* Tests of the useful arrays methods
|
||||
* Test case of the useful arrays methods
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ArraysTest extends PHPUnit_Framework_TestCase
|
||||
class ArraysTest extends BaseTestCase
|
||||
{
|
||||
private $simpleArray;
|
||||
private $simpleArrayWithKeys;
|
||||
@@ -25,6 +25,11 @@ class ArraysTest extends PHPUnit_Framework_TestCase
|
||||
private $complexArray;
|
||||
private $superComplexArray;
|
||||
|
||||
public function verifyConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(Arrays::class);
|
||||
}
|
||||
|
||||
public function testValues2string()
|
||||
{
|
||||
/*
|
||||
|
||||
@@ -8,17 +8,22 @@
|
||||
|
||||
namespace Meritoo\Common\Test\Utilities;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Utilities\Bundle;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* Tests of the useful methods for bundle
|
||||
* Test case of the useful methods for bundle
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class BundleTest extends PHPUnit_Framework_TestCase
|
||||
class BundleTest extends BaseTestCase
|
||||
{
|
||||
public function verifyConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(Bundle::class);
|
||||
}
|
||||
|
||||
public function testGetBundleViewPathEmptyPathAndBundle()
|
||||
{
|
||||
self::assertNull(Bundle::getBundleViewPath('', ''));
|
||||
|
||||
@@ -13,7 +13,7 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Utilities\Composer;
|
||||
|
||||
/**
|
||||
* Tests of the useful Composer-related methods
|
||||
* Test case of the useful Composer-related methods
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
@@ -27,6 +27,11 @@ class ComposerTest extends BaseTestCase
|
||||
*/
|
||||
private $composerJsonPath;
|
||||
|
||||
public function verifyConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(Composer::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $composerJsonPath Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
|
||||
@@ -15,7 +15,7 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\Common\Utilities\DatePeriod;
|
||||
|
||||
/**
|
||||
* Tests of date's period
|
||||
* Test case of date's period
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
@@ -24,7 +24,7 @@ class DatePeriodTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyConstructorVisibilityAndArguments(DatePeriod::class, OopVisibilityType::IS_PUBLIC, 2, 0);
|
||||
static::assertConstructorVisibilityAndArguments(DatePeriod::class, OopVisibilityType::IS_PUBLIC, 2, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,13 +16,18 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Utilities\Date;
|
||||
|
||||
/**
|
||||
* Tests of the Date methods (only static functions)
|
||||
* Test case of the Date methods (only static functions)
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class DateTest extends BaseTestCase
|
||||
{
|
||||
public function verifyConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(Date::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
@@ -454,8 +459,11 @@ class DateTest extends BaseTestCase
|
||||
$start = 1;
|
||||
$end = 100;
|
||||
|
||||
$intervalMinDate = (clone $startDate)->add(new DateInterval(sprintf('P%dD', $start)));
|
||||
$intervalMaxDate = (clone $startDate)->add(new DateInterval(sprintf('P%dD', $end)));
|
||||
$minDate = clone $startDate;
|
||||
$maxDate = clone $startDate;
|
||||
|
||||
$intervalMinDate = $minDate->add(new DateInterval(sprintf('P%dD', $start)));
|
||||
$intervalMaxDate = $maxDate->add(new DateInterval(sprintf('P%dD', $end)));
|
||||
|
||||
$randomDate = Date::getRandomDate();
|
||||
self::assertTrue($randomDate >= $intervalMinDate && $randomDate <= $intervalMaxDate);
|
||||
@@ -471,7 +479,9 @@ class DateTest extends BaseTestCase
|
||||
public function testGetRandomDateIncorrectEnd(DateTime $startDate, $start, $end)
|
||||
{
|
||||
$randomDate = Date::getRandomDate($startDate, $start, $end);
|
||||
$intervalDate = (clone $startDate)->add(new DateInterval(sprintf('P%dD', $start)));
|
||||
|
||||
$cloned = clone $startDate;
|
||||
$intervalDate = $cloned->add(new DateInterval(sprintf('P%dD', $start)));
|
||||
|
||||
self::assertTrue($randomDate >= $intervalDate && $randomDate <= $intervalDate);
|
||||
}
|
||||
@@ -487,8 +497,11 @@ class DateTest extends BaseTestCase
|
||||
{
|
||||
$randomDate = Date::getRandomDate($startDate, $start, $end);
|
||||
|
||||
$intervalMinDate = (clone $startDate)->add(new DateInterval(sprintf('P%dD', $start)));
|
||||
$intervalMaxDate = (clone $startDate)->add(new DateInterval(sprintf('P%dD', $end)));
|
||||
$minDate = clone $startDate;
|
||||
$maxDate = clone $startDate;
|
||||
|
||||
$intervalMinDate = $minDate->add(new DateInterval(sprintf('P%dD', $start)));
|
||||
$intervalMaxDate = $maxDate->add(new DateInterval(sprintf('P%dD', $end)));
|
||||
|
||||
self::assertTrue($randomDate >= $intervalMinDate && $randomDate <= $intervalMaxDate);
|
||||
}
|
||||
|
||||
@@ -12,13 +12,18 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Utilities\GeneratorUtility;
|
||||
|
||||
/**
|
||||
* Tests of the useful methods for the Generator class
|
||||
* Test case of the useful methods for the Generator class
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class GeneratorUtilityTest extends BaseTestCase
|
||||
{
|
||||
public function verifyConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(GeneratorUtility::class);
|
||||
}
|
||||
|
||||
public function testGetGeneratorElements()
|
||||
{
|
||||
/*
|
||||
|
||||
@@ -13,13 +13,18 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Utilities\Locale;
|
||||
|
||||
/**
|
||||
* Tests of the useful locale methods
|
||||
* Test case of the useful locale methods
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class LocaleTest extends BaseTestCase
|
||||
{
|
||||
public function verifyConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(Locale::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $languageCode Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
|
||||
@@ -13,13 +13,18 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Utilities\MimeTypes;
|
||||
|
||||
/**
|
||||
* Tests of the useful methods for mime types of files
|
||||
* Test case of the useful methods for mime types of files
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class MimeTypesTest extends BaseTestCase
|
||||
{
|
||||
public function verifyConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(MimeTypes::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $mimeType Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
|
||||
@@ -17,7 +17,7 @@ use Meritoo\Common\Utilities\Miscellaneous;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Tests of the Miscellaneous methods (only static functions)
|
||||
* Test case of the Miscellaneous methods (only static functions)
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
@@ -28,6 +28,11 @@ class MiscellaneousTest extends BaseTestCase
|
||||
private $stringCommaSeparated;
|
||||
private $stringDotSeparated;
|
||||
|
||||
public function verifyConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(Miscellaneous::class);
|
||||
}
|
||||
|
||||
public function testGetDirectoryContent()
|
||||
{
|
||||
$directoryPath = __DIR__ . '/../';
|
||||
@@ -503,16 +508,35 @@ class MiscellaneousTest extends BaseTestCase
|
||||
self::assertEquals('lorem ipsum', Miscellaneous::trimSmart(' lorem ipsum '));
|
||||
}
|
||||
|
||||
public function testConcatenatePaths()
|
||||
/**
|
||||
* @param mixed $emptyPaths Empty paths co concatenate
|
||||
* @dataProvider provideEmptyValue
|
||||
*/
|
||||
public function testConcatenatePathsWithEmptyPaths($emptyPaths)
|
||||
{
|
||||
self::assertEquals('', Miscellaneous::concatenatePaths($emptyPaths));
|
||||
}
|
||||
|
||||
public function testConcatenatePathsWithOneEmptyPath()
|
||||
{
|
||||
$paths = [
|
||||
'first/directory',
|
||||
'second/one',
|
||||
'',
|
||||
'and/the/third',
|
||||
];
|
||||
|
||||
$concatenated = Miscellaneous::concatenatePaths($paths);
|
||||
unset($paths[2]);
|
||||
$imploded = implode('/', $paths);
|
||||
|
||||
self::assertEquals('/' . $imploded, $concatenated);
|
||||
}
|
||||
|
||||
public function testConcatenatePathsInNixOs()
|
||||
{
|
||||
/*
|
||||
* Common cases
|
||||
*/
|
||||
self::assertEquals('', Miscellaneous::concatenatePaths(null));
|
||||
self::assertEquals('', Miscellaneous::concatenatePaths([]));
|
||||
|
||||
/*
|
||||
* *nix operating system
|
||||
* For *nix operating system
|
||||
*/
|
||||
$paths1 = [
|
||||
'first/directory',
|
||||
@@ -522,7 +546,10 @@ class MiscellaneousTest extends BaseTestCase
|
||||
|
||||
self::assertEquals('/' . implode('/', $paths1), Miscellaneous::concatenatePaths($paths1));
|
||||
self::assertEquals('/' . implode('/', $paths1), Miscellaneous::concatenatePaths($paths1[0], $paths1[1], $paths1[2]));
|
||||
}
|
||||
|
||||
public function testConcatenatePathsInWindowsOs()
|
||||
{
|
||||
/*
|
||||
* For Windows operating system
|
||||
*/
|
||||
@@ -720,6 +747,11 @@ class MiscellaneousTest extends BaseTestCase
|
||||
self::assertSame($expected, Miscellaneous::fillMissingZeros($number, $length, $before));
|
||||
}
|
||||
|
||||
public function testGetProjectRootPath()
|
||||
{
|
||||
self::assertNotEmpty(Miscellaneous::getProjectRootPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides string to convert characters to latin characters and not lower cased and not human-readable
|
||||
*
|
||||
|
||||
@@ -19,8 +19,15 @@ class A
|
||||
{
|
||||
use E;
|
||||
|
||||
private $count = 1;
|
||||
|
||||
protected function lorem()
|
||||
{
|
||||
return 'ipsum';
|
||||
}
|
||||
|
||||
protected function getCount()
|
||||
{
|
||||
return $this->count;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,4 +17,10 @@ namespace Meritoo\Common\Test\Utilities\Reflection;
|
||||
*/
|
||||
class B extends A
|
||||
{
|
||||
protected $name = 'Lorem Ipsum';
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,15 +20,21 @@ use Meritoo\Common\Test\Utilities\Reflection\C;
|
||||
use Meritoo\Common\Test\Utilities\Reflection\D;
|
||||
use Meritoo\Common\Test\Utilities\Reflection\E;
|
||||
use Meritoo\Common\Utilities\Reflection;
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* Tests of the useful reflection methods
|
||||
* Test case of the useful reflection methods
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ReflectionTest extends BaseTestCase
|
||||
{
|
||||
public function verifyConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(Reflection::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $invalidClass Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
@@ -171,11 +177,11 @@ class ReflectionTest extends BaseTestCase
|
||||
|
||||
public function testGetMethods()
|
||||
{
|
||||
self::assertEquals(0, count(Reflection::getMethods(B::class, true)));
|
||||
self::assertEquals(1, count(Reflection::getMethods(B::class)));
|
||||
self::assertEquals(1, count(Reflection::getMethods(A::class)));
|
||||
self::assertEquals(1, count(Reflection::getMethods(B::class, true)));
|
||||
self::assertEquals(3, count(Reflection::getMethods(B::class)));
|
||||
self::assertEquals(2, count(Reflection::getMethods(A::class)));
|
||||
self::assertEquals(2, count(Reflection::getMethods(C::class, true)));
|
||||
self::assertEquals(3, count(Reflection::getMethods(C::class)));
|
||||
self::assertEquals(5, count(Reflection::getMethods(C::class)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,6 +222,23 @@ class ReflectionTest extends BaseTestCase
|
||||
self::assertFalse(Reflection::usesTrait(D::class, E::class, true));
|
||||
}
|
||||
|
||||
public function testGetProperties()
|
||||
{
|
||||
self::assertCount(1, Reflection::getProperties(B::class));
|
||||
}
|
||||
|
||||
public function testGetPropertiesUsingFilter()
|
||||
{
|
||||
self::assertCount(1, Reflection::getProperties(B::class, ReflectionProperty::IS_PROTECTED));
|
||||
self::assertCount(0, Reflection::getProperties(B::class, ReflectionProperty::IS_PRIVATE));
|
||||
self::assertCount(1, Reflection::getProperties(B::class, ReflectionProperty::IS_PRIVATE, true));
|
||||
}
|
||||
|
||||
public function testGetPropertiesWithParents()
|
||||
{
|
||||
self::assertCount(2, Reflection::getProperties(B::class, null, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides invalid class and trait
|
||||
*
|
||||
|
||||
@@ -8,18 +8,24 @@
|
||||
|
||||
namespace Meritoo\Common\Utilities;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
|
||||
/**
|
||||
* Tests of the useful regular expressions methods
|
||||
* Test case of the useful regular expressions methods
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class RegexTest extends \PHPUnit_Framework_TestCase
|
||||
class RegexTest extends BaseTestCase
|
||||
{
|
||||
private $simpleText;
|
||||
|
||||
private $camelCaseText;
|
||||
|
||||
public function verifyConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(Regex::class);
|
||||
}
|
||||
|
||||
public function testGetCamelCaseParts()
|
||||
{
|
||||
$parts = [];
|
||||
|
||||
@@ -12,13 +12,18 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Utilities\Uri;
|
||||
|
||||
/**
|
||||
* Tests of the useful uri methods (only static functions)
|
||||
* Test case of the useful uri methods (only static functions)
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class UriTest extends BaseTestCase
|
||||
{
|
||||
public function verifyConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(Uri::class);
|
||||
}
|
||||
|
||||
public function testAddProtocolToUrl()
|
||||
{
|
||||
$http = 'http';
|
||||
|
||||
@@ -8,21 +8,26 @@
|
||||
|
||||
namespace Meritoo\Common\Test\Utilities;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Utilities\Xml;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use SimpleXMLElement;
|
||||
|
||||
/**
|
||||
* Tests of the useful XML-related methods (only static functions)
|
||||
* Test case of the useful XML-related methods (only static functions)
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class XmlTest extends PHPUnit_Framework_TestCase
|
||||
class XmlTest extends BaseTestCase
|
||||
{
|
||||
private $simpleXml;
|
||||
private $advancedXml;
|
||||
|
||||
public function verifyConstructor()
|
||||
{
|
||||
static::assertHasNoConstructor(Xml::class);
|
||||
}
|
||||
|
||||
public function testMergeNodes()
|
||||
{
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user