mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-13 01:51:50 +01:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37e7b14ae2 | ||
|
|
a12aaf4bc0 | ||
|
|
f9c480aa19 | ||
|
|
ffa3fbffe7 | ||
|
|
48aa27fb86 | ||
|
|
86cc5ff79b | ||
|
|
633696ebc0 |
@@ -2,7 +2,7 @@
|
|||||||
"name": "meritoo/common-library",
|
"name": "meritoo/common-library",
|
||||||
"description": "Useful classes, methods, extensions etc.",
|
"description": "Useful classes, methods, extensions etc.",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "0.0.11",
|
"version": "0.0.13",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Meritoo.pl",
|
"name": "Meritoo.pl",
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class NotExistingFileException extends \Exception
|
|||||||
*/
|
*/
|
||||||
public function __construct($notExistingFilePath)
|
public function __construct($notExistingFilePath)
|
||||||
{
|
{
|
||||||
$template = 'File with path \'%s\' does not exist (or is not readable). Did you provide proper path of file?';
|
$template = 'File with path \'%s\' does not exist (or is not readable). Did you provide path of proper file?';
|
||||||
$message = sprintf($template, $notExistingFilePath);
|
$message = sprintf($template, $notExistingFilePath);
|
||||||
|
|
||||||
parent::__construct($message);
|
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
|
* 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.
|
* namespaces, object or namespace.
|
||||||
* @param bool $forClass (optional) If is set to true, message of this exception for class is
|
* @param bool $forClass (optional) If is set to true, message of this exception for class is
|
||||||
* prepared. Otherwise - for trait.
|
* prepared. Otherwise - for trait.
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ namespace Meritoo\Common\Utilities;
|
|||||||
/**
|
/**
|
||||||
* Useful arrays methods
|
* Useful arrays methods
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class Arrays
|
class Arrays
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ namespace Meritoo\Common\Utilities;
|
|||||||
/**
|
/**
|
||||||
* Useful methods for bundle
|
* Useful methods for bundle
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class Bundle
|
class Bundle
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ use Meritoo\Common\Type\DatePartType;
|
|||||||
/**
|
/**
|
||||||
* Useful date methods
|
* Useful date methods
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class Date
|
class Date
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ use DateTime;
|
|||||||
* A date's period.
|
* A date's period.
|
||||||
* Contains start and end date of the period.
|
* Contains start and end date of the period.
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class DatePeriod
|
class DatePeriod
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ namespace Meritoo\Common\Utilities;
|
|||||||
/**
|
/**
|
||||||
* Useful locale methods
|
* Useful locale methods
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class Locale
|
class Locale
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ namespace Meritoo\Common\Utilities;
|
|||||||
/**
|
/**
|
||||||
* Useful methods for mime types of files
|
* Useful methods for mime types of files
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class MimeTypes
|
class MimeTypes
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ use Transliterator;
|
|||||||
/**
|
/**
|
||||||
* Miscellaneous methods (only static functions)
|
* Miscellaneous methods (only static functions)
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class Miscellaneous
|
class Miscellaneous
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ use Doctrine\ORM\QueryBuilder;
|
|||||||
/**
|
/**
|
||||||
* Useful methods for query builder (the Doctrine's QueryBuilder class)
|
* Useful methods for query builder (the Doctrine's QueryBuilder class)
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class QueryBuilderUtility
|
class QueryBuilderUtility
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
namespace Meritoo\Common\Utilities;
|
namespace Meritoo\Common\Utilities;
|
||||||
|
|
||||||
use Doctrine\Common\Collections\Collection;
|
|
||||||
use Doctrine\Common\Util\ClassUtils;
|
use Doctrine\Common\Util\ClassUtils;
|
||||||
use Doctrine\Common\Util\Inflector;
|
use Doctrine\Common\Util\Inflector;
|
||||||
|
use Meritoo\Common\Collection\Collection;
|
||||||
use Meritoo\Common\Exception\Reflection\CannotResolveClassNameException;
|
use Meritoo\Common\Exception\Reflection\CannotResolveClassNameException;
|
||||||
use Meritoo\Common\Exception\Reflection\MissingChildClassesException;
|
use Meritoo\Common\Exception\Reflection\MissingChildClassesException;
|
||||||
use Meritoo\Common\Exception\Reflection\TooManyChildClassesException;
|
use Meritoo\Common\Exception\Reflection\TooManyChildClassesException;
|
||||||
@@ -23,8 +23,8 @@ use ReflectionProperty;
|
|||||||
/**
|
/**
|
||||||
* Useful reflection methods
|
* Useful reflection methods
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class Reflection
|
class Reflection
|
||||||
{
|
{
|
||||||
@@ -229,17 +229,29 @@ class Reflection
|
|||||||
if ($class->hasProperty($property) || $force) {
|
if ($class->hasProperty($property) || $force) {
|
||||||
$property = Inflector::classify($property);
|
$property = Inflector::classify($property);
|
||||||
|
|
||||||
$methodPrefixes = [
|
$getterPrefixes = [
|
||||||
'get',
|
'get',
|
||||||
'has',
|
'has',
|
||||||
'is',
|
'is',
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($methodPrefixes as $prefix) {
|
foreach ($getterPrefixes as $prefix) {
|
||||||
$method = sprintf('%s%s', $prefix, $property);
|
$getterName = sprintf('%s%s', $prefix, $property);
|
||||||
|
|
||||||
if ($class->hasMethod($method)) {
|
if ($class->hasMethod($getterName)) {
|
||||||
$value = $object->{$method}();
|
$method = new ReflectionMethod($object, $getterName);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Getter is not accessible publicly?
|
||||||
|
* I have to skip it, to avoid an error like this:
|
||||||
|
*
|
||||||
|
* Call to protected method My\ExtraClass::getExtraProperty() from context 'My\ExtraClass'
|
||||||
|
*/
|
||||||
|
if ($method->isProtected() || $method->isPrivate()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = $object->{$getterName}();
|
||||||
$valueFound = true;
|
$valueFound = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -248,13 +260,14 @@ class Reflection
|
|||||||
|
|
||||||
if (!$valueFound && null !== $reflectionProperty) {
|
if (!$valueFound && null !== $reflectionProperty) {
|
||||||
/*
|
/*
|
||||||
* Oops, we have got exception.
|
* Oops, value of the property is still unknown
|
||||||
*
|
*
|
||||||
* 3rd try:
|
* 3rd try:
|
||||||
* Let's try modify accessibility of the property and try again to get value.
|
* Let's modify accessibility of the property and try again to get value
|
||||||
*/
|
*/
|
||||||
$reflectionProperty->setAccessible(true);
|
$reflectionProperty->setAccessible(true);
|
||||||
$value = $reflectionProperty->getValue($object);
|
$value = $reflectionProperty->getValue($object);
|
||||||
|
$reflectionProperty->setAccessible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -275,6 +288,14 @@ class Reflection
|
|||||||
*/
|
*/
|
||||||
public static function getPropertyValues($objects, $property, $force = false)
|
public static function getPropertyValues($objects, $property, $force = false)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* No objects?
|
||||||
|
* Nothing to do
|
||||||
|
*/
|
||||||
|
if (empty($objects)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
if ($objects instanceof Collection) {
|
if ($objects instanceof Collection) {
|
||||||
$objects = $objects->toArray();
|
$objects = $objects->toArray();
|
||||||
}
|
}
|
||||||
@@ -417,12 +438,14 @@ class Reflection
|
|||||||
/**
|
/**
|
||||||
* Returns given object properties
|
* Returns given object properties
|
||||||
*
|
*
|
||||||
* @param array|object|string $source An array of objects, namespaces, object or namespace
|
* @param array|object|string $source An array of objects, namespaces, object or namespace
|
||||||
* @param int $filter (optional) Filter of properties. Uses ReflectionProperty class constants.
|
* @param int $filter (optional) Filter of properties. Uses ReflectionProperty class
|
||||||
* By default all properties are returned.
|
* 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
|
* @return array|ReflectionProperty
|
||||||
*/
|
*/
|
||||||
public static function getProperties($source, $filter = null)
|
public static function getProperties($source, $filter = null, $includeParents = false)
|
||||||
{
|
{
|
||||||
$className = self::getClassName($source);
|
$className = self::getClassName($source);
|
||||||
$reflection = new ReflectionClass($className);
|
$reflection = new ReflectionClass($className);
|
||||||
@@ -434,14 +457,26 @@ class Reflection
|
|||||||
+ ReflectionProperty::IS_STATIC;
|
+ 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
|
* @param array|object|string $source An array of objects, namespaces, object or namespace
|
||||||
* @return ReflectionClass
|
* @return ReflectionClass|bool
|
||||||
*/
|
*/
|
||||||
public static function getParentClass($source)
|
public static function getParentClass($source)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ use Meritoo\Common\Exception\Regex\InvalidColorHexValueException;
|
|||||||
/**
|
/**
|
||||||
* Useful regular expressions methods
|
* Useful regular expressions methods
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class Regex
|
class Regex
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ use Doctrine\ORM\QueryBuilder;
|
|||||||
/**
|
/**
|
||||||
* Useful methods for repository
|
* Useful methods for repository
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class Repository
|
class Repository
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ namespace Meritoo\Common\Utilities;
|
|||||||
/**
|
/**
|
||||||
* Useful uri methods (only static functions)
|
* Useful uri methods (only static functions)
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class Uri
|
class Uri
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ use SimpleXMLElement;
|
|||||||
/**
|
/**
|
||||||
* Useful XML-related methods (only static functions)
|
* Useful XML-related methods (only static functions)
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class Xml
|
class Xml
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
|||||||
use Meritoo\Common\Type\OopVisibilityType;
|
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>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
|
|||||||
@@ -9,17 +9,23 @@
|
|||||||
namespace Meritoo\Common\Test\Exception\Base;
|
namespace Meritoo\Common\Test\Exception\Base;
|
||||||
|
|
||||||
use Meritoo\Common\Exception\Base\UnknownTypeException;
|
use Meritoo\Common\Exception\Base\UnknownTypeException;
|
||||||
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
use Meritoo\Common\Type\Base\BaseType;
|
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>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class UnknownTypeExceptionTest extends TestCase
|
class UnknownTypeExceptionTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
|
public function testConstructorVisibilityAndArguments()
|
||||||
|
{
|
||||||
|
static::assertConstructorVisibilityAndArguments(UnknownTestTypeException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
public function testWithoutException()
|
public function testWithoutException()
|
||||||
{
|
{
|
||||||
self::assertEquals('Test 2', (new TestService())->getTranslatedType('test_2'));
|
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)),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@ 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>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use Meritoo\Common\Test\Base\BaseTypeTestCase;
|
|||||||
use Meritoo\Common\Type\DatePartType;
|
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>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
|||||||
use Meritoo\Common\Utilities\Arrays;
|
use Meritoo\Common\Utilities\Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the useful arrays methods
|
* Test case of the useful arrays methods
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
|||||||
use Meritoo\Common\Utilities\Bundle;
|
use Meritoo\Common\Utilities\Bundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the useful methods for bundle
|
* Test case of the useful methods for bundle
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
|||||||
use Meritoo\Common\Utilities\Composer;
|
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>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use Meritoo\Common\Type\OopVisibilityType;
|
|||||||
use Meritoo\Common\Utilities\DatePeriod;
|
use Meritoo\Common\Utilities\DatePeriod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of date's period
|
* Test case of date's period
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
|||||||
use Meritoo\Common\Utilities\Date;
|
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>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
|||||||
use Meritoo\Common\Utilities\GeneratorUtility;
|
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>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
|||||||
use Meritoo\Common\Utilities\Locale;
|
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>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
|||||||
use Meritoo\Common\Utilities\MimeTypes;
|
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>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ use Meritoo\Common\Utilities\Miscellaneous;
|
|||||||
use stdClass;
|
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>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
|
|||||||
@@ -19,8 +19,15 @@ class A
|
|||||||
{
|
{
|
||||||
use E;
|
use E;
|
||||||
|
|
||||||
|
private $count = 1;
|
||||||
|
|
||||||
protected function lorem()
|
protected function lorem()
|
||||||
{
|
{
|
||||||
return 'ipsum';
|
return 'ipsum';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getCount()
|
||||||
|
{
|
||||||
|
return $this->count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,4 +17,10 @@ namespace Meritoo\Common\Test\Utilities\Reflection;
|
|||||||
*/
|
*/
|
||||||
class B extends A
|
class B extends A
|
||||||
{
|
{
|
||||||
|
protected $name = 'Lorem Ipsum';
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
54
tests/Meritoo/Common/Test/Utilities/Reflection/F.php
Normal file
54
tests/Meritoo/Common/Test/Utilities/Reflection/F.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?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\Utilities\Reflection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The F class.
|
||||||
|
* Used for testing the Reflection class.
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
class F
|
||||||
|
{
|
||||||
|
protected $username;
|
||||||
|
private $accountBalance;
|
||||||
|
private $city;
|
||||||
|
private $country;
|
||||||
|
private $gInstance;
|
||||||
|
|
||||||
|
public function __construct($accountBalance, $city, $country, $username, $firstName = 'John', $lastName = 'Scott')
|
||||||
|
{
|
||||||
|
$this->accountBalance = $accountBalance;
|
||||||
|
$this->city = $city;
|
||||||
|
$this->country = $country;
|
||||||
|
$this->username = $username;
|
||||||
|
$this->gInstance = new G($firstName, $lastName);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Called to avoid "Unused private method getAccountBalance" warning only
|
||||||
|
*/
|
||||||
|
$this->getAccountBalance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCountry()
|
||||||
|
{
|
||||||
|
return $this->country;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getCity()
|
||||||
|
{
|
||||||
|
return $this->city;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getAccountBalance()
|
||||||
|
{
|
||||||
|
return $this->accountBalance;
|
||||||
|
}
|
||||||
|
}
|
||||||
38
tests/Meritoo/Common/Test/Utilities/Reflection/G.php
Normal file
38
tests/Meritoo/Common/Test/Utilities/Reflection/G.php
Normal file
@@ -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\Test\Utilities\Reflection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The G class.
|
||||||
|
* Used for testing the Reflection class.
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
class G
|
||||||
|
{
|
||||||
|
private $firstName;
|
||||||
|
private $lastName;
|
||||||
|
|
||||||
|
public function __construct($firstName = 'John', $lastName = 'Scott')
|
||||||
|
{
|
||||||
|
$this->firstName = $firstName;
|
||||||
|
$this->lastName = $lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFirstName()
|
||||||
|
{
|
||||||
|
return $this->firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLastName()
|
||||||
|
{
|
||||||
|
return $this->lastName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ namespace Meritoo\Common\Test\Utilities;
|
|||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Generator;
|
use Generator;
|
||||||
|
use Meritoo\Common\Collection\Collection;
|
||||||
use Meritoo\Common\Exception\Reflection\CannotResolveClassNameException;
|
use Meritoo\Common\Exception\Reflection\CannotResolveClassNameException;
|
||||||
use Meritoo\Common\Exception\Reflection\MissingChildClassesException;
|
use Meritoo\Common\Exception\Reflection\MissingChildClassesException;
|
||||||
use Meritoo\Common\Exception\Reflection\TooManyChildClassesException;
|
use Meritoo\Common\Exception\Reflection\TooManyChildClassesException;
|
||||||
@@ -19,10 +20,13 @@ use Meritoo\Common\Test\Utilities\Reflection\B;
|
|||||||
use Meritoo\Common\Test\Utilities\Reflection\C;
|
use Meritoo\Common\Test\Utilities\Reflection\C;
|
||||||
use Meritoo\Common\Test\Utilities\Reflection\D;
|
use Meritoo\Common\Test\Utilities\Reflection\D;
|
||||||
use Meritoo\Common\Test\Utilities\Reflection\E;
|
use Meritoo\Common\Test\Utilities\Reflection\E;
|
||||||
|
use Meritoo\Common\Test\Utilities\Reflection\F;
|
||||||
|
use Meritoo\Common\Test\Utilities\Reflection\G;
|
||||||
use Meritoo\Common\Utilities\Reflection;
|
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>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
@@ -176,11 +180,11 @@ class ReflectionTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testGetMethods()
|
public function testGetMethods()
|
||||||
{
|
{
|
||||||
self::assertEquals(0, count(Reflection::getMethods(B::class, true)));
|
self::assertEquals(1, count(Reflection::getMethods(B::class, true)));
|
||||||
self::assertEquals(1, count(Reflection::getMethods(B::class)));
|
self::assertEquals(3, count(Reflection::getMethods(B::class)));
|
||||||
self::assertEquals(1, count(Reflection::getMethods(A::class)));
|
self::assertEquals(2, count(Reflection::getMethods(A::class)));
|
||||||
self::assertEquals(2, count(Reflection::getMethods(C::class, true)));
|
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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -221,6 +225,161 @@ class ReflectionTest extends BaseTestCase
|
|||||||
self::assertFalse(Reflection::usesTrait(D::class, E::class, true));
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPropertyValueOfNotExistingProperty()
|
||||||
|
{
|
||||||
|
self::assertNull(Reflection::getPropertyValue(new D(), 'something'));
|
||||||
|
self::assertNull(Reflection::getPropertyValue(new D(), 'something', true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPropertyValueFromChain()
|
||||||
|
{
|
||||||
|
$f = new F(1000, 'New York', 'USA', 'john.scott');
|
||||||
|
self::assertEquals('John', Reflection::getPropertyValue($f, 'gInstance.firstName'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPropertyValueWithPublicGetter()
|
||||||
|
{
|
||||||
|
$country = 'USA';
|
||||||
|
$f = new F(1000, 'New York', $country, 'john.scott');
|
||||||
|
|
||||||
|
self::assertEquals($country, Reflection::getPropertyValue($f, 'country'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPropertyValueWithProtectedGetter()
|
||||||
|
{
|
||||||
|
$city = 'New York';
|
||||||
|
$f = new F(1000, $city, 'USA', 'john.scott');
|
||||||
|
|
||||||
|
self::assertEquals($city, Reflection::getPropertyValue($f, 'city'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testGetPropertyValueWithPrivateGetter()
|
||||||
|
{
|
||||||
|
$accountBalance = 1000;
|
||||||
|
$f = new F($accountBalance, 'New York', 'USA', 'john.scott');
|
||||||
|
|
||||||
|
self::assertEquals($accountBalance, Reflection::getPropertyValue($f, 'accountBalance'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPropertyValueWithoutGetter()
|
||||||
|
{
|
||||||
|
$username = 'john.scott';
|
||||||
|
$f = new F(1000, 'New York', 'USA', $username);
|
||||||
|
|
||||||
|
self::assertEquals($username, Reflection::getPropertyValue($f, 'username'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPropertyValuesFromEmptySource()
|
||||||
|
{
|
||||||
|
self::assertEquals([], Reflection::getPropertyValues([], 'something'));
|
||||||
|
self::assertEquals([], Reflection::getPropertyValues(new Collection(), 'something'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPropertyValuesOfNotExistingPropertyFromSingleObject()
|
||||||
|
{
|
||||||
|
self::assertEquals([], Reflection::getPropertyValues(new D(), 'something'));
|
||||||
|
self::assertEquals([], Reflection::getPropertyValues(new D(), 'something', true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPropertyValuesOfNotExistingPropertyFromMultipleObjects()
|
||||||
|
{
|
||||||
|
$objects = [
|
||||||
|
new A(),
|
||||||
|
new A(),
|
||||||
|
new A(),
|
||||||
|
new B(),
|
||||||
|
new B(),
|
||||||
|
new C(),
|
||||||
|
new D(),
|
||||||
|
];
|
||||||
|
|
||||||
|
self::assertEquals([], Reflection::getPropertyValues($objects, 'something'));
|
||||||
|
self::assertEquals([], Reflection::getPropertyValues($objects, 'something', true));
|
||||||
|
|
||||||
|
$collection = new Collection($objects);
|
||||||
|
|
||||||
|
self::assertEquals([], Reflection::getPropertyValues($collection, 'something'));
|
||||||
|
self::assertEquals([], Reflection::getPropertyValues($collection, 'something', true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPropertyValuesOfExistingPropertyFromSingleObject()
|
||||||
|
{
|
||||||
|
self::assertEquals(['John'], Reflection::getPropertyValues(new G(), 'firstName'));
|
||||||
|
self::assertEquals(['John'], Reflection::getPropertyValues(new G(), 'firstName', true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPropertyValuesOfExistingPropertyFromMultipleObjects()
|
||||||
|
{
|
||||||
|
$expected = [
|
||||||
|
'New York',
|
||||||
|
'London',
|
||||||
|
'Tokyo',
|
||||||
|
];
|
||||||
|
|
||||||
|
$objects = [
|
||||||
|
new F(1000, 'New York', 'USA', 'john.scott'),
|
||||||
|
new F(2000, 'London', 'GB', 'john.scott'),
|
||||||
|
new F(3000, 'Tokyo', 'Japan', 'john.scott'),
|
||||||
|
];
|
||||||
|
|
||||||
|
self::assertEquals($expected, Reflection::getPropertyValues($objects, 'city'));
|
||||||
|
self::assertEquals($expected, Reflection::getPropertyValues($objects, 'city', true));
|
||||||
|
|
||||||
|
$collection = new Collection($objects);
|
||||||
|
|
||||||
|
self::assertEquals($expected, Reflection::getPropertyValues($collection, 'city'));
|
||||||
|
self::assertEquals($expected, Reflection::getPropertyValues($collection, 'city', true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPropertyValuesFromChainAndSingleObject()
|
||||||
|
{
|
||||||
|
$f = new F(1000, 'New York', 'USA', 'john.scott');
|
||||||
|
|
||||||
|
self::assertEquals(['John'], Reflection::getPropertyValues($f, 'gInstance.firstName'));
|
||||||
|
self::assertEquals(['John'], Reflection::getPropertyValues($f, 'gInstance.firstName', true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPropertyValuesFromChainAndMultipleObjects()
|
||||||
|
{
|
||||||
|
$expected = [
|
||||||
|
'John',
|
||||||
|
'Mary',
|
||||||
|
'Peter',
|
||||||
|
];
|
||||||
|
|
||||||
|
$objects = [
|
||||||
|
new F(1000, 'New York', 'USA', 'john.scott'),
|
||||||
|
new F(2000, 'London', 'GB', 'john.scott', 'Mary', 'Jane'),
|
||||||
|
new F(3000, 'Tokyo', 'Japan', 'john.scott', 'Peter', 'Brown'),
|
||||||
|
];
|
||||||
|
|
||||||
|
self::assertEquals($expected, Reflection::getPropertyValues($objects, 'gInstance.firstName'));
|
||||||
|
self::assertEquals($expected, Reflection::getPropertyValues($objects, 'gInstance.firstName', true));
|
||||||
|
|
||||||
|
$collection = new Collection($objects);
|
||||||
|
|
||||||
|
self::assertEquals($expected, Reflection::getPropertyValues($collection, 'gInstance.firstName'));
|
||||||
|
self::assertEquals($expected, Reflection::getPropertyValues($collection, 'gInstance.firstName', true));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides invalid class and trait
|
* Provides invalid class and trait
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace Meritoo\Common\Utilities;
|
|||||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
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>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
|||||||
use Meritoo\Common\Utilities\Uri;
|
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>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use Meritoo\Common\Utilities\Xml;
|
|||||||
use SimpleXMLElement;
|
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>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
|
|||||||
Reference in New Issue
Block a user