mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3bcda8e906 | ||
|
|
1641c50d1d | ||
|
|
afbbdfe437 | ||
|
|
6d4e422165 | ||
|
|
6f441bb9ea | ||
|
|
73030d703b | ||
|
|
36ddb326b9 | ||
|
|
452a4ec458 | ||
|
|
325fe6b141 | ||
|
|
a1c26b3812 | ||
|
|
67d93036cf | ||
|
|
9368616dfe | ||
|
|
5ab68d3667 | ||
|
|
4613a63f02 | ||
|
|
9dac5bd11c | ||
|
|
12100db058 | ||
|
|
f9ab0a6194 | ||
|
|
b824808cd4 | ||
|
|
71e1eeb81b |
|
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
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -14,7 +14,7 @@
|
|||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
### Phing
|
### Phing
|
||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
/phing/properties
|
/.phing/properties
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -32,13 +32,13 @@
|
|||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
### Build files
|
### Build files
|
||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
/build/
|
/.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>
|
||||||
|
|
||||||
23
README.md
23
README.md
@@ -5,14 +5,35 @@ Common and useful classes, methods, exceptions etc.
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
In your `composer.json` add address of repository into `repositories` section:
|
||||||
|
|
||||||
|
```json
|
||||||
|
"repositories": [
|
||||||
|
(...)
|
||||||
|
{
|
||||||
|
"type": "vcs",
|
||||||
|
"url": "https://github.com/wiosna-dev/common-library"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
Run [Composer](https://getcomposer.org) to install this package in your project:
|
Run [Composer](https://getcomposer.org) to install this package in your project:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ composer require meritoo/common-library
|
$ composer require wiosna-dev/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..." />
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "meritoo/common-library",
|
"name": "wiosna-dev/common-library",
|
||||||
"description": "Useful classes, methods, extensions etc.",
|
"description": "Useful classes, methods, extensions etc.",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "0.0.14",
|
"version": "0.0.17",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Meritoo.pl",
|
"name": "Meritoo.pl",
|
||||||
@@ -11,18 +11,18 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"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": {
|
||||||
"friendsofphp/php-cs-fixer": "^2.6",
|
"friendsofphp/php-cs-fixer": "^2.2",
|
||||||
"pdepend/pdepend": "^2.5",
|
"pdepend/pdepend": "^2.5",
|
||||||
"phploc/phploc": "^4.0",
|
"phploc/phploc": "^2.1",
|
||||||
"phpmd/phpmd": "^2.6",
|
"phpmd/phpmd": "^2.6",
|
||||||
"phpunit/phpunit": "^5.7",
|
"phpunit/phpunit": "^4.8",
|
||||||
"sebastian/phpcpd": "^3.0",
|
"sebastian/phpcpd": "^2.0",
|
||||||
"squizlabs/php_codesniffer": "^2.9"
|
"squizlabs/php_codesniffer": "^2.9"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
@@ -34,5 +34,8 @@
|
|||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Meritoo\\Common\\Test\\": "tests/"
|
"Meritoo\\Common\\Test\\": "tests/"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"sort-packages": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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>
|
||||||
|
|||||||
@@ -8,14 +8,8 @@
|
|||||||
|
|
||||||
namespace Meritoo\Common\Test\Base;
|
namespace Meritoo\Common\Test\Base;
|
||||||
|
|
||||||
use DateTime;
|
use Meritoo\Common\Traits\Test\Base\BaseTestCaseTrait;
|
||||||
use Generator;
|
|
||||||
use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException;
|
|
||||||
use Meritoo\Common\Type\OopVisibilityType;
|
|
||||||
use Meritoo\Common\Utilities\Miscellaneous;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use ReflectionClass;
|
|
||||||
use ReflectionMethod;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base test case with common methods and data providers
|
* Base test case with common methods and data providers
|
||||||
@@ -25,197 +19,5 @@ use ReflectionMethod;
|
|||||||
*/
|
*/
|
||||||
abstract class BaseTestCase extends TestCase
|
abstract class BaseTestCase extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
use BaseTestCaseTrait;
|
||||||
* Provides an empty value
|
|
||||||
*
|
|
||||||
* @return Generator
|
|
||||||
*/
|
|
||||||
public function provideEmptyValue()
|
|
||||||
{
|
|
||||||
yield[''];
|
|
||||||
yield[' '];
|
|
||||||
yield[null];
|
|
||||||
yield[0];
|
|
||||||
yield[false];
|
|
||||||
yield[[]];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides boolean value
|
|
||||||
*
|
|
||||||
* @return Generator
|
|
||||||
*/
|
|
||||||
public function provideBooleanValue()
|
|
||||||
{
|
|
||||||
yield[false];
|
|
||||||
yield[true];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides instance of DateTime class
|
|
||||||
*
|
|
||||||
* @return Generator
|
|
||||||
*/
|
|
||||||
public function provideDateTimeInstance()
|
|
||||||
{
|
|
||||||
yield[new DateTime()];
|
|
||||||
yield[new DateTime('yesterday')];
|
|
||||||
yield[new DateTime('now')];
|
|
||||||
yield[new DateTime('tomorrow')];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides relative / compound format of DateTime
|
|
||||||
*
|
|
||||||
* @return Generator
|
|
||||||
*/
|
|
||||||
public function provideDateTimeRelativeFormat()
|
|
||||||
{
|
|
||||||
yield['now'];
|
|
||||||
yield['yesterday'];
|
|
||||||
yield['tomorrow'];
|
|
||||||
yield['back of 10'];
|
|
||||||
yield['front of 10'];
|
|
||||||
yield['last day of February'];
|
|
||||||
yield['first day of next month'];
|
|
||||||
yield['last day of previous month'];
|
|
||||||
yield['last day of next month'];
|
|
||||||
yield['Y-m-d'];
|
|
||||||
yield['Y-m-d 10:00'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides path of not existing file, e.g. "lorem/ipsum.jpg"
|
|
||||||
*
|
|
||||||
* @return Generator
|
|
||||||
*/
|
|
||||||
public function provideNotExistingFilePath()
|
|
||||||
{
|
|
||||||
yield['lets-test.doc'];
|
|
||||||
yield['lorem/ipsum.jpg'];
|
|
||||||
yield['surprise/me/one/more/time.txt'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns path of file used by tests.
|
|
||||||
* It should be placed in /data/tests directory of this project.
|
|
||||||
*
|
|
||||||
* @param string $fileName Name of file
|
|
||||||
* @param string $directoryPath (optional) Path of directory containing the file
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getFilePathToTests($fileName, $directoryPath = '')
|
|
||||||
{
|
|
||||||
$rootPath = Miscellaneous::getProjectRootPath();
|
|
||||||
|
|
||||||
$paths = [
|
|
||||||
$rootPath,
|
|
||||||
'data/tests',
|
|
||||||
$directoryPath,
|
|
||||||
$fileName,
|
|
||||||
];
|
|
||||||
|
|
||||||
return Miscellaneous::concatenatePaths($paths);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies visibility and arguments of method
|
|
||||||
*
|
|
||||||
* @param string $classNamespace Namespace of class that contains method to verify
|
|
||||||
* @param string|ReflectionMethod $method Name of method or just the method to verify
|
|
||||||
* @param string $visibilityType Expected visibility of verified method. One of
|
|
||||||
* OopVisibilityType class constants.
|
|
||||||
* @param int $argumentsCount (optional) Expected count/amount of arguments of the
|
|
||||||
* verified method
|
|
||||||
* @param int $requiredArgumentsCount (optional) Expected count/amount of required arguments
|
|
||||||
* of the verified method
|
|
||||||
* @throws UnknownOopVisibilityTypeException
|
|
||||||
*
|
|
||||||
* Attention. 2nd argument, the $method, may be:
|
|
||||||
* - string - name of the method
|
|
||||||
* - instance of ReflectionMethod - just the method (provided by ReflectionClass::getMethod() method)
|
|
||||||
*/
|
|
||||||
protected static function assertMethodVisibilityAndArguments(
|
|
||||||
$classNamespace,
|
|
||||||
$method,
|
|
||||||
$visibilityType,
|
|
||||||
$argumentsCount = 0,
|
|
||||||
$requiredArgumentsCount = 0
|
|
||||||
) {
|
|
||||||
/*
|
|
||||||
* Type of visibility is correct?
|
|
||||||
*/
|
|
||||||
if (!(new OopVisibilityType())->isCorrectType($visibilityType)) {
|
|
||||||
throw new UnknownOopVisibilityTypeException($visibilityType);
|
|
||||||
}
|
|
||||||
|
|
||||||
$reflection = new ReflectionClass($classNamespace);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Name of method provided only?
|
|
||||||
* Let's find instance of the method (based on reflection)
|
|
||||||
*/
|
|
||||||
if (!$method instanceof ReflectionMethod) {
|
|
||||||
$method = $reflection->getMethod($method);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($visibilityType) {
|
|
||||||
case OopVisibilityType::IS_PUBLIC:
|
|
||||||
static::assertTrue($method->isPublic());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OopVisibilityType::IS_PROTECTED:
|
|
||||||
static::assertTrue($method->isProtected());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OopVisibilityType::IS_PRIVATE:
|
|
||||||
static::assertTrue($method->isPrivate());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
static::assertEquals($argumentsCount, $method->getNumberOfParameters());
|
|
||||||
static::assertEquals($requiredArgumentsCount, $method->getNumberOfRequiredParameters());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies visibility and arguments of class constructor
|
|
||||||
*
|
|
||||||
* @param string $classNamespace Namespace of class that contains constructor to verify
|
|
||||||
* @param string $visibilityType Expected visibility of verified method. One of OopVisibilityType class
|
|
||||||
* constants.
|
|
||||||
* @param int $argumentsCount (optional) Expected count/amount of arguments of the verified method
|
|
||||||
* @param int $requiredArgumentsCount (optional) Expected count/amount of required arguments of the verified
|
|
||||||
* method
|
|
||||||
* @throws UnknownOopVisibilityTypeException
|
|
||||||
*/
|
|
||||||
protected static function assertConstructorVisibilityAndArguments(
|
|
||||||
$classNamespace,
|
|
||||||
$visibilityType,
|
|
||||||
$argumentsCount = 0,
|
|
||||||
$requiredArgumentsCount = 0
|
|
||||||
) {
|
|
||||||
/*
|
|
||||||
* Let's grab the constructor
|
|
||||||
*/
|
|
||||||
$reflection = new ReflectionClass($classNamespace);
|
|
||||||
$method = $reflection->getConstructor();
|
|
||||||
|
|
||||||
return static::assertMethodVisibilityAndArguments($classNamespace, $method, $visibilityType, $argumentsCount, $requiredArgumentsCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that class with given namespace has no constructor
|
|
||||||
*
|
|
||||||
* @param string $classNamespace Namespace of class that contains constructor to verify
|
|
||||||
*/
|
|
||||||
protected static function assertHasNoConstructor($classNamespace)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Let's grab the constructor
|
|
||||||
*/
|
|
||||||
$reflection = new ReflectionClass($classNamespace);
|
|
||||||
$constructor = $reflection->getConstructor();
|
|
||||||
|
|
||||||
static::assertNull($constructor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
<?php
|
<?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;
|
namespace Meritoo\Common\Test\Base;
|
||||||
|
|
||||||
use Generator;
|
use Meritoo\Common\Traits\Test\Base\BaseTypeTestCaseTrait;
|
||||||
use Meritoo\Common\Type\Base\BaseType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base test case for the type of something
|
* Base test case for the type of something
|
||||||
@@ -13,48 +18,5 @@ use Meritoo\Common\Type\Base\BaseType;
|
|||||||
*/
|
*/
|
||||||
abstract class BaseTypeTestCase extends BaseTestCase
|
abstract class BaseTypeTestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
/**
|
use BaseTypeTestCaseTrait;
|
||||||
* Verifies availability of all types
|
|
||||||
*/
|
|
||||||
public function testAvailabilityOfAllTypes()
|
|
||||||
{
|
|
||||||
$available = $this->getTestedTypeInstance()->getAll();
|
|
||||||
$all = $this->getAllExpectedTypes();
|
|
||||||
|
|
||||||
static::assertEquals($all, $available);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies whether given type is correct or not
|
|
||||||
*
|
|
||||||
* @param string $type Type to verify
|
|
||||||
* @param bool $expected Information if given type is correct or not
|
|
||||||
*
|
|
||||||
* @dataProvider provideTypeToVerify
|
|
||||||
*/
|
|
||||||
public function testIfGivenTypeIsCorrect($type, $expected)
|
|
||||||
{
|
|
||||||
static::assertEquals($expected, $this->getTestedTypeInstance()->isCorrectType($type));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides type to verify and information if it's correct
|
|
||||||
*
|
|
||||||
* @return Generator
|
|
||||||
*/
|
|
||||||
abstract public function provideTypeToVerify();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns instance of the tested type
|
|
||||||
*
|
|
||||||
* @return BaseType
|
|
||||||
*/
|
|
||||||
abstract protected function getTestedTypeInstance();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns all expected types of the tested type
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
abstract protected function getAllExpectedTypes();
|
|
||||||
}
|
}
|
||||||
|
|||||||
238
src/Traits/Test/Base/BaseTestCaseTrait.php
Normal file
238
src/Traits/Test/Base/BaseTestCaseTrait.php
Normal file
@@ -0,0 +1,238 @@
|
|||||||
|
<?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\Traits\Test\Base;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use Generator;
|
||||||
|
use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException;
|
||||||
|
use Meritoo\Common\Type\OopVisibilityType;
|
||||||
|
use Meritoo\Common\Utilities\Miscellaneous;
|
||||||
|
use ReflectionClass;
|
||||||
|
use ReflectionMethod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BaseTestCaseTrait
|
||||||
|
* Created on 2017-11-02
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
trait BaseTestCaseTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Path of directory with data used by test cases
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $testsDataDirPath = '.data/tests';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an empty value
|
||||||
|
*
|
||||||
|
* @return Generator
|
||||||
|
*/
|
||||||
|
public function provideEmptyValue()
|
||||||
|
{
|
||||||
|
yield[''];
|
||||||
|
yield[' '];
|
||||||
|
yield[null];
|
||||||
|
yield[0];
|
||||||
|
yield[false];
|
||||||
|
yield[[]];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides boolean value
|
||||||
|
*
|
||||||
|
* @return Generator
|
||||||
|
*/
|
||||||
|
public function provideBooleanValue()
|
||||||
|
{
|
||||||
|
yield[false];
|
||||||
|
yield[true];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides instance of DateTime class
|
||||||
|
*
|
||||||
|
* @return Generator
|
||||||
|
*/
|
||||||
|
public function provideDateTimeInstance()
|
||||||
|
{
|
||||||
|
yield[new DateTime()];
|
||||||
|
yield[new DateTime('yesterday')];
|
||||||
|
yield[new DateTime('now')];
|
||||||
|
yield[new DateTime('tomorrow')];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides relative / compound format of DateTime
|
||||||
|
*
|
||||||
|
* @return Generator
|
||||||
|
*/
|
||||||
|
public function provideDateTimeRelativeFormat()
|
||||||
|
{
|
||||||
|
yield['now'];
|
||||||
|
yield['yesterday'];
|
||||||
|
yield['tomorrow'];
|
||||||
|
yield['back of 10'];
|
||||||
|
yield['front of 10'];
|
||||||
|
yield['last day of February'];
|
||||||
|
yield['first day of next month'];
|
||||||
|
yield['last day of previous month'];
|
||||||
|
yield['last day of next month'];
|
||||||
|
yield['Y-m-d'];
|
||||||
|
yield['Y-m-d 10:00'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides path of not existing file, e.g. "lorem/ipsum.jpg"
|
||||||
|
*
|
||||||
|
* @return Generator
|
||||||
|
*/
|
||||||
|
public function provideNotExistingFilePath()
|
||||||
|
{
|
||||||
|
yield['lets-test.doc'];
|
||||||
|
yield['lorem/ipsum.jpg'];
|
||||||
|
yield['surprise/me/one/more/time.txt'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns path of file used by tests.
|
||||||
|
* It should be placed in /.data/tests directory of this project.
|
||||||
|
*
|
||||||
|
* @param string $fileName Name of file
|
||||||
|
* @param string $directoryPath (optional) Path of directory containing the file
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getFilePathForTesting($fileName, $directoryPath = '')
|
||||||
|
{
|
||||||
|
$rootPath = Miscellaneous::getProjectRootPath();
|
||||||
|
|
||||||
|
$paths = [
|
||||||
|
$rootPath,
|
||||||
|
self::$testsDataDirPath,
|
||||||
|
$directoryPath,
|
||||||
|
$fileName,
|
||||||
|
];
|
||||||
|
|
||||||
|
return Miscellaneous::concatenatePaths($paths);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies visibility and arguments of method
|
||||||
|
*
|
||||||
|
* @param string $classNamespace Namespace of class that contains method to verify
|
||||||
|
* @param string|ReflectionMethod $method Name of method or just the method to verify
|
||||||
|
* @param string $visibilityType Expected visibility of verified method. One of
|
||||||
|
* OopVisibilityType class constants.
|
||||||
|
* @param int $argumentsCount (optional) Expected count/amount of arguments of the
|
||||||
|
* verified method
|
||||||
|
* @param int $requiredArgumentsCount (optional) Expected count/amount of required arguments
|
||||||
|
* of the verified method
|
||||||
|
* @throws UnknownOopVisibilityTypeException
|
||||||
|
*
|
||||||
|
* Attention. 2nd argument, the $method, may be:
|
||||||
|
* - string - name of the method
|
||||||
|
* - instance of ReflectionMethod - just the method (provided by ReflectionClass::getMethod() method)
|
||||||
|
*/
|
||||||
|
protected static function assertMethodVisibilityAndArguments(
|
||||||
|
$classNamespace,
|
||||||
|
$method,
|
||||||
|
$visibilityType,
|
||||||
|
$argumentsCount = 0,
|
||||||
|
$requiredArgumentsCount = 0
|
||||||
|
) {
|
||||||
|
/*
|
||||||
|
* Type of visibility is correct?
|
||||||
|
*/
|
||||||
|
if (!(new OopVisibilityType())->isCorrectType($visibilityType)) {
|
||||||
|
throw new UnknownOopVisibilityTypeException($visibilityType);
|
||||||
|
}
|
||||||
|
|
||||||
|
$reflection = new ReflectionClass($classNamespace);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name of method provided only?
|
||||||
|
* Let's find instance of the method (based on reflection)
|
||||||
|
*/
|
||||||
|
if (!$method instanceof ReflectionMethod) {
|
||||||
|
$method = $reflection->getMethod($method);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($visibilityType) {
|
||||||
|
case OopVisibilityType::IS_PUBLIC:
|
||||||
|
static::assertTrue($method->isPublic());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OopVisibilityType::IS_PROTECTED:
|
||||||
|
static::assertTrue($method->isProtected());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OopVisibilityType::IS_PRIVATE:
|
||||||
|
static::assertTrue($method->isPrivate());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
static::assertEquals($argumentsCount, $method->getNumberOfParameters());
|
||||||
|
static::assertEquals($requiredArgumentsCount, $method->getNumberOfRequiredParameters());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies visibility and arguments of class constructor
|
||||||
|
*
|
||||||
|
* @param string $classNamespace Namespace of class that contains constructor to verify
|
||||||
|
* @param string $visibilityType Expected visibility of verified method. One of OopVisibilityType class
|
||||||
|
* constants.
|
||||||
|
* @param int $argumentsCount (optional) Expected count/amount of arguments of the verified method
|
||||||
|
* @param int $requiredArgumentsCount (optional) Expected count/amount of required arguments of the verified
|
||||||
|
* method
|
||||||
|
* @throws UnknownOopVisibilityTypeException
|
||||||
|
*/
|
||||||
|
protected static function assertConstructorVisibilityAndArguments(
|
||||||
|
$classNamespace,
|
||||||
|
$visibilityType,
|
||||||
|
$argumentsCount = 0,
|
||||||
|
$requiredArgumentsCount = 0
|
||||||
|
) {
|
||||||
|
/*
|
||||||
|
* Let's grab the constructor
|
||||||
|
*/
|
||||||
|
$reflection = new ReflectionClass($classNamespace);
|
||||||
|
$method = $reflection->getConstructor();
|
||||||
|
|
||||||
|
static::assertMethodVisibilityAndArguments($classNamespace, $method, $visibilityType, $argumentsCount, $requiredArgumentsCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that class with given namespace has no constructor
|
||||||
|
*
|
||||||
|
* @param string $classNamespace Namespace of class that contains constructor to verify
|
||||||
|
*/
|
||||||
|
protected static function assertHasNoConstructor($classNamespace)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Let's grab the constructor
|
||||||
|
*/
|
||||||
|
$reflection = new ReflectionClass($classNamespace);
|
||||||
|
$constructor = $reflection->getConstructor();
|
||||||
|
|
||||||
|
static::assertNull($constructor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
66
src/Traits/Test/Base/BaseTypeTestCaseTrait.php
Normal file
66
src/Traits/Test/Base/BaseTypeTestCaseTrait.php
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?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\Traits\Test\Base;
|
||||||
|
|
||||||
|
use Generator;
|
||||||
|
use Meritoo\Common\Type\Base\BaseType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trait for the base test case for the type of something
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
trait BaseTypeTestCaseTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Verifies availability of all types
|
||||||
|
*/
|
||||||
|
public function testAvailabilityOfAllTypes()
|
||||||
|
{
|
||||||
|
$available = $this->getTestedTypeInstance()->getAll();
|
||||||
|
$all = $this->getAllExpectedTypes();
|
||||||
|
|
||||||
|
static::assertEquals($all, $available);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies whether given type is correct or not
|
||||||
|
*
|
||||||
|
* @param string $type Type to verify
|
||||||
|
* @param bool $expected Information if given type is correct or not
|
||||||
|
*
|
||||||
|
* @dataProvider provideTypeToVerify
|
||||||
|
*/
|
||||||
|
public function testIfGivenTypeIsCorrect($type, $expected)
|
||||||
|
{
|
||||||
|
static::assertEquals($expected, $this->getTestedTypeInstance()->isCorrectType($type));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides type to verify and information if it's correct
|
||||||
|
*
|
||||||
|
* @return Generator
|
||||||
|
*/
|
||||||
|
abstract public function provideTypeToVerify();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns instance of the tested type
|
||||||
|
*
|
||||||
|
* @return BaseType
|
||||||
|
*/
|
||||||
|
abstract protected function getTestedTypeInstance();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all expected types of the tested type
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
abstract protected function getAllExpectedTypes();
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,7 +223,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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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');
|
||||||
|
|||||||
@@ -122,7 +122,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 +130,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 +161,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 +195,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 +205,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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user