mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70c273750d | ||
|
|
e5e39651f3 | ||
|
|
4683970c87 | ||
|
|
559466c0ce | ||
|
|
bfd69c1098 | ||
|
|
45493b37b0 | ||
|
|
37e7b14ae2 | ||
|
|
a12aaf4bc0 | ||
|
|
f9c480aa19 |
7
.gitignore
vendored
7
.gitignore
vendored
@@ -7,6 +7,7 @@
|
|||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
### Composer
|
### Composer
|
||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
|
/composer.lock
|
||||||
/composer.phar
|
/composer.phar
|
||||||
|
|
||||||
|
|
||||||
@@ -28,6 +29,12 @@
|
|||||||
/.php_cs.cache
|
/.php_cs.cache
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
|
### Build files
|
||||||
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
|
/build/
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
### Generated databases
|
### Generated databases
|
||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -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.12",
|
"version": "0.0.14",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Meritoo.pl",
|
"name": "Meritoo.pl",
|
||||||
@@ -17,18 +17,22 @@
|
|||||||
"symfony/http-foundation": "^3.3"
|
"symfony/http-foundation": "^3.3"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^5.7",
|
"friendsofphp/php-cs-fixer": "^2.6",
|
||||||
"squizlabs/php_codesniffer": "^2.9",
|
|
||||||
"phpmd/phpmd": "^2.6",
|
|
||||||
"sebastian/phpcpd": "^3.0",
|
|
||||||
"pdepend/pdepend": "^2.5",
|
"pdepend/pdepend": "^2.5",
|
||||||
"phploc/phploc": "^4.0",
|
"phploc/phploc": "^4.0",
|
||||||
"friendsofphp/php-cs-fixer": "^2.6"
|
"phpmd/phpmd": "^2.6",
|
||||||
|
"phpunit/phpunit": "^5.7",
|
||||||
|
"sebastian/phpcpd": "^3.0",
|
||||||
|
"squizlabs/php_codesniffer": "^2.9"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Meritoo\\Common\\": "src/Meritoo/Common/",
|
"Meritoo\\Common\\": "src/"
|
||||||
"Meritoo\\Common\\Test\\": "tests/Meritoo/Common/Test/"
|
}
|
||||||
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"Meritoo\\Common\\Test\\": "tests/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3494
composer.lock
generated
3494
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -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();
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
{
|
{
|
||||||
@@ -27,9 +27,9 @@ class TooManyChildClassesExceptionTest extends BaseTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array|object|string $parentClass Class that has more than one child class, but it shouldn't. An array
|
* @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.
|
* of objects, strings, object or string.
|
||||||
* @param array $childClasses Child classes
|
* @param array $childClasses Child classes
|
||||||
* @param string $expectedMessage Expected exception's message
|
* @param string $expectedMessage Expected exception's message
|
||||||
*
|
*
|
||||||
* @dataProvider provideParentAndChildClasses
|
* @dataProvider provideParentAndChildClasses
|
||||||
@@ -25,7 +25,7 @@ class ArraysTest extends BaseTestCase
|
|||||||
private $complexArray;
|
private $complexArray;
|
||||||
private $superComplexArray;
|
private $superComplexArray;
|
||||||
|
|
||||||
public function verifyConstructor()
|
public function testConstructor()
|
||||||
{
|
{
|
||||||
static::assertHasNoConstructor(Arrays::class);
|
static::assertHasNoConstructor(Arrays::class);
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ use Meritoo\Common\Utilities\Bundle;
|
|||||||
*/
|
*/
|
||||||
class BundleTest extends BaseTestCase
|
class BundleTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function verifyConstructor()
|
public function testConstructor()
|
||||||
{
|
{
|
||||||
static::assertHasNoConstructor(Bundle::class);
|
static::assertHasNoConstructor(Bundle::class);
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ class ComposerTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
private $composerJsonPath;
|
private $composerJsonPath;
|
||||||
|
|
||||||
public function verifyConstructor()
|
public function testConstructor()
|
||||||
{
|
{
|
||||||
static::assertHasNoConstructor(Composer::class);
|
static::assertHasNoConstructor(Composer::class);
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ use Meritoo\Common\Utilities\Date;
|
|||||||
*/
|
*/
|
||||||
class DateTest extends BaseTestCase
|
class DateTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function verifyConstructor()
|
public function testConstructor()
|
||||||
{
|
{
|
||||||
static::assertHasNoConstructor(Date::class);
|
static::assertHasNoConstructor(Date::class);
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ use Meritoo\Common\Utilities\GeneratorUtility;
|
|||||||
*/
|
*/
|
||||||
class GeneratorUtilityTest extends BaseTestCase
|
class GeneratorUtilityTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function verifyConstructor()
|
public function testConstructor()
|
||||||
{
|
{
|
||||||
static::assertHasNoConstructor(GeneratorUtility::class);
|
static::assertHasNoConstructor(GeneratorUtility::class);
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@ use Meritoo\Common\Utilities\Locale;
|
|||||||
*/
|
*/
|
||||||
class LocaleTest extends BaseTestCase
|
class LocaleTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function verifyConstructor()
|
public function testConstructor()
|
||||||
{
|
{
|
||||||
static::assertHasNoConstructor(Locale::class);
|
static::assertHasNoConstructor(Locale::class);
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@ use Meritoo\Common\Utilities\MimeTypes;
|
|||||||
*/
|
*/
|
||||||
class MimeTypesTest extends BaseTestCase
|
class MimeTypesTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function verifyConstructor()
|
public function testConstructor()
|
||||||
{
|
{
|
||||||
static::assertHasNoConstructor(MimeTypes::class);
|
static::assertHasNoConstructor(MimeTypes::class);
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ class MiscellaneousTest extends BaseTestCase
|
|||||||
private $stringCommaSeparated;
|
private $stringCommaSeparated;
|
||||||
private $stringDotSeparated;
|
private $stringDotSeparated;
|
||||||
|
|
||||||
public function verifyConstructor()
|
public function testConstructor()
|
||||||
{
|
{
|
||||||
static::assertHasNoConstructor(Miscellaneous::class);
|
static::assertHasNoConstructor(Miscellaneous::class);
|
||||||
}
|
}
|
||||||
@@ -159,8 +159,8 @@ class MiscellaneousTest extends BaseTestCase
|
|||||||
$expected = "int(123)\n";
|
$expected = "int(123)\n";
|
||||||
|
|
||||||
if ($xdebugLoaded) {
|
if ($xdebugLoaded) {
|
||||||
$libraryPath = realpath(sprintf('%s%s', dirname(__FILE__), '/../../../../..'));
|
$libraryPath = realpath(sprintf('%s%s', dirname(__FILE__), '/../..'));
|
||||||
$filePath = sprintf('%s%s', $libraryPath, '/src/Meritoo/Common/Utilities/Miscellaneous.php:');
|
$filePath = sprintf('%s%s', $libraryPath, '/src/Utilities/Miscellaneous.php:');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attention. I have to use "\d+" at the end of $filePath, because number of line may be different if new
|
* Attention. I have to use "\d+" at the end of $filePath, because number of line may be different if new
|
||||||
54
tests/Utilities/Reflection/F.php
Normal file
54
tests/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/Utilities/Reflection/G.php
Normal file
38
tests/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,6 +20,8 @@ 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;
|
use ReflectionProperty;
|
||||||
|
|
||||||
@@ -30,7 +33,7 @@ use ReflectionProperty;
|
|||||||
*/
|
*/
|
||||||
class ReflectionTest extends BaseTestCase
|
class ReflectionTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function verifyConstructor()
|
public function testConstructor()
|
||||||
{
|
{
|
||||||
static::assertHasNoConstructor(Reflection::class);
|
static::assertHasNoConstructor(Reflection::class);
|
||||||
}
|
}
|
||||||
@@ -239,6 +242,143 @@ class ReflectionTest extends BaseTestCase
|
|||||||
self::assertCount(2, Reflection::getProperties(B::class, null, true));
|
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
|
||||||
*
|
*
|
||||||
@@ -21,7 +21,7 @@ class RegexTest extends BaseTestCase
|
|||||||
private $simpleText;
|
private $simpleText;
|
||||||
private $camelCaseText;
|
private $camelCaseText;
|
||||||
|
|
||||||
public function verifyConstructor()
|
public function testConstructor()
|
||||||
{
|
{
|
||||||
static::assertHasNoConstructor(Regex::class);
|
static::assertHasNoConstructor(Regex::class);
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ use Meritoo\Common\Utilities\Uri;
|
|||||||
*/
|
*/
|
||||||
class UriTest extends BaseTestCase
|
class UriTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function verifyConstructor()
|
public function testConstructor()
|
||||||
{
|
{
|
||||||
static::assertHasNoConstructor(Uri::class);
|
static::assertHasNoConstructor(Uri::class);
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ class XmlTest extends BaseTestCase
|
|||||||
private $simpleXml;
|
private $simpleXml;
|
||||||
private $advancedXml;
|
private $advancedXml;
|
||||||
|
|
||||||
public function verifyConstructor()
|
public function testConstructor()
|
||||||
{
|
{
|
||||||
static::assertHasNoConstructor(Xml::class);
|
static::assertHasNoConstructor(Xml::class);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user