mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 17:41:50 +01:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9dac5bd11c | ||
|
|
12100db058 | ||
|
|
f9ab0a6194 | ||
|
|
b824808cd4 | ||
|
|
71e1eeb81b | ||
|
|
70c273750d | ||
|
|
e5e39651f3 | ||
|
|
4683970c87 | ||
|
|
559466c0ce | ||
|
|
bfd69c1098 | ||
|
|
45493b37b0 | ||
|
|
37e7b14ae2 | ||
|
|
a12aaf4bc0 | ||
|
|
f9c480aa19 |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
54
.docker/config/Dockerfile
Normal file
54
.docker/config/Dockerfile
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
FROM php:5.6-cli
|
||||||
|
|
||||||
|
#
|
||||||
|
# Tools & libraries
|
||||||
|
#
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends \
|
||||||
|
git \
|
||||||
|
zip \
|
||||||
|
unzip \
|
||||||
|
zlib1g-dev \
|
||||||
|
libicu-dev \
|
||||||
|
&& apt-get clean \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
|
#
|
||||||
|
# PHP Extensions
|
||||||
|
#
|
||||||
|
RUN docker-php-ext-install \
|
||||||
|
zip \
|
||||||
|
intl \
|
||||||
|
mbstring
|
||||||
|
|
||||||
|
#
|
||||||
|
# PHP configuration:
|
||||||
|
# - timezone
|
||||||
|
#
|
||||||
|
ARG TIMEZONE
|
||||||
|
RUN echo "date.timezone = $TIMEZONE" >> /usr/local/etc/php/php.ini
|
||||||
|
|
||||||
|
#
|
||||||
|
# Xdebug
|
||||||
|
#
|
||||||
|
RUN pecl install xdebug \
|
||||||
|
&& docker-php-ext-enable xdebug
|
||||||
|
COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
|
||||||
|
|
||||||
|
#
|
||||||
|
# Phing
|
||||||
|
#
|
||||||
|
RUN pear channel-discover pear.phing.info \
|
||||||
|
&& pear install [--alldeps] phing/phing
|
||||||
|
|
||||||
|
#
|
||||||
|
# Composer + https://packagist.org/packages/hirak/prestissimo package
|
||||||
|
#
|
||||||
|
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
|
||||||
|
&& php -r "if (hash_file('SHA384', 'composer-setup.php') === \
|
||||||
|
'544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo \
|
||||||
|
'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
|
||||||
|
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
|
||||||
|
&& php -r "unlink('composer-setup.php');" \
|
||||||
|
&& composer global require --no-plugins --no-scripts hirak/prestissimo \
|
||||||
|
&& rm -rf /root/.composer/cache/*
|
||||||
7
.docker/config/xdebug.ini
Normal file
7
.docker/config/xdebug.ini
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[xdebug]
|
||||||
|
zend_extension='xdebug.so'
|
||||||
|
|
||||||
|
xdebug.remote_enable=1
|
||||||
|
xdebug.remote_connect_back=1
|
||||||
|
xdebug.idekey='PHPSTORM'
|
||||||
|
xdebug.remote_port=9001
|
||||||
11
.gitignore
vendored
11
.gitignore
vendored
@@ -7,13 +7,14 @@
|
|||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
### Composer
|
### Composer
|
||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
|
/composer.lock
|
||||||
/composer.phar
|
/composer.phar
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
### Phing
|
### Phing
|
||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
/phing/properties
|
/.phing/properties
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -28,10 +29,16 @@
|
|||||||
/.php_cs.cache
|
/.php_cs.cache
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
|
### Build files
|
||||||
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
|
/.build/
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
### Generated databases
|
### Generated databases
|
||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
/data/tmp
|
/.data/tmp
|
||||||
*.sql
|
*.sql
|
||||||
*.sqlite
|
*.sqlite
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
<project name="Meritoo Package" basedir="." default="build:main" phingVersion="2.14.0">
|
<project name="Meritoo Package" basedir="." default="build:main" phingVersion="2.14.0">
|
||||||
<!-- Properties -->
|
<!-- Properties -->
|
||||||
<if>
|
<if>
|
||||||
<available file="phing/properties" property="custom.properties.available"/>
|
<available file=".phing/properties" property="custom.properties.available"/>
|
||||||
<then>
|
<then>
|
||||||
<property file="phing/properties" />
|
<property file=".phing/properties" />
|
||||||
</then>
|
</then>
|
||||||
<else>
|
<else>
|
||||||
<property file="phing/properties.dist" />
|
<property file=".phing/properties.dist" />
|
||||||
</else>
|
</else>
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ composer.validate = false
|
|||||||
|
|
||||||
# System directories
|
# System directories
|
||||||
#
|
#
|
||||||
dir.data = ${project.basedir}/data
|
dir.data = ${project.basedir}/.data
|
||||||
dir.src = ${project.basedir}/src
|
dir.src = ${project.basedir}/src
|
||||||
dir.tests = ${project.basedir}/tests
|
dir.tests = ${project.basedir}/tests
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ dir.tests = ${project.basedir}/tests
|
|||||||
# Build directories
|
# Build directories
|
||||||
# --------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------
|
||||||
|
|
||||||
dir.build = ${project.basedir}/build
|
dir.build = ${project.basedir}/.build
|
||||||
dir.reports = ${dir.build}/logs
|
dir.reports = ${dir.build}/logs
|
||||||
dir.reports.pdepend = ${dir.reports}/pdepend
|
dir.reports.pdepend = ${dir.reports}/pdepend
|
||||||
dir.reports.coverage = ${dir.reports}/phpunit_coverage
|
dir.reports.coverage = ${dir.reports}/phpunit_coverage
|
||||||
@@ -11,12 +11,12 @@
|
|||||||
|
|
||||||
<!-- Properties -->
|
<!-- Properties -->
|
||||||
<if>
|
<if>
|
||||||
<available file="phing/properties" property="custom.properties.available"/>
|
<available file=".phing/properties" property="custom.properties.available"/>
|
||||||
<then>
|
<then>
|
||||||
<property file="phing/properties" />
|
<property file=".phing/properties" />
|
||||||
</then>
|
</then>
|
||||||
<else>
|
<else>
|
||||||
<property file="phing/properties.dist" />
|
<property file=".phing/properties.dist" />
|
||||||
</else>
|
</else>
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
@@ -13,6 +13,15 @@ $ composer require meritoo/common-library
|
|||||||
|
|
||||||
> How to install Composer: https://getcomposer.org/download
|
> How to install Composer: https://getcomposer.org/download
|
||||||
|
|
||||||
|
## Rebuilding project and tests running
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ docker-compose up -d
|
||||||
|
$ docker-compose exec php-cli phing
|
||||||
|
```
|
||||||
|
|
||||||
|
> What is Docker? https://www.docker.com/what-docker
|
||||||
|
|
||||||
## Static methods
|
## Static methods
|
||||||
|
|
||||||
This package contains a lot of class with static methods, so usage is not so complicated. Just run the static method who would you like to use. Example:
|
This package contains a lot of class with static methods, so usage is not so complicated. Just run the static method who would you like to use. Example:
|
||||||
|
|||||||
12
build.xml
12
build.xml
@@ -2,12 +2,12 @@
|
|||||||
<project name="Meritoo Package" basedir="." default="build:main" phingVersion="2.14.0">
|
<project name="Meritoo Package" basedir="." default="build:main" phingVersion="2.14.0">
|
||||||
<!-- Properties -->
|
<!-- Properties -->
|
||||||
<if>
|
<if>
|
||||||
<available file="phing/properties" property="custom.properties.available"/>
|
<available file=".phing/properties" property="custom.properties.available"/>
|
||||||
<then>
|
<then>
|
||||||
<property file="phing/properties" />
|
<property file=".phing/properties" />
|
||||||
</then>
|
</then>
|
||||||
<else>
|
<else>
|
||||||
<property file="phing/properties.dist" />
|
<property file=".phing/properties.dist" />
|
||||||
</else>
|
</else>
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
@@ -18,12 +18,12 @@
|
|||||||
|
|
||||||
<!-- Build app -->
|
<!-- Build app -->
|
||||||
<target name="build:app" description="Prepares app to build and tests">
|
<target name="build:app" description="Prepares app to build and tests">
|
||||||
<phing phingfile="phing/app.xml" haltonfailure="true" />
|
<phing phingfile=".phing/app.xml" haltonfailure="true" />
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<!-- Build tests -->
|
<!-- Build tests -->
|
||||||
<target name="build:tests" description="Runs all tests, checks and creates docs">
|
<target name="build:tests" description="Runs all tests, checks and creates docs">
|
||||||
<phing phingfile="phing/tests.xml" haltonfailure="true" />
|
<phing phingfile=".phing/tests.xml" haltonfailure="true" />
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Conditional running of tests.
|
Conditional running of tests.
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
<if>
|
<if>
|
||||||
<equals arg1="${env}" arg2="test" />
|
<equals arg1="${env}" arg2="test" />
|
||||||
<then>
|
<then>
|
||||||
<phing phingfile="phing/tests.xml" haltonfailure="true" />
|
<phing phingfile=".phing/tests.xml" haltonfailure="true" />
|
||||||
</then>
|
</then>
|
||||||
<else>
|
<else>
|
||||||
<echo message="[Skipped] Running tests, checks and creating docs, because it's a not 'test' environment..." />
|
<echo message="[Skipped] Running tests, checks and creating docs, because it's a not 'test' environment..." />
|
||||||
|
|||||||
@@ -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.15",
|
||||||
"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
15
docker-compose.yml
Normal file
15
docker-compose.yml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
php-cli:
|
||||||
|
image: meritoo/common-library
|
||||||
|
container_name: meritoo-common-library
|
||||||
|
working_dir: /project
|
||||||
|
entrypoint: php
|
||||||
|
command: -S 0.0.0.0:9999
|
||||||
|
build:
|
||||||
|
context: ./.docker/config
|
||||||
|
args:
|
||||||
|
- TIMEZONE=$TIMEZONE
|
||||||
|
volumes:
|
||||||
|
- .:/project
|
||||||
@@ -30,6 +30,6 @@
|
|||||||
</groups>
|
</groups>
|
||||||
|
|
||||||
<logging>
|
<logging>
|
||||||
<log type="coverage-html" target="./build/logs/phpunit_coverage/html" />
|
<log type="coverage-html" target="./.build/logs/phpunit_coverage/html" />
|
||||||
</logging>
|
</logging>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|||||||
@@ -25,6 +25,13 @@ use ReflectionMethod;
|
|||||||
*/
|
*/
|
||||||
abstract class BaseTestCase extends TestCase
|
abstract class BaseTestCase extends TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Path of directory with data used by test cases
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $testsDataDirPath = '.data/tests';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides an empty value
|
* Provides an empty value
|
||||||
*
|
*
|
||||||
@@ -98,7 +105,7 @@ abstract class BaseTestCase extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns path of file used by tests.
|
* Returns path of file used by tests.
|
||||||
* It should be placed in /data/tests directory of this project.
|
* It should be placed in /.data/tests directory of this project.
|
||||||
*
|
*
|
||||||
* @param string $fileName Name of file
|
* @param string $fileName Name of file
|
||||||
* @param string $directoryPath (optional) Path of directory containing the file
|
* @param string $directoryPath (optional) Path of directory containing the file
|
||||||
@@ -110,7 +117,7 @@ abstract class BaseTestCase extends TestCase
|
|||||||
|
|
||||||
$paths = [
|
$paths = [
|
||||||
$rootPath,
|
$rootPath,
|
||||||
'data/tests',
|
self::$testsDataDirPath,
|
||||||
$directoryPath,
|
$directoryPath,
|
||||||
$fileName,
|
$fileName,
|
||||||
];
|
];
|
||||||
@@ -218,4 +225,14 @@ abstract class BaseTestCase extends TestCase
|
|||||||
|
|
||||||
static::assertNull($constructor);
|
static::assertNull($constructor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets path of directory with data used by test cases
|
||||||
|
*
|
||||||
|
* @param string $testsDataDirPath Path of directory with data used by test cases
|
||||||
|
*/
|
||||||
|
protected static function setTestsDataDirPath($testsDataDirPath)
|
||||||
|
{
|
||||||
|
static::$testsDataDirPath = $testsDataDirPath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
@@ -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();
|
||||||
}
|
}
|
||||||
@@ -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