mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8bcf006e02 | ||
|
|
edc51aeee1 | ||
|
|
6d4e422165 | ||
|
|
6f441bb9ea | ||
|
|
73030d703b | ||
|
|
36ddb326b9 | ||
|
|
452a4ec458 | ||
|
|
325fe6b141 | ||
|
|
a1c26b3812 | ||
|
|
67d93036cf | ||
|
|
9368616dfe | ||
|
|
5ab68d3667 | ||
|
|
4613a63f02 | ||
|
|
9dac5bd11c | ||
|
|
12100db058 | ||
|
|
f9ab0a6194 | ||
|
|
b824808cd4 | ||
|
|
71e1eeb81b | ||
|
|
70c273750d | ||
|
|
e5e39651f3 | ||
|
|
4683970c87 | ||
|
|
559466c0ce | ||
|
|
bfd69c1098 | ||
|
|
45493b37b0 |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
64
.docker/config/Dockerfile
Normal file
64
.docker/config/Dockerfile
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
FROM php:5.5-cli
|
||||||
|
|
||||||
|
#
|
||||||
|
# Tools & libraries
|
||||||
|
#
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends \
|
||||||
|
vim \
|
||||||
|
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:
|
||||||
|
# - default configuration
|
||||||
|
# - timezone
|
||||||
|
#
|
||||||
|
COPY php.ini /usr/local/etc/php/php.ini
|
||||||
|
ARG TIMEZONE
|
||||||
|
RUN echo "\n""date.timezone = $TIMEZONE""\n" >> /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/*
|
||||||
|
|
||||||
|
#
|
||||||
|
# Bash
|
||||||
|
#
|
||||||
|
RUN sed -i 's/^# export/export/g' /root/.bashrc \
|
||||||
|
&& sed -i 's/^# alias/alias/g' /root/.bashrc \
|
||||||
|
&& echo "\n"'export PATH=/project/vendor/bin:$PATH'"\n" >> /root/.bashrc
|
||||||
3
.docker/config/php.ini
Normal file
3
.docker/config/php.ini
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
display_errors = On
|
||||||
|
display_startup_errors = On
|
||||||
|
error_reporting = E_ALL
|
||||||
6
.docker/config/xdebug.ini
Normal file
6
.docker/config/xdebug.ini
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[xdebug]
|
||||||
|
zend_extension=xdebug.so
|
||||||
|
|
||||||
|
xdebug.remote_enable=1
|
||||||
|
xdebug.remote_port=9001
|
||||||
|
xdebug.remote_host=10.254.254.254
|
||||||
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>
|
||||||
|
|
||||||
@@ -28,7 +28,13 @@ assets.installWithSymlink = true
|
|||||||
|
|
||||||
# Clear cache with the "warmup" option
|
# Clear cache with the "warmup" option
|
||||||
#
|
#
|
||||||
cache.clearWithWarmup = true
|
# The cache:clear command should always be called with the --no-warmup option. Warmup should be done via the cache:warmup command.
|
||||||
|
# https://github.com/symfony/symfony/blob/master/UPGRADE-3.3.md#frameworkbundle
|
||||||
|
#
|
||||||
|
# Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
# 2017-06-06
|
||||||
|
#
|
||||||
|
cache.clearWithWarmup = false
|
||||||
|
|
||||||
# --------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------
|
||||||
# Composer
|
# Composer
|
||||||
@@ -59,7 +65,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 +73,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.13",
|
"version": "0.0.18",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Meritoo.pl",
|
"name": "Meritoo.pl",
|
||||||
@@ -11,24 +11,31 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.6.0",
|
"php": ">=5.5.9",
|
||||||
"doctrine/orm": "^2.5",
|
"doctrine/orm": "^2.5",
|
||||||
"gedmo/doctrine-extensions": "^2.4",
|
"gedmo/doctrine-extensions": "^2.4",
|
||||||
"symfony/http-foundation": "^3.3"
|
"symfony/http-foundation": "^3.3"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^5.7",
|
"friendsofphp/php-cs-fixer": "^2.2",
|
||||||
"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": "^2.1",
|
||||||
"friendsofphp/php-cs-fixer": "^2.6"
|
"phpmd/phpmd": "^2.6",
|
||||||
|
"phpunit/phpunit": "^4.8",
|
||||||
|
"sebastian/phpcpd": "^2.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/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"sort-packages": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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>
|
||||||
|
|||||||
23
src/Test/Base/BaseTestCase.php
Normal file
23
src/Test/Base/BaseTestCase.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?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\Base;
|
||||||
|
|
||||||
|
use Meritoo\Common\Traits\Test\Base\BaseTestCaseTrait;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base test case with common methods and data providers
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
abstract class BaseTestCase extends TestCase
|
||||||
|
{
|
||||||
|
use BaseTestCaseTrait;
|
||||||
|
}
|
||||||
22
src/Test/Base/BaseTypeTestCase.php
Normal file
22
src/Test/Base/BaseTypeTestCase.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?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\Base;
|
||||||
|
|
||||||
|
use Meritoo\Common\Traits\Test\Base\BaseTypeTestCaseTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base test case for the type of something
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
abstract class BaseTypeTestCase extends BaseTestCase
|
||||||
|
{
|
||||||
|
use BaseTypeTestCaseTrait;
|
||||||
|
}
|
||||||
@@ -6,25 +6,32 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Meritoo\Common\Test\Base;
|
namespace Meritoo\Common\Traits\Test\Base;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Generator;
|
use Generator;
|
||||||
use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException;
|
use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException;
|
||||||
use Meritoo\Common\Type\OopVisibilityType;
|
use Meritoo\Common\Type\OopVisibilityType;
|
||||||
use Meritoo\Common\Utilities\Miscellaneous;
|
use Meritoo\Common\Utilities\Miscellaneous;
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use ReflectionMethod;
|
use ReflectionMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base test case with common methods and data providers
|
* BaseTestCaseTrait
|
||||||
|
* Created on 2017-11-02
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
abstract class BaseTestCase extends TestCase
|
trait BaseTestCaseTrait
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* 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,19 +105,19 @@ 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
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getFilePathToTests($fileName, $directoryPath = '')
|
public function getFilePathForTesting($fileName, $directoryPath = '')
|
||||||
{
|
{
|
||||||
$rootPath = Miscellaneous::getProjectRootPath();
|
$rootPath = Miscellaneous::getProjectRootPath();
|
||||||
|
|
||||||
$paths = [
|
$paths = [
|
||||||
$rootPath,
|
$rootPath,
|
||||||
'data/tests',
|
self::$testsDataDirPath,
|
||||||
$directoryPath,
|
$directoryPath,
|
||||||
$fileName,
|
$fileName,
|
||||||
];
|
];
|
||||||
@@ -200,7 +207,7 @@ abstract class BaseTestCase extends TestCase
|
|||||||
$reflection = new ReflectionClass($classNamespace);
|
$reflection = new ReflectionClass($classNamespace);
|
||||||
$method = $reflection->getConstructor();
|
$method = $reflection->getConstructor();
|
||||||
|
|
||||||
return static::assertMethodVisibilityAndArguments($classNamespace, $method, $visibilityType, $argumentsCount, $requiredArgumentsCount);
|
static::assertMethodVisibilityAndArguments($classNamespace, $method, $visibilityType, $argumentsCount, $requiredArgumentsCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,23 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Meritoo\Common\Test\Base;
|
/**
|
||||||
|
* (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\Traits\Test\Base;
|
||||||
|
|
||||||
use Generator;
|
use Generator;
|
||||||
use Meritoo\Common\Type\Base\BaseType;
|
use Meritoo\Common\Type\Base\BaseType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base test case for the type of something
|
* Trait for the base test case for the type of something
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
abstract class BaseTypeTestCase extends BaseTestCase
|
trait BaseTypeTestCaseTrait
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Verifies availability of all types
|
* Verifies availability of all types
|
||||||
@@ -6,9 +6,11 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Meritoo\Common\Utilities;
|
namespace Meritoo\Common\Type;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
use Meritoo\Common\Type\Base\BaseType;
|
||||||
|
use Meritoo\Common\Utilities\Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A date's period.
|
* A date's period.
|
||||||
@@ -17,7 +19,7 @@ use DateTime;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class DatePeriod
|
class DatePeriod extends BaseType
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The period constant: last month
|
* The period constant: last month
|
||||||
@@ -108,17 +110,6 @@ class DatePeriod
|
|||||||
$this->endDate = $endDate;
|
$this->endDate = $endDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns information if given period is correct
|
|
||||||
*
|
|
||||||
* @param int $period The period to verify
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function isCorrectPeriod($period)
|
|
||||||
{
|
|
||||||
return in_array($period, Reflection::getConstants(__CLASS__));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns formatted one of the period's date: start date or end date
|
* Returns formatted one of the period's date: start date or end date
|
||||||
*
|
*
|
||||||
@@ -12,6 +12,7 @@ use DateInterval;
|
|||||||
use DateTime;
|
use DateTime;
|
||||||
use Meritoo\Common\Exception\Date\UnknownDatePartTypeException;
|
use Meritoo\Common\Exception\Date\UnknownDatePartTypeException;
|
||||||
use Meritoo\Common\Type\DatePartType;
|
use Meritoo\Common\Type\DatePartType;
|
||||||
|
use Meritoo\Common\Type\DatePeriod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful date methods
|
* Useful date methods
|
||||||
@@ -66,97 +67,105 @@ class Date
|
|||||||
* The dates are returned in an array with indexes 'start' and 'end'.
|
* The dates are returned in an array with indexes 'start' and 'end'.
|
||||||
*
|
*
|
||||||
* @param int $period The period, type of period. One of DatePeriod class constants, e.g. DatePeriod::LAST_WEEK.
|
* @param int $period The period, type of period. One of DatePeriod class constants, e.g. DatePeriod::LAST_WEEK.
|
||||||
* @return DatePeriod
|
* @return null|DatePeriod
|
||||||
*/
|
*/
|
||||||
public static function getDatesForPeriod($period)
|
public static function getDatesForPeriod($period)
|
||||||
{
|
{
|
||||||
$datePeriod = null;
|
/*
|
||||||
|
* Type of period is incorrect?
|
||||||
if (DatePeriod::isCorrectPeriod($period)) {
|
* Nothing to do
|
||||||
$dateStart = null;
|
*/
|
||||||
$dateEnd = null;
|
if (!(new DatePeriod())->isCorrectType($period)) {
|
||||||
|
return null;
|
||||||
switch ($period) {
|
|
||||||
case DatePeriod::LAST_WEEK:
|
|
||||||
$thisWeekStart = new DateTime('this week');
|
|
||||||
|
|
||||||
$dateStart = clone $thisWeekStart;
|
|
||||||
$dateEnd = clone $thisWeekStart;
|
|
||||||
|
|
||||||
$dateStart->sub(new DateInterval('P7D'));
|
|
||||||
$dateEnd->sub(new DateInterval('P1D'));
|
|
||||||
|
|
||||||
break;
|
|
||||||
case DatePeriod::THIS_WEEK:
|
|
||||||
$dateStart = new DateTime('this week');
|
|
||||||
|
|
||||||
$dateEnd = clone $dateStart;
|
|
||||||
$dateEnd->add(new DateInterval('P6D'));
|
|
||||||
|
|
||||||
break;
|
|
||||||
case DatePeriod::NEXT_WEEK:
|
|
||||||
$dateStart = new DateTime('this week');
|
|
||||||
$dateStart->add(new DateInterval('P7D'));
|
|
||||||
|
|
||||||
$dateEnd = clone $dateStart;
|
|
||||||
$dateEnd->add(new DateInterval('P6D'));
|
|
||||||
|
|
||||||
break;
|
|
||||||
case DatePeriod::LAST_MONTH:
|
|
||||||
$dateStart = new DateTime('first day of last month');
|
|
||||||
$dateEnd = new DateTime('last day of last month');
|
|
||||||
|
|
||||||
break;
|
|
||||||
case DatePeriod::THIS_MONTH:
|
|
||||||
$lastMonth = self::getDatesForPeriod(DatePeriod::LAST_MONTH);
|
|
||||||
$nextMonth = self::getDatesForPeriod(DatePeriod::NEXT_MONTH);
|
|
||||||
|
|
||||||
$dateStart = $lastMonth->getEndDate();
|
|
||||||
$dateStart->add(new DateInterval('P1D'));
|
|
||||||
|
|
||||||
$dateEnd = $nextMonth->getStartDate();
|
|
||||||
$dateEnd->sub(new DateInterval('P1D'));
|
|
||||||
|
|
||||||
break;
|
|
||||||
case DatePeriod::NEXT_MONTH:
|
|
||||||
$dateStart = new DateTime('first day of next month');
|
|
||||||
$dateEnd = new DateTime('last day of next month');
|
|
||||||
|
|
||||||
break;
|
|
||||||
case DatePeriod::LAST_YEAR:
|
|
||||||
case DatePeriod::THIS_YEAR:
|
|
||||||
case DatePeriod::NEXT_YEAR:
|
|
||||||
$dateStart = new DateTime();
|
|
||||||
$dateEnd = new DateTime();
|
|
||||||
|
|
||||||
if (DatePeriod::LAST_YEAR == $period || DatePeriod::NEXT_YEAR == $period) {
|
|
||||||
$yearDifference = 1;
|
|
||||||
|
|
||||||
if (DatePeriod::LAST_YEAR == $period) {
|
|
||||||
$yearDifference *= -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$modifyString = sprintf('%s year', $yearDifference);
|
|
||||||
$dateStart->modify($modifyString);
|
|
||||||
$dateEnd->modify($modifyString);
|
|
||||||
}
|
|
||||||
|
|
||||||
$year = $dateStart->format('Y');
|
|
||||||
$dateStart->setDate($year, 1, 1);
|
|
||||||
$dateEnd->setDate($year, 12, 31);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null !== $dateStart && null !== $dateEnd) {
|
|
||||||
$dateStart->setTime(0, 0, 0);
|
|
||||||
$dateEnd->setTime(23, 59, 59);
|
|
||||||
|
|
||||||
$datePeriod = new DatePeriod($dateStart, $dateEnd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $datePeriod;
|
$dateStart = null;
|
||||||
|
$dateEnd = null;
|
||||||
|
|
||||||
|
switch ($period) {
|
||||||
|
case DatePeriod::LAST_WEEK:
|
||||||
|
$thisWeekStart = new DateTime('this week');
|
||||||
|
|
||||||
|
$dateStart = clone $thisWeekStart;
|
||||||
|
$dateEnd = clone $thisWeekStart;
|
||||||
|
|
||||||
|
$dateStart->sub(new DateInterval('P7D'));
|
||||||
|
$dateEnd->sub(new DateInterval('P1D'));
|
||||||
|
|
||||||
|
break;
|
||||||
|
case DatePeriod::THIS_WEEK:
|
||||||
|
$dateStart = new DateTime('this week');
|
||||||
|
|
||||||
|
$dateEnd = clone $dateStart;
|
||||||
|
$dateEnd->add(new DateInterval('P6D'));
|
||||||
|
|
||||||
|
break;
|
||||||
|
case DatePeriod::NEXT_WEEK:
|
||||||
|
$dateStart = new DateTime('this week');
|
||||||
|
$dateStart->add(new DateInterval('P7D'));
|
||||||
|
|
||||||
|
$dateEnd = clone $dateStart;
|
||||||
|
$dateEnd->add(new DateInterval('P6D'));
|
||||||
|
|
||||||
|
break;
|
||||||
|
case DatePeriod::LAST_MONTH:
|
||||||
|
$dateStart = new DateTime('first day of last month');
|
||||||
|
$dateEnd = new DateTime('last day of last month');
|
||||||
|
|
||||||
|
break;
|
||||||
|
case DatePeriod::THIS_MONTH:
|
||||||
|
$lastMonth = self::getDatesForPeriod(DatePeriod::LAST_MONTH);
|
||||||
|
$nextMonth = self::getDatesForPeriod(DatePeriod::NEXT_MONTH);
|
||||||
|
|
||||||
|
$dateStart = $lastMonth->getEndDate();
|
||||||
|
$dateStart->add(new DateInterval('P1D'));
|
||||||
|
|
||||||
|
$dateEnd = $nextMonth->getStartDate();
|
||||||
|
$dateEnd->sub(new DateInterval('P1D'));
|
||||||
|
|
||||||
|
break;
|
||||||
|
case DatePeriod::NEXT_MONTH:
|
||||||
|
$dateStart = new DateTime('first day of next month');
|
||||||
|
$dateEnd = new DateTime('last day of next month');
|
||||||
|
|
||||||
|
break;
|
||||||
|
case DatePeriod::LAST_YEAR:
|
||||||
|
case DatePeriod::THIS_YEAR:
|
||||||
|
case DatePeriod::NEXT_YEAR:
|
||||||
|
$dateStart = new DateTime();
|
||||||
|
$dateEnd = new DateTime();
|
||||||
|
|
||||||
|
if (DatePeriod::LAST_YEAR == $period || DatePeriod::NEXT_YEAR == $period) {
|
||||||
|
$yearDifference = 1;
|
||||||
|
|
||||||
|
if (DatePeriod::LAST_YEAR == $period) {
|
||||||
|
$yearDifference *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$modifyString = sprintf('%s year', $yearDifference);
|
||||||
|
$dateStart->modify($modifyString);
|
||||||
|
$dateEnd->modify($modifyString);
|
||||||
|
}
|
||||||
|
|
||||||
|
$year = $dateStart->format('Y');
|
||||||
|
$dateStart->setDate($year, 1, 1);
|
||||||
|
$dateEnd->setDate($year, 12, 31);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start or end date is unknown?
|
||||||
|
* Nothing to do
|
||||||
|
*/
|
||||||
|
if (null === $dateStart || null === $dateEnd) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dateStart->setTime(0, 0, 0);
|
||||||
|
$dateEnd->setTime(23, 59, 59);
|
||||||
|
|
||||||
|
return new DatePeriod($dateStart, $dateEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,6 +33,10 @@ class QueryBuilderUtility
|
|||||||
{
|
{
|
||||||
$aliases = $queryBuilder->getRootAliases();
|
$aliases = $queryBuilder->getRootAliases();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* No aliases?
|
||||||
|
* Nothing to do
|
||||||
|
*/
|
||||||
if (empty($aliases)) {
|
if (empty($aliases)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -42,7 +46,8 @@ class QueryBuilderUtility
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns alias of given property joined in given query builder
|
* Returns alias of given property joined in given query builder
|
||||||
* If the join does not exist, null is returned.
|
*
|
||||||
|
* If there are no joins or the join does not exist, null is returned.
|
||||||
* It's also information if given property is already joined in given query builder.
|
* It's also information if given property is already joined in given query builder.
|
||||||
*
|
*
|
||||||
* @param QueryBuilder $queryBuilder The query builder to verify
|
* @param QueryBuilder $queryBuilder The query builder to verify
|
||||||
@@ -53,6 +58,10 @@ class QueryBuilderUtility
|
|||||||
{
|
{
|
||||||
$joins = $queryBuilder->getDQLPart('join');
|
$joins = $queryBuilder->getDQLPart('join');
|
||||||
|
|
||||||
|
/*
|
||||||
|
* No joins?
|
||||||
|
* Nothing to do
|
||||||
|
*/
|
||||||
if (empty($joins)) {
|
if (empty($joins)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -99,33 +108,43 @@ class QueryBuilderUtility
|
|||||||
*/
|
*/
|
||||||
public static function setCriteria(QueryBuilder $queryBuilder, array $criteria = [], $alias = '')
|
public static function setCriteria(QueryBuilder $queryBuilder, array $criteria = [], $alias = '')
|
||||||
{
|
{
|
||||||
if (!empty($criteria)) {
|
/*
|
||||||
if (empty($alias)) {
|
* No criteria used in WHERE clause?
|
||||||
$alias = self::getRootAlias($queryBuilder);
|
* Nothing to do
|
||||||
}
|
*/
|
||||||
|
if (empty($criteria)) {
|
||||||
|
return $queryBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($criteria as $column => $value) {
|
/*
|
||||||
$compareOperator = '=';
|
* No alias provided?
|
||||||
|
* Let's use root alias
|
||||||
|
*/
|
||||||
|
if (empty($alias)) {
|
||||||
|
$alias = self::getRootAlias($queryBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
if (is_array($value) && !empty($value)) {
|
foreach ($criteria as $column => $value) {
|
||||||
if (2 == count($value)) {
|
$compareOperator = '=';
|
||||||
$compareOperator = $value[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
$value = $value[0];
|
if (is_array($value) && !empty($value)) {
|
||||||
|
if (2 == count($value)) {
|
||||||
|
$compareOperator = $value[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
$predicate = sprintf('%s.%s %s :%s', $alias, $column, $compareOperator, $column);
|
$value = $value[0];
|
||||||
|
|
||||||
if (null === $value) {
|
|
||||||
$predicate = $queryBuilder->expr()->isNull(sprintf('%s.%s', $alias, $column));
|
|
||||||
unset($criteria[$column]);
|
|
||||||
} else {
|
|
||||||
$queryBuilder->setParameter($column, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
$queryBuilder = $queryBuilder->andWhere($predicate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$predicate = sprintf('%s.%s %s :%s', $alias, $column, $compareOperator, $column);
|
||||||
|
|
||||||
|
if (null === $value) {
|
||||||
|
$predicate = $queryBuilder->expr()->isNull(sprintf('%s.%s', $alias, $column));
|
||||||
|
unset($criteria[$column]);
|
||||||
|
} else {
|
||||||
|
$queryBuilder->setParameter($column, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
$queryBuilder = $queryBuilder->andWhere($predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $queryBuilder;
|
return $queryBuilder;
|
||||||
@@ -143,7 +162,7 @@ class QueryBuilderUtility
|
|||||||
public static function deleteEntities(EntityManager $entityManager, $entities, $flushDeleted = true)
|
public static function deleteEntities(EntityManager $entityManager, $entities, $flushDeleted = true)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* No entities found?
|
* No entities provided?
|
||||||
* Nothing to do
|
* Nothing to do
|
||||||
*/
|
*/
|
||||||
if (empty($entities)) {
|
if (empty($entities)) {
|
||||||
@@ -169,24 +188,30 @@ class QueryBuilderUtility
|
|||||||
* Attention. Existing parameters will be overridden.
|
* Attention. Existing parameters will be overridden.
|
||||||
*
|
*
|
||||||
* @param QueryBuilder $queryBuilder The query builder
|
* @param QueryBuilder $queryBuilder The query builder
|
||||||
* @param array|ArrayCollection $parameters Parameters to add. Collection of instances of
|
* @param array|ArrayCollection $parameters Parameters to add. Collection of Doctrine\ORM\Query\Parameter
|
||||||
* Doctrine\ORM\Query\Parameter class or an array with key-value pairs.
|
* instances or an array with key-value pairs.
|
||||||
* @return QueryBuilder
|
* @return QueryBuilder
|
||||||
*/
|
*/
|
||||||
public static function addParameters(QueryBuilder $queryBuilder, $parameters)
|
public static function addParameters(QueryBuilder $queryBuilder, $parameters)
|
||||||
{
|
{
|
||||||
if (!empty($parameters)) {
|
/*
|
||||||
foreach ($parameters as $key => $parameter) {
|
* No parameters?
|
||||||
$name = $key;
|
* Nothing to do
|
||||||
$value = $parameter;
|
*/
|
||||||
|
if (empty($parameters)) {
|
||||||
|
return $queryBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
if ($parameter instanceof Parameter) {
|
foreach ($parameters as $key => $parameter) {
|
||||||
$name = $parameter->getName();
|
$name = $key;
|
||||||
$value = $parameter->getValue();
|
$value = $parameter;
|
||||||
}
|
|
||||||
|
|
||||||
$queryBuilder->setParameter($name, $value);
|
if ($parameter instanceof Parameter) {
|
||||||
|
$name = $parameter->getName();
|
||||||
|
$value = $parameter->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$queryBuilder->setParameter($name, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $queryBuilder;
|
return $queryBuilder;
|
||||||
@@ -74,8 +74,8 @@ class Reflection
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns maximum constant from all constants of given class / object.
|
* Returns maximum integer value of constant of given class / object.
|
||||||
* Values of constants should be integers.
|
* Constants whose values are integers are considered only.
|
||||||
*
|
*
|
||||||
* @param object|string $class The object or name of object's class
|
* @param object|string $class The object or name of object's class
|
||||||
* @return int|null
|
* @return int|null
|
||||||
@@ -33,7 +33,7 @@ class UnknownTypeExceptionTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testTheException()
|
public function testTheException()
|
||||||
{
|
{
|
||||||
$this->expectException(UnknownTestTypeException::class);
|
$this->setExpectedException(UnknownTestTypeException::class);
|
||||||
self::assertEmpty((new TestService())->getTranslatedType('test_3'));
|
self::assertEmpty((new TestService())->getTranslatedType('test_3'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
176
tests/Test/Base/BaseTestCaseTest.php
Normal file
176
tests/Test/Base/BaseTestCaseTest.php
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
<?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\Test\Base;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use Generator;
|
||||||
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
|
use Meritoo\Common\Type\OopVisibilityType;
|
||||||
|
use Meritoo\Common\Utilities\GeneratorUtility;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test case of the base test case with common methods and data providers
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
class BaseTestCaseTest extends BaseTestCase
|
||||||
|
{
|
||||||
|
public function testConstructor()
|
||||||
|
{
|
||||||
|
static::assertConstructorVisibilityAndArguments(BaseTestCase::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testProvideEmptyValue()
|
||||||
|
{
|
||||||
|
$elements = [
|
||||||
|
[''],
|
||||||
|
[' '],
|
||||||
|
[null],
|
||||||
|
[0],
|
||||||
|
[false],
|
||||||
|
[[]],
|
||||||
|
];
|
||||||
|
|
||||||
|
$generator = (new SimpleTestCase())->provideEmptyValue();
|
||||||
|
self::assertEquals($elements, GeneratorUtility::getGeneratorElements($generator));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testProvideBooleanValue()
|
||||||
|
{
|
||||||
|
$elements = [
|
||||||
|
[false],
|
||||||
|
[true],
|
||||||
|
];
|
||||||
|
|
||||||
|
$generator = (new SimpleTestCase())->provideBooleanValue();
|
||||||
|
self::assertEquals($elements, GeneratorUtility::getGeneratorElements($generator));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testProvideDateTimeInstance()
|
||||||
|
{
|
||||||
|
$dateFormat = 'Y-m-d H:i';
|
||||||
|
|
||||||
|
$expectedElements = [
|
||||||
|
[new DateTime()],
|
||||||
|
[new DateTime('yesterday')],
|
||||||
|
[new DateTime('now')],
|
||||||
|
[new DateTime('tomorrow')],
|
||||||
|
];
|
||||||
|
|
||||||
|
$generator = (new SimpleTestCase())->provideDateTimeInstance();
|
||||||
|
$generatedElements = GeneratorUtility::getGeneratorElements($generator);
|
||||||
|
|
||||||
|
/* @var DateTime $instance1 */
|
||||||
|
$instance1 = $generatedElements[0][0];
|
||||||
|
|
||||||
|
/* @var DateTime $instance2 */
|
||||||
|
$instance2 = $generatedElements[1][0];
|
||||||
|
|
||||||
|
/* @var DateTime $instance3 */
|
||||||
|
$instance3 = $generatedElements[2][0];
|
||||||
|
|
||||||
|
/* @var DateTime $instance4 */
|
||||||
|
$instance4 = $generatedElements[3][0];
|
||||||
|
|
||||||
|
self::assertCount(count($expectedElements), $generatedElements);
|
||||||
|
self::assertEquals($instance1->format($dateFormat), (new DateTime())->format($dateFormat));
|
||||||
|
self::assertEquals($instance2->format($dateFormat), (new DateTime('yesterday'))->format($dateFormat));
|
||||||
|
self::assertEquals($instance3->format($dateFormat), (new DateTime('now'))->format($dateFormat));
|
||||||
|
self::assertEquals($instance4->format($dateFormat), (new DateTime('tomorrow'))->format($dateFormat));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testProvideDateTimeRelativeFormat()
|
||||||
|
{
|
||||||
|
$elements = [
|
||||||
|
['now'],
|
||||||
|
['yesterday'],
|
||||||
|
['tomorrow'],
|
||||||
|
['back of 10'],
|
||||||
|
['front of 10'],
|
||||||
|
['last day of February'],
|
||||||
|
['first day of next month'],
|
||||||
|
['last day of previous month'],
|
||||||
|
['last day of next month'],
|
||||||
|
['Y-m-d'],
|
||||||
|
['Y-m-d 10:00'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$generator = (new SimpleTestCase())->provideDateTimeRelativeFormat();
|
||||||
|
self::assertEquals($elements, GeneratorUtility::getGeneratorElements($generator));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testProvideNotExistingFilePath()
|
||||||
|
{
|
||||||
|
$elements = [
|
||||||
|
['lets-test.doc'],
|
||||||
|
['lorem/ipsum.jpg'],
|
||||||
|
['surprise/me/one/more/time.txt'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$generator = (new SimpleTestCase())->provideNotExistingFilePath();
|
||||||
|
self::assertEquals($elements, GeneratorUtility::getGeneratorElements($generator));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $fileName Name of file
|
||||||
|
* @param string $directoryPath Path of directory containing the file
|
||||||
|
*
|
||||||
|
* @dataProvider provideFileNameAndDirectoryPath
|
||||||
|
*/
|
||||||
|
public function testGetFilePathForTesting($fileName, $directoryPath)
|
||||||
|
{
|
||||||
|
$path = (new SimpleTestCase())->getFilePathForTesting($fileName, $directoryPath);
|
||||||
|
|
||||||
|
if (!empty($directoryPath)) {
|
||||||
|
$directoryPath .= '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
$expectedContains = sprintf('/.data/tests/%s%s', $directoryPath, $fileName);
|
||||||
|
static::assertContains($expectedContains, $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides name of file and path of directory containing the file
|
||||||
|
*
|
||||||
|
* @return Generator
|
||||||
|
*/
|
||||||
|
public function provideFileNameAndDirectoryPath()
|
||||||
|
{
|
||||||
|
yield[
|
||||||
|
'abc.jpg',
|
||||||
|
'',
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
'abc.def.jpg',
|
||||||
|
'',
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
'abc.jpg',
|
||||||
|
'def',
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
'abc.def.jpg',
|
||||||
|
'def',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple test case
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
class SimpleTestCase extends BaseTestCase
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -9,8 +9,8 @@
|
|||||||
namespace Meritoo\Common\Test\Type\Base;
|
namespace Meritoo\Common\Test\Type\Base;
|
||||||
|
|
||||||
use Generator;
|
use Generator;
|
||||||
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
use Meritoo\Common\Type\Base\BaseType;
|
use Meritoo\Common\Type\Base\BaseType;
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test case of the base / abstract type of something
|
* Test case of the base / abstract type of something
|
||||||
@@ -18,8 +18,13 @@ use PHPUnit\Framework\TestCase;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class BaseTypeTest extends TestCase
|
class BaseTypeTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
|
public function testConstructor()
|
||||||
|
{
|
||||||
|
static::assertHasNoConstructor(BaseType::class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param BaseType $type Type of something
|
* @param BaseType $type Type of something
|
||||||
* @param array $expectedTypes Expected concrete types of given instance of type
|
* @param array $expectedTypes Expected concrete types of given instance of type
|
||||||
@@ -6,13 +6,13 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Meritoo\Common\Test\Utilities;
|
namespace Meritoo\Common\Test\Type;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Generator;
|
use Generator;
|
||||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
use Meritoo\Common\Test\Base\BaseTypeTestCase;
|
||||||
|
use Meritoo\Common\Type\DatePeriod;
|
||||||
use Meritoo\Common\Type\OopVisibilityType;
|
use Meritoo\Common\Type\OopVisibilityType;
|
||||||
use Meritoo\Common\Utilities\DatePeriod;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test case of date's period
|
* Test case of date's period
|
||||||
@@ -20,7 +20,7 @@ use Meritoo\Common\Utilities\DatePeriod;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class DatePeriodTest extends BaseTestCase
|
class DatePeriodTest extends BaseTypeTestCase
|
||||||
{
|
{
|
||||||
public function testConstructorVisibilityAndArguments()
|
public function testConstructorVisibilityAndArguments()
|
||||||
{
|
{
|
||||||
@@ -58,33 +58,6 @@ class DatePeriodTest extends BaseTestCase
|
|||||||
self::assertEquals($endDate, $period->getEndDate());
|
self::assertEquals($endDate, $period->getEndDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $period Empty value, e.g. ""
|
|
||||||
* @dataProvider provideEmptyValue
|
|
||||||
*/
|
|
||||||
public function testIsCorrectPeriodEmptyPeriod($period)
|
|
||||||
{
|
|
||||||
self::assertFalse(DatePeriod::isCorrectPeriod($period));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $period Incorrect period to verify
|
|
||||||
* @dataProvider provideIncorrectPeriod
|
|
||||||
*/
|
|
||||||
public function testIsCorrectPeriodIncorrectPeriod($period)
|
|
||||||
{
|
|
||||||
self::assertFalse(DatePeriod::isCorrectPeriod($period));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $period The period to verify
|
|
||||||
* @dataProvider providePeriod
|
|
||||||
*/
|
|
||||||
public function testIsCorrectPeriod($period)
|
|
||||||
{
|
|
||||||
self::assertTrue(DatePeriod::isCorrectPeriod($period));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param DatePeriod $period The date period to verify
|
* @param DatePeriod $period The date period to verify
|
||||||
* @param string $format Format used to format the date
|
* @param string $format Format used to format the date
|
||||||
@@ -142,36 +115,6 @@ class DatePeriodTest extends BaseTestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides incorrect period
|
|
||||||
*
|
|
||||||
* @return Generator
|
|
||||||
*/
|
|
||||||
public function provideIncorrectPeriod()
|
|
||||||
{
|
|
||||||
yield[-1];
|
|
||||||
yield[0];
|
|
||||||
yield[10];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides period to verify
|
|
||||||
*
|
|
||||||
* @return Generator
|
|
||||||
*/
|
|
||||||
public function providePeriod()
|
|
||||||
{
|
|
||||||
yield[DatePeriod::LAST_WEEK];
|
|
||||||
yield[DatePeriod::THIS_WEEK];
|
|
||||||
yield[DatePeriod::NEXT_WEEK];
|
|
||||||
yield[DatePeriod::LAST_MONTH];
|
|
||||||
yield[DatePeriod::THIS_MONTH];
|
|
||||||
yield[DatePeriod::NEXT_MONTH];
|
|
||||||
yield[DatePeriod::LAST_YEAR];
|
|
||||||
yield[DatePeriod::THIS_YEAR];
|
|
||||||
yield[DatePeriod::NEXT_YEAR];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides period and incorrect format of date to verify
|
* Provides period and incorrect format of date to verify
|
||||||
*
|
*
|
||||||
@@ -270,4 +213,68 @@ class DatePeriodTest extends BaseTestCase
|
|||||||
'2002-02-02 00:00',
|
'2002-02-02 00:00',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all expected types of the tested type
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getAllExpectedTypes()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'LAST_MONTH' => DatePeriod::LAST_MONTH,
|
||||||
|
'LAST_WEEK' => DatePeriod::LAST_WEEK,
|
||||||
|
'LAST_YEAR' => DatePeriod::LAST_YEAR,
|
||||||
|
'NEXT_MONTH' => DatePeriod::NEXT_MONTH,
|
||||||
|
'NEXT_WEEK' => DatePeriod::NEXT_WEEK,
|
||||||
|
'NEXT_YEAR' => DatePeriod::NEXT_YEAR,
|
||||||
|
'THIS_MONTH' => DatePeriod::THIS_MONTH,
|
||||||
|
'THIS_WEEK' => DatePeriod::THIS_WEEK,
|
||||||
|
'THIS_YEAR' => DatePeriod::THIS_YEAR,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function getTestedTypeInstance()
|
||||||
|
{
|
||||||
|
return new DatePeriod();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function provideTypeToVerify()
|
||||||
|
{
|
||||||
|
yield[
|
||||||
|
'',
|
||||||
|
false,
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
-1,
|
||||||
|
false,
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
DatePeriod::LAST_MONTH,
|
||||||
|
true,
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
DatePeriod::NEXT_WEEK,
|
||||||
|
true,
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
DatePeriod::THIS_YEAR,
|
||||||
|
true,
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
@@ -88,6 +88,6 @@ class ComposerTest extends BaseTestCase
|
|||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->composerJsonPath = $this->getFilePathToTests(Composer::FILE_NAME_MAIN);
|
$this->composerJsonPath = $this->getFilePathForTesting(Composer::FILE_NAME_MAIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,6 +13,7 @@ use DateTime;
|
|||||||
use Generator;
|
use Generator;
|
||||||
use Meritoo\Common\Exception\Date\UnknownDatePartTypeException;
|
use Meritoo\Common\Exception\Date\UnknownDatePartTypeException;
|
||||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
|
use Meritoo\Common\Type\DatePeriod;
|
||||||
use Meritoo\Common\Utilities\Date;
|
use Meritoo\Common\Utilities\Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,7 +24,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);
|
||||||
}
|
}
|
||||||
@@ -223,7 +224,7 @@ class DateTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetDayOfWeekIncorrectValues($year, $month, $day)
|
public function testGetDayOfWeekIncorrectValues($year, $month, $day)
|
||||||
{
|
{
|
||||||
$this->expectException(UnknownDatePartTypeException::class);
|
$this->setExpectedException(UnknownDatePartTypeException::class);
|
||||||
self::assertEmpty(Date::getDayOfWeek($year, $month, $day));
|
self::assertEmpty(Date::getDayOfWeek($year, $month, $day));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -506,6 +507,35 @@ class DateTest extends BaseTestCase
|
|||||||
self::assertTrue($randomDate >= $intervalMinDate && $randomDate <= $intervalMaxDate);
|
self::assertTrue($randomDate >= $intervalMinDate && $randomDate <= $intervalMaxDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $period Empty value, e.g. ""
|
||||||
|
* @dataProvider provideEmptyValue
|
||||||
|
*/
|
||||||
|
public function testGetDatesForPeriodUsingEmptyPeriod($period)
|
||||||
|
{
|
||||||
|
self::assertNull(Date::getDatesForPeriod($period));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $period Incorrect period to verify
|
||||||
|
* @dataProvider provideIncorrectPeriod
|
||||||
|
*/
|
||||||
|
public function testGetDatesForPeriodUsingIncorrectPeriod($period)
|
||||||
|
{
|
||||||
|
self::assertNull(Date::getDatesForPeriod($period));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $period The period, type of period. One of DatePeriod class constants, e.g. DatePeriod::LAST_WEEK.
|
||||||
|
* @param DatePeriod $expected Expected start and end date for given period
|
||||||
|
*
|
||||||
|
* @dataProvider provideCorrectPeriod
|
||||||
|
*/
|
||||||
|
public function testGetDatesForPeriod($period, DatePeriod $expected)
|
||||||
|
{
|
||||||
|
self::assertEquals($expected, Date::getDatesForPeriod($period));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides incorrect invalidCount of DateTime
|
* Provides incorrect invalidCount of DateTime
|
||||||
*
|
*
|
||||||
@@ -758,4 +788,112 @@ class DateTest extends BaseTestCase
|
|||||||
50,
|
50,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides incorrect period
|
||||||
|
*
|
||||||
|
* @return Generator
|
||||||
|
*/
|
||||||
|
public function provideIncorrectPeriod()
|
||||||
|
{
|
||||||
|
yield[-1];
|
||||||
|
yield[0];
|
||||||
|
yield[10];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides correct period
|
||||||
|
*
|
||||||
|
* @return Generator
|
||||||
|
*/
|
||||||
|
public function provideCorrectPeriod()
|
||||||
|
{
|
||||||
|
yield[
|
||||||
|
DatePeriod::LAST_WEEK,
|
||||||
|
new DatePeriod(
|
||||||
|
(new DateTime('this week'))->sub(new DateInterval('P7D'))->setTime(0, 0, 0),
|
||||||
|
(new DateTime('this week'))->sub(new DateInterval('P1D'))->setTime(23, 59, 59)
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
DatePeriod::THIS_WEEK,
|
||||||
|
new DatePeriod(
|
||||||
|
(new DateTime('this week'))->setTime(0, 0, 0),
|
||||||
|
(new DateTime('this week'))->add(new DateInterval('P6D'))->setTime(23, 59, 59)
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
DatePeriod::NEXT_WEEK,
|
||||||
|
new DatePeriod(
|
||||||
|
(new DateTime('this week'))->add(new DateInterval('P7D'))->setTime(0, 0, 0),
|
||||||
|
(new DateTime('this week'))->add(new DateInterval('P7D'))->add(new DateInterval('P6D'))->setTime(23, 59, 59)
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
DatePeriod::LAST_MONTH,
|
||||||
|
new DatePeriod(
|
||||||
|
(new DateTime('first day of last month'))->setTime(0, 0, 0),
|
||||||
|
(new DateTime('last day of last month'))->setTime(23, 59, 59)
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
DatePeriod::THIS_MONTH,
|
||||||
|
new DatePeriod(
|
||||||
|
Date::getDatesForPeriod(DatePeriod::LAST_MONTH)
|
||||||
|
->getEndDate()
|
||||||
|
->add(new DateInterval('P1D'))
|
||||||
|
->setTime(0, 0, 0),
|
||||||
|
Date::getDatesForPeriod(DatePeriod::NEXT_MONTH)
|
||||||
|
->getStartDate()
|
||||||
|
->sub(new DateInterval('P1D'))
|
||||||
|
->setTime(23, 59, 59)
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
DatePeriod::NEXT_MONTH,
|
||||||
|
new DatePeriod(
|
||||||
|
(new DateTime('first day of next month'))->setTime(0, 0, 0),
|
||||||
|
(new DateTime('last day of next month'))->setTime(23, 59, 59)
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
$lastYearStart = (new DateTime())->modify('-1 year');
|
||||||
|
$lastYearEnd = (new DateTime())->modify('-1 year');
|
||||||
|
$year = $lastYearStart->format('Y');
|
||||||
|
|
||||||
|
yield[
|
||||||
|
DatePeriod::LAST_YEAR,
|
||||||
|
new DatePeriod(
|
||||||
|
$lastYearStart->setDate($year, 1, 1)->setTime(0, 0, 0),
|
||||||
|
$lastYearEnd->setDate($year, 12, 31)->setTime(23, 59, 59)
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
$year = (new DateTime())->format('Y');
|
||||||
|
|
||||||
|
yield[
|
||||||
|
DatePeriod::THIS_YEAR,
|
||||||
|
new DatePeriod(
|
||||||
|
(new DateTime())->setDate($year, 1, 1)->setTime(0, 0, 0),
|
||||||
|
(new DateTime())->setDate($year, 12, 31)->setTime(23, 59, 59)
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
$nextYearStart = (new DateTime())->modify('1 year');
|
||||||
|
$nextYearEnd = (new DateTime())->modify('1 year');
|
||||||
|
$year = $nextYearStart->format('Y');
|
||||||
|
|
||||||
|
yield[
|
||||||
|
DatePeriod::NEXT_YEAR,
|
||||||
|
new DatePeriod(
|
||||||
|
$nextYearStart->setDate($year, 1, 1)->setTime(0, 0, 0),
|
||||||
|
$nextYearEnd->setDate($year, 12, 31)->setTime(23, 59, 59)
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
@@ -447,12 +447,12 @@ class MimeTypesTest extends BaseTestCase
|
|||||||
public function provideFilePathToGetMimeTypeOfRealFile()
|
public function provideFilePathToGetMimeTypeOfRealFile()
|
||||||
{
|
{
|
||||||
yield[
|
yield[
|
||||||
$this->getFilePathToTests('minion.jpg'),
|
$this->getFilePathForTesting('minion.jpg'),
|
||||||
'image/jpeg',
|
'image/jpeg',
|
||||||
];
|
];
|
||||||
|
|
||||||
yield[
|
yield[
|
||||||
$this->getFilePathToTests('lorem-ipsum.txt'),
|
$this->getFilePathForTesting('lorem-ipsum.txt'),
|
||||||
'text/plain',
|
'text/plain',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -465,12 +465,12 @@ class MimeTypesTest extends BaseTestCase
|
|||||||
public function provideExistingFilePathToCheckIsImagePath()
|
public function provideExistingFilePathToCheckIsImagePath()
|
||||||
{
|
{
|
||||||
yield[
|
yield[
|
||||||
$this->getFilePathToTests('minion.jpg'),
|
$this->getFilePathForTesting('minion.jpg'),
|
||||||
true,
|
true,
|
||||||
];
|
];
|
||||||
|
|
||||||
yield[
|
yield[
|
||||||
$this->getFilePathToTests('lorem-ipsum.txt'),
|
$this->getFilePathForTesting('lorem-ipsum.txt'),
|
||||||
false,
|
false,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
@@ -663,7 +663,8 @@ class MiscellaneousTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testGetInvertedColorWithIncorrectLength()
|
public function testGetInvertedColorWithIncorrectLength()
|
||||||
{
|
{
|
||||||
$this->expectException(IncorrectColorHexLengthException::class);
|
$this->setExpectedException(IncorrectColorHexLengthException::class);
|
||||||
|
|
||||||
Miscellaneous::getInvertedColor(null);
|
Miscellaneous::getInvertedColor(null);
|
||||||
Miscellaneous::getInvertedColor('');
|
Miscellaneous::getInvertedColor('');
|
||||||
Miscellaneous::getInvertedColor(1);
|
Miscellaneous::getInvertedColor(1);
|
||||||
@@ -676,7 +677,8 @@ class MiscellaneousTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testGetInvertedColorWithInvalidValue()
|
public function testGetInvertedColorWithInvalidValue()
|
||||||
{
|
{
|
||||||
$this->expectException(InvalidColorHexValueException::class);
|
$this->setExpectedException(InvalidColorHexValueException::class);
|
||||||
|
|
||||||
Miscellaneous::getInvertedColor('0011zz');
|
Miscellaneous::getInvertedColor('0011zz');
|
||||||
Miscellaneous::getInvertedColor('001#zz');
|
Miscellaneous::getInvertedColor('001#zz');
|
||||||
Miscellaneous::getInvertedColor('001!zz');
|
Miscellaneous::getInvertedColor('001!zz');
|
||||||
341
tests/Utilities/QueryBuilderUtilityTest.php
Normal file
341
tests/Utilities/QueryBuilderUtilityTest.php
Normal file
@@ -0,0 +1,341 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Doctrine\ORM\EntityManager;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Doctrine\ORM\Query\Expr;
|
||||||
|
use Doctrine\ORM\Query\Parameter;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Generator;
|
||||||
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
|
use Meritoo\Common\Utilities\QueryBuilderUtility;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test case of the useful methods for query builder (the Doctrine's QueryBuilder class)
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
class QueryBuilderUtilityTest extends BaseTestCase
|
||||||
|
{
|
||||||
|
public function testConstructor()
|
||||||
|
{
|
||||||
|
static::assertHasNoConstructor(QueryBuilderUtility::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param QueryBuilder $queryBuilder The query builder to retrieve root alias
|
||||||
|
* @param null|string $rootAlias Expected root alias of given query builder
|
||||||
|
*
|
||||||
|
* @dataProvider provideQueryBuilderAndRootAlias
|
||||||
|
*/
|
||||||
|
public function testGetRootAlias(QueryBuilder $queryBuilder, $rootAlias)
|
||||||
|
{
|
||||||
|
static::assertSame($rootAlias, QueryBuilderUtility::getRootAlias($queryBuilder));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param QueryBuilder $queryBuilder The query builder to verify
|
||||||
|
* @param string $propertyName Name of property that maybe is joined
|
||||||
|
* @param null|string $propertyAlias Expected alias of given property joined in given query builder
|
||||||
|
*
|
||||||
|
* @dataProvider provideQueryBuilderAndPropertyAlias
|
||||||
|
*/
|
||||||
|
public function testGetJoinedPropertyAlias(QueryBuilder $queryBuilder, $propertyName, $propertyAlias)
|
||||||
|
{
|
||||||
|
static::assertSame($propertyAlias, QueryBuilderUtility::getJoinedPropertyAlias($queryBuilder, $propertyName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetCriteriaWithoutCriteria()
|
||||||
|
{
|
||||||
|
$entityManager = $this->getMock(EntityManagerInterface::class);
|
||||||
|
$queryBuilder = new QueryBuilder($entityManager);
|
||||||
|
$newQueryBuilder = QueryBuilderUtility::setCriteria($queryBuilder);
|
||||||
|
|
||||||
|
static::assertSame($queryBuilder, $newQueryBuilder);
|
||||||
|
static::assertCount(0, $newQueryBuilder->getParameters());
|
||||||
|
static::assertNull($newQueryBuilder->getDQLPart('where'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetCriteriaWithoutAlias()
|
||||||
|
{
|
||||||
|
$criteria = [
|
||||||
|
'lorem' => 11,
|
||||||
|
'ipsum' => 22,
|
||||||
|
];
|
||||||
|
|
||||||
|
$entityManager = $this->getMock(EntityManagerInterface::class);
|
||||||
|
$queryBuilder = new QueryBuilder($entityManager);
|
||||||
|
$newQueryBuilder = QueryBuilderUtility::setCriteria($queryBuilder, $criteria);
|
||||||
|
|
||||||
|
static::assertSame($queryBuilder, $newQueryBuilder);
|
||||||
|
static::assertCount(count($criteria), $newQueryBuilder->getParameters());
|
||||||
|
static::assertNotNull($newQueryBuilder->getDQLPart('where'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param QueryBuilder $queryBuilder The query builder
|
||||||
|
* @param array $criteria The criteria used in WHERE clause
|
||||||
|
*
|
||||||
|
* @dataProvider provideQueryBuilderAndCriteria
|
||||||
|
*/
|
||||||
|
public function testSetCriteria(QueryBuilder $queryBuilder, array $criteria)
|
||||||
|
{
|
||||||
|
$newQueryBuilder = QueryBuilderUtility::setCriteria($queryBuilder, $criteria);
|
||||||
|
$criteriaCount = count($criteria);
|
||||||
|
$nullsCount = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* I have to verify count/amount of NULLs and decrease $criteriaCount, because for null parameter is not added
|
||||||
|
*/
|
||||||
|
array_walk($criteria, function ($value) use (&$nullsCount) {
|
||||||
|
if (null === $value) {
|
||||||
|
++$nullsCount;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
static::assertSame($queryBuilder, $newQueryBuilder);
|
||||||
|
static::assertCount($criteriaCount - $nullsCount, $newQueryBuilder->getParameters());
|
||||||
|
static::assertNotNull($newQueryBuilder->getDQLPart('where'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeleteEntitiesWithoutFlush()
|
||||||
|
{
|
||||||
|
$methods = [
|
||||||
|
'remove',
|
||||||
|
'flush',
|
||||||
|
];
|
||||||
|
|
||||||
|
$entityManager = $this->getMock(EntityManager::class, $methods, [], '', false);
|
||||||
|
$entities1 = [];
|
||||||
|
|
||||||
|
$entities2 = [
|
||||||
|
new \stdClass(),
|
||||||
|
];
|
||||||
|
|
||||||
|
static::assertFalse(QueryBuilderUtility::deleteEntities($entityManager, $entities1, false));
|
||||||
|
static::assertTrue(QueryBuilderUtility::deleteEntities($entityManager, $entities2, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeleteEntities()
|
||||||
|
{
|
||||||
|
$methods = [
|
||||||
|
'remove',
|
||||||
|
'flush',
|
||||||
|
];
|
||||||
|
|
||||||
|
$entityManager = $this->getMock(EntityManager::class, $methods, [], '', false);
|
||||||
|
$entities1 = [];
|
||||||
|
|
||||||
|
$entities2 = [
|
||||||
|
new \stdClass(),
|
||||||
|
];
|
||||||
|
|
||||||
|
static::assertFalse(QueryBuilderUtility::deleteEntities($entityManager, $entities1));
|
||||||
|
static::assertTrue(QueryBuilderUtility::deleteEntities($entityManager, $entities2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param QueryBuilder $queryBuilder The query builder
|
||||||
|
* @param array|ArrayCollection $parameters Parameters to add. Collection of Doctrine\ORM\Query\Parameter
|
||||||
|
* instances or an array with key-value pairs.
|
||||||
|
*
|
||||||
|
* @dataProvider provideQueryBuilderAndParameters
|
||||||
|
*/
|
||||||
|
public function testAddParameters(QueryBuilder $queryBuilder, $parameters)
|
||||||
|
{
|
||||||
|
$newQueryBuilder = QueryBuilderUtility::addParameters($queryBuilder, $parameters);
|
||||||
|
|
||||||
|
static::assertSame($queryBuilder, $newQueryBuilder);
|
||||||
|
static::assertCount(count($parameters), $newQueryBuilder->getParameters());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides query builder to retrieve root alias and expected root alias
|
||||||
|
*
|
||||||
|
* @return Generator
|
||||||
|
*/
|
||||||
|
public function provideQueryBuilderAndRootAlias()
|
||||||
|
{
|
||||||
|
$entityManager = $this->getMock(EntityManagerInterface::class);
|
||||||
|
|
||||||
|
yield[
|
||||||
|
new QueryBuilder($entityManager),
|
||||||
|
null,
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
(new QueryBuilder($entityManager))->from('lorem_ipsum', 'lm'),
|
||||||
|
'lm',
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
(new QueryBuilder($entityManager))
|
||||||
|
->from('lorem', 'l')
|
||||||
|
->leftJoin('l.ipsum', 'i'),
|
||||||
|
'l',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides query builder, name of property and expected alias of given property
|
||||||
|
*
|
||||||
|
* @return Generator
|
||||||
|
*/
|
||||||
|
public function provideQueryBuilderAndPropertyAlias()
|
||||||
|
{
|
||||||
|
$entityManager = $this->getMock(EntityManagerInterface::class);
|
||||||
|
|
||||||
|
yield[
|
||||||
|
new QueryBuilder($entityManager),
|
||||||
|
'',
|
||||||
|
null,
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
new QueryBuilder($entityManager),
|
||||||
|
'lorem',
|
||||||
|
null,
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
(new QueryBuilder($entityManager))->from('lorem_ipsum', 'lm'),
|
||||||
|
'lm',
|
||||||
|
null,
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
(new QueryBuilder($entityManager))
|
||||||
|
->from('lorem', 'l')
|
||||||
|
->leftJoin('l.ipsum', 'i'),
|
||||||
|
'ipsum',
|
||||||
|
'i',
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
(new QueryBuilder($entityManager))
|
||||||
|
->from('lorem', 'l')
|
||||||
|
->leftJoin('l.ipsum', 'i')
|
||||||
|
->innerJoin('i.dolor', 'd'),
|
||||||
|
'ipsum1',
|
||||||
|
null,
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
(new QueryBuilder($entityManager))
|
||||||
|
->from('lorem', 'l')
|
||||||
|
->leftJoin('l.ipsum', 'i')
|
||||||
|
->innerJoin('i.dolor', 'd'),
|
||||||
|
'ipsum',
|
||||||
|
'i',
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
(new QueryBuilder($entityManager))
|
||||||
|
->from('lorem', 'l')
|
||||||
|
->leftJoin('l.ipsum', 'i')
|
||||||
|
->innerJoin('i.dolor', 'd'),
|
||||||
|
'dolor',
|
||||||
|
'd',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides query builder and criteria used in WHERE clause
|
||||||
|
*
|
||||||
|
* @return Generator
|
||||||
|
*/
|
||||||
|
public function provideQueryBuilderAndCriteria()
|
||||||
|
{
|
||||||
|
$entityManager = $this->getMock(EntityManager::class, ['getExpressionBuilder'], [], '', false);
|
||||||
|
|
||||||
|
$entityManager
|
||||||
|
->expects(static::any())
|
||||||
|
->method('getExpressionBuilder')
|
||||||
|
->willReturn(new Expr());
|
||||||
|
|
||||||
|
yield[
|
||||||
|
(new QueryBuilder($entityManager))->from('lorem_ipsum', 'lm'),
|
||||||
|
[
|
||||||
|
'lorem' => 11,
|
||||||
|
'ipsum' => 22,
|
||||||
|
'dolor' => null,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
(new QueryBuilder($entityManager))->from('lorem_ipsum', 'lm'),
|
||||||
|
[
|
||||||
|
'lorem' => [
|
||||||
|
11,
|
||||||
|
'>=',
|
||||||
|
],
|
||||||
|
'ipsum' => [
|
||||||
|
22,
|
||||||
|
'<',
|
||||||
|
],
|
||||||
|
'dolor' => null,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides query builder and parameters to add to given query builder
|
||||||
|
*
|
||||||
|
* @return Generator
|
||||||
|
*/
|
||||||
|
public function provideQueryBuilderAndParameters()
|
||||||
|
{
|
||||||
|
$entityManager = $this->getMock(EntityManagerInterface::class);
|
||||||
|
|
||||||
|
yield[
|
||||||
|
new QueryBuilder($entityManager),
|
||||||
|
[],
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
new QueryBuilder($entityManager),
|
||||||
|
new ArrayCollection(),
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
new QueryBuilder($entityManager),
|
||||||
|
[
|
||||||
|
'lorem' => 11,
|
||||||
|
'ipsum' => 22,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
new QueryBuilder($entityManager),
|
||||||
|
new ArrayCollection([
|
||||||
|
'lorem' => 11,
|
||||||
|
'ipsum' => 22,
|
||||||
|
]),
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
new QueryBuilder($entityManager),
|
||||||
|
[
|
||||||
|
new Parameter('lorem', 11),
|
||||||
|
new Parameter('ipsum', 22),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
new QueryBuilder($entityManager),
|
||||||
|
new ArrayCollection([
|
||||||
|
new Parameter('lorem', 11),
|
||||||
|
new Parameter('ipsum', 22),
|
||||||
|
]),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ namespace Meritoo\Common\Test\Utilities\Reflection;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class B extends A
|
class B extends A implements I
|
||||||
{
|
{
|
||||||
protected $name = 'Lorem Ipsum';
|
protected $name = 'Lorem Ipsum';
|
||||||
|
|
||||||
27
tests/Utilities/Reflection/H.php
Normal file
27
tests/Utilities/Reflection/H.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?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 H class.
|
||||||
|
* Used for testing the Reflection class.
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
class H
|
||||||
|
{
|
||||||
|
const DOLOR = 'sit';
|
||||||
|
|
||||||
|
const LOREM = 'ipsum';
|
||||||
|
|
||||||
|
const MAX_USERS = 5;
|
||||||
|
|
||||||
|
const MIN_USERS = 2;
|
||||||
|
}
|
||||||
20
tests/Utilities/Reflection/I.php
Normal file
20
tests/Utilities/Reflection/I.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?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 H interface.
|
||||||
|
* Used for testing the Reflection class.
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
interface I
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -22,6 +22,8 @@ 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\F;
|
||||||
use Meritoo\Common\Test\Utilities\Reflection\G;
|
use Meritoo\Common\Test\Utilities\Reflection\G;
|
||||||
|
use Meritoo\Common\Test\Utilities\Reflection\H;
|
||||||
|
use Meritoo\Common\Test\Utilities\Reflection\I;
|
||||||
use Meritoo\Common\Utilities\Reflection;
|
use Meritoo\Common\Utilities\Reflection;
|
||||||
use ReflectionProperty;
|
use ReflectionProperty;
|
||||||
|
|
||||||
@@ -33,7 +35,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);
|
||||||
}
|
}
|
||||||
@@ -122,7 +124,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetChildClassesInvalidClass($invalidClass)
|
public function testGetChildClassesInvalidClass($invalidClass)
|
||||||
{
|
{
|
||||||
$this->expectException(CannotResolveClassNameException::class);
|
$this->setExpectedException(CannotResolveClassNameException::class);
|
||||||
|
|
||||||
self::assertNull(Reflection::getChildClasses($invalidClass));
|
self::assertNull(Reflection::getChildClasses($invalidClass));
|
||||||
self::assertNull(Reflection::getChildClasses(123));
|
self::assertNull(Reflection::getChildClasses(123));
|
||||||
@@ -130,7 +132,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testGetChildClassesNotExistingClass()
|
public function testGetChildClassesNotExistingClass()
|
||||||
{
|
{
|
||||||
$this->expectException(CannotResolveClassNameException::class);
|
$this->setExpectedException(CannotResolveClassNameException::class);
|
||||||
self::assertEquals('', Reflection::getChildClasses('xyz'));
|
self::assertEquals('', Reflection::getChildClasses('xyz'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,13 +163,13 @@ class ReflectionTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testGetOneChildClassWithMissingChildClasses()
|
public function testGetOneChildClassWithMissingChildClasses()
|
||||||
{
|
{
|
||||||
$this->expectException(MissingChildClassesException::class);
|
$this->setExpectedException(MissingChildClassesException::class);
|
||||||
self::assertEquals('LoremIpsum', Reflection::getOneChildClass(C::class));
|
self::assertEquals('LoremIpsum', Reflection::getOneChildClass(C::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetOneChildClassWithTooManyChildClasses()
|
public function testGetOneChildClassWithTooManyChildClasses()
|
||||||
{
|
{
|
||||||
$this->expectException(TooManyChildClassesException::class);
|
$this->setExpectedException(TooManyChildClassesException::class);
|
||||||
|
|
||||||
self::assertEquals(B::class, Reflection::getOneChildClass(A::class));
|
self::assertEquals(B::class, Reflection::getOneChildClass(A::class));
|
||||||
self::assertEquals(C::class, Reflection::getOneChildClass(A::class));
|
self::assertEquals(C::class, Reflection::getOneChildClass(A::class));
|
||||||
@@ -195,7 +197,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
public function testUsesTraitInvalidClass($class, $trait)
|
public function testUsesTraitInvalidClass($class, $trait)
|
||||||
{
|
{
|
||||||
$this->expectException(CannotResolveClassNameException::class);
|
$this->setExpectedException(CannotResolveClassNameException::class);
|
||||||
self::assertNull(Reflection::usesTrait($class, $trait));
|
self::assertNull(Reflection::usesTrait($class, $trait));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +207,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
public function testUsesTraitInvalidTrait($trait)
|
public function testUsesTraitInvalidTrait($trait)
|
||||||
{
|
{
|
||||||
$this->expectException(CannotResolveClassNameException::class);
|
$this->setExpectedException(CannotResolveClassNameException::class);
|
||||||
self::assertNull(Reflection::usesTrait(DateTime::class, $trait));
|
self::assertNull(Reflection::usesTrait(DateTime::class, $trait));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +272,6 @@ class ReflectionTest extends BaseTestCase
|
|||||||
self::assertEquals($city, Reflection::getPropertyValue($f, 'city'));
|
self::assertEquals($city, Reflection::getPropertyValue($f, 'city'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testGetPropertyValueWithPrivateGetter()
|
public function testGetPropertyValueWithPrivateGetter()
|
||||||
{
|
{
|
||||||
$accountBalance = 1000;
|
$accountBalance = 1000;
|
||||||
@@ -380,6 +381,99 @@ class ReflectionTest extends BaseTestCase
|
|||||||
self::assertEquals($expected, Reflection::getPropertyValues($collection, 'gInstance.firstName', true));
|
self::assertEquals($expected, Reflection::getPropertyValues($collection, 'gInstance.firstName', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetMaxNumberConstantUsingClassWithoutConstants()
|
||||||
|
{
|
||||||
|
static::assertNull(Reflection::getMaxNumberConstant(A::class));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetMaxNumberConstant()
|
||||||
|
{
|
||||||
|
static::assertEquals(5, Reflection::getMaxNumberConstant(H::class));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHasMethodUsingClassWithoutMethod()
|
||||||
|
{
|
||||||
|
static::assertFalse(Reflection::hasMethod(A::class, 'getUser'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHasMethod()
|
||||||
|
{
|
||||||
|
static::assertTrue(Reflection::hasMethod(A::class, 'getCount'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHasPropertyUsingClassWithoutProperty()
|
||||||
|
{
|
||||||
|
static::assertFalse(Reflection::hasProperty(A::class, 'users'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHasProperty()
|
||||||
|
{
|
||||||
|
static::assertTrue(Reflection::hasProperty(A::class, 'count'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHasConstantUsingClassWithoutConstant()
|
||||||
|
{
|
||||||
|
static::assertFalse(Reflection::hasConstant(H::class, 'users'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHasConstant()
|
||||||
|
{
|
||||||
|
static::assertTrue(Reflection::hasConstant(H::class, 'LOREM'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetConstantValueUsingClassWithoutConstant()
|
||||||
|
{
|
||||||
|
static::assertNull(Reflection::getConstantValue(H::class, 'users'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetConstantValue()
|
||||||
|
{
|
||||||
|
static::assertEquals(H::LOREM, Reflection::getConstantValue(H::class, 'LOREM'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsInterfaceImplementedUsingClassWithoutInterface()
|
||||||
|
{
|
||||||
|
static::assertFalse(Reflection::isInterfaceImplemented(A::class, I::class));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsInterfaceImplemented()
|
||||||
|
{
|
||||||
|
static::assertTrue(Reflection::isInterfaceImplemented(B::class, I::class));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsChildOfClassUsingClassWithoutChildClass()
|
||||||
|
{
|
||||||
|
static::assertFalse(Reflection::isChildOfClass(A::class, B::class));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsChildOfClass()
|
||||||
|
{
|
||||||
|
static::assertTrue(Reflection::isChildOfClass(B::class, A::class));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPropertyUsingClassWithoutProperty()
|
||||||
|
{
|
||||||
|
static::assertNull(Reflection::getProperty(A::class, 'lorem'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPropertyUsingClassWithPrivateProperty()
|
||||||
|
{
|
||||||
|
$property = Reflection::getProperty(A::class, 'count', ReflectionProperty::IS_PRIVATE);
|
||||||
|
|
||||||
|
static::assertInstanceOf(ReflectionProperty::class, $property);
|
||||||
|
static::assertTrue($property->isPrivate());
|
||||||
|
static::assertEquals('count', $property->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPropertyUsingClassWithProtectedProperty()
|
||||||
|
{
|
||||||
|
$property = Reflection::getProperty(B::class, 'name', ReflectionProperty::IS_PROTECTED);
|
||||||
|
|
||||||
|
static::assertInstanceOf(ReflectionProperty::class, $property);
|
||||||
|
static::assertTrue($property->isProtected());
|
||||||
|
static::assertEquals('name', $property->getName());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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