17 Commits

Author SHA1 Message Date
Meritoo
e53273fb32 Merge branch 'develop' 2018-07-02 20:20:52 +02:00
Meritoo
cc30ad8d9e Move version of this package to "VERSION" file (from "composer.json" file) 2018-07-02 20:19:29 +02:00
Meritoo
9f08a2aaaf ValueObject > class Version > represents version of software 2018-07-02 20:07:33 +02:00
Meritoo
b49605a26c TravisCI - fix "No output has been received in the last 10m0s" bug (build times out because no output was received) 2018-07-02 10:40:33 +02:00
Meritoo
8441c82356 TravisCI > run using PHP 7.2 too 2018-07-02 09:53:16 +02:00
Meritoo
55dde2e898 Merge branch 'develop' 2018-07-02 09:34:53 +02:00
Meritoo
a32e0c4cca Documentation > Exceptions 2018-07-02 09:31:07 +02:00
Meritoo
834b24f348 Exceptions > create instance of exception using static "create()" method (instead of constructor) 2018-07-02 08:54:24 +02:00
Meritoo
9342f0e87e Docker > rename "php-cli" service to "php" 2018-07-02 08:47:56 +02:00
Meritoo
72fd87e165 Composer > support/require PHP 5.6+ (instead of 5.5.9+) 2018-07-02 08:12:26 +02:00
Meritoo
64499b49d3 Update @author and @copyright in classes' descriptions 2018-07-01 21:07:47 +02:00
Meritoo
848adef015 Arrays > minor refactoring 2018-07-01 17:45:03 +02:00
Meritoo
1431fd9935 Composer > require ext-pcre 2018-07-01 17:37:51 +02:00
Meritoo
3bb7a182c2 Merge branch 'develop' 2018-06-22 08:26:10 +02:00
Meritoo
1a649d35e1 Merge branch 'develop' 2018-06-18 09:37:27 +02:00
Meritoo
0a3955026b Revert "StyleCI > update configuration"
This reverts commit f9fa5f5
2018-06-15 23:00:53 +02:00
Meritoo
f9fa5f5915 StyleCI > update configuration 2018-06-15 23:00:29 +02:00
99 changed files with 878 additions and 380 deletions

View File

@@ -4,13 +4,14 @@ php:
- 5.6
- 7.0
- 7.1
- 7.2
before_install:
- sudo locale-gen de_DE.UTF-8 es_ES.UTF-8 en_GB.UTF-8 en_US.UTF-8 fr_FR.UTF-8 it_IT.UTF-8 pl_PL.UTF-8 ru_RU.UTF-8
- composer global require hirak/prestissimo
install:
- travis_wait 30 composer install -vvv
- travis_wait 30 composer install
script:
- php ./vendor/bin/phpunit

View File

@@ -1,6 +1,26 @@
# Meritoo Common Library
Common and useful classes, methods, exceptions etc.
# 0.1.1
1. TravisCI > run using PHP 7.2 too
2. ValueObject > class Version > represents version of software
3. Move version of this package to `VERSION` file (from `composer.json` file)
# 0.1.0
1. Composer > support/require PHP 5.6+ (instead of 5.5.9+)
2. Docker > rename `php-cli` service to `php`
3. Exceptions > create instance of exception using static `create()` method (instead of constructor)
4. Documentation > Exceptions
# 0.0.21
1. Composer > require ext-pcre
2. Arrays > minor refactoring
3. Update @author and @copyright in classes' descriptions
# 0.0.20
1. Collection > add() method > treat empty string as not provided index (same as null)

View File

@@ -1,4 +1,5 @@
# Meritoo Common Library
Common and useful classes, methods, exceptions etc.
[![Travis](https://img.shields.io/travis/rust-lang/rust.svg?style=flat-square)](https://travis-ci.org/meritoo/common-library) [![Packagist](https://img.shields.io/packagist/v/meritoo/common-library.svg?style=flat-square)](https://packagist.org/packages/meritoo/common-library) [![license](https://img.shields.io/github/license/meritoo/common-library.svg?style=flat-square)](https://github.com/meritoo/common-library) [![GitHub commits](https://img.shields.io/github/commits-since/meritoo/common-library/0.0.1.svg?style=flat-square)](https://github.com/meritoo/common-library) [![Coverage Status](https://coveralls.io/repos/github/meritoo/common-library/badge.svg?branch=master)](https://coveralls.io/github/meritoo/common-library?branch=master)
@@ -17,7 +18,8 @@ composer require meritoo/common-library
1. [Base test case (with common methods and data providers)](docs/Base-test-case.md)
2. [Collection of elements](docs/Collection-of-elements.md)
3. [Static methods](docs/Static-methods.md)
3. [Exceptions](docs/Static-methods.md)
4. [Static methods](docs/Static-methods.md)
# Development

1
VERSION Normal file
View File

@@ -0,0 +1 @@
0.1.1

View File

@@ -29,7 +29,7 @@
Conditional running of tests.
Disabled, because not required.
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
Meritoo <github@meritoo.pl>
2017-02-22
<if>

View File

@@ -2,7 +2,6 @@
"name": "meritoo/common-library",
"description": "Useful classes, methods, extensions etc.",
"license": "MIT",
"version": "0.0.20",
"authors": [
{
"name": "Meritoo.pl",
@@ -11,7 +10,8 @@
}
],
"require": {
"php": ">=5.5.9",
"php": ">=5.6",
"ext-pcre": "*",
"doctrine/orm": "^2.5",
"gedmo/doctrine-extensions": "^2.4"
},

View File

@@ -1,9 +1,9 @@
version: '3'
services:
php-cli:
image: ${DOCKER_CONTAINER_OWNER}/${DOCKER_CONTAINER_PROJECT}-php-cli
container_name: ${DOCKER_CONTAINER_OWNER}-${DOCKER_CONTAINER_PROJECT}-php-cli
php:
image: ${DOCKER_CONTAINER_OWNER}/${DOCKER_CONTAINER_PROJECT}-php
container_name: ${DOCKER_CONTAINER_OWNER}-${DOCKER_CONTAINER_PROJECT}-php
entrypoint: php
command: -S 0.0.0.0:9999
build:
@@ -13,7 +13,7 @@ services:
volumes:
- .:/project
composer:
image: ${DOCKER_CONTAINER_OWNER}/${DOCKER_CONTAINER_PROJECT}-php-cli
image: ${DOCKER_CONTAINER_OWNER}/${DOCKER_CONTAINER_PROJECT}-php
container_name: ${DOCKER_CONTAINER_OWNER}-${DOCKER_CONTAINER_PROJECT}-composer
entrypoint: composer
volumes:

View File

@@ -1,4 +1,4 @@
FROM php:5.5-cli
FROM php:5.6-cli
MAINTAINER Meritoo <github@meritoo.pl>
#

View File

@@ -1,4 +1,5 @@
# Meritoo Common Library
Common and useful classes, methods, exceptions etc.
# Base test case (with common methods and data providers)
@@ -45,6 +46,7 @@ class MimeTypesTest extends BaseTestCase
1. [**Base test case (with common methods and data providers)**](Base-test-case.md)
2. [Collection of elements](Collection-of-elements.md)
3. [Static methods](Static-methods.md)
3. [Exceptions](Exceptions.md)
4. [Static methods](Static-methods.md)
[&lsaquo; Back to `Readme`](../README.md)

View File

@@ -1,4 +1,5 @@
# Meritoo Common Library
Common and useful classes, methods, exceptions etc.
# Collection of elements
@@ -43,6 +44,7 @@ var_dump($simpleCollection->has('dolor')); // bool(true)
1. [Base test case (with common methods and data providers)](Base-test-case.md)
2. [**Collection of elements**](Collection-of-elements.md)
3. [Static methods](Static-methods.md)
3. [Exceptions](Exceptions.md)
4. [Static methods](Static-methods.md)
[&lsaquo; Back to `Readme`](../README.md)

View File

@@ -1,4 +1,5 @@
# Meritoo Common Library
Development-related information
# Requirements
@@ -61,13 +62,13 @@ docker-compose run composer remove <vendor>/<package>
Fix coding standard by running command:
```bash
docker-compose exec php-cli php-cs-fixer fix
docker-compose exec php php-cs-fixer fix
```
Omit cache and run the Fixer from scratch by running command:
```bash
docker-compose exec php-cli rm .php_cs.cache && docker-compose exec php-cli php-cs-fixer fix
docker-compose exec php rm .php_cs.cache && docker-compose exec php php-cs-fixer fix
```
> [Want more?](https://cs.sensiolabs.org)
@@ -82,17 +83,17 @@ Install required packages by running command: `docker-compose run composer insta
#### Simply & quick, without code coverage
Tests are running using Docker and `php-cli` service defined in `docker-compose.yml`. Example:
Tests are running using Docker and `php` service defined in `docker-compose.yml`. Example:
```bash
docker-compose exec php-cli phpunit --no-coverage
docker-compose exec php phpunit --no-coverage
```
You can also run them in container. In this case you have to run 2 commands:
1. Enter container:
```bash
docker-compose exec php-cli bash
docker-compose exec php bash
```
2. Run tests:
@@ -104,7 +105,7 @@ You can also run them in container. In this case you have to run 2 commands:
#### With code coverage
```bash
docker-compose exec php-cli phpunit
docker-compose exec php phpunit
```
# Other
@@ -112,7 +113,7 @@ docker-compose exec php-cli phpunit
Rebuild project and run tests by running command:
```bash
docker-compose exec php-cli phing
docker-compose exec php phing
```
[&lsaquo; Back to `Readme`](../README.md)

61
docs/Exceptions.md Normal file
View File

@@ -0,0 +1,61 @@
# Meritoo Common Library
Common and useful classes, methods, exceptions etc.
# Exceptions
### Create instance of exception
This package contains a lot of exceptions. Each of them contains static method `create()` with proper arguments that is used to create instance of the exception. Example:
```php
use Meritoo\Common\Exception\Bundle\IncorrectBundleNameException;
throw IncorrectBundleNameException::create('RisusIpsum');
```
### Base exception for unknown type of something
##### Short description
It's a `Meritoo\Common\Exception\Base\UnknownTypeException` class. Related to `Meritoo\Common\Type\Base\BaseType` class that represents type of something, e.g. type of button, order.
##### Usage
You can extend `Meritoo\Common\Exception\Base\UnknownTypeException` class and create your own static method, e.g. `createException()`, which will be used create instance of the exception. Inside the `createException()` method you can call `parent::create()` method.
##### Example
```php
<?php
namespace Your\Package\Exception\Type;
use Meritoo\Common\Exception\Base\UnknownTypeException;
use Your\Package\Type\SimpleType;
class UnknownSimpleTypeException extends UnknownTypeException
{
/**
* Creates exception
*
* @param string $unknownType Unknown and simple type
* @return UnknownSimpleTypeException
*/
public static function createException($unknownType)
{
/* @var UnknownSimpleTypeException $exception */
$exception = parent::create($unknownType, new SimpleType(), 'my simple type of something');
return $exception;
}
}
```
# More
1. [Base test case (with common methods and data providers)](Base-test-case.md)
2. [Collection of elements](Collection-of-elements.md)
3. [**Exceptions**](Exceptions.md)
4. [Static methods](Static-methods.md)
[&lsaquo; Back to `Readme`](../README.md)

View File

@@ -1,4 +1,5 @@
# Meritoo Common Library
Common and useful classes, methods, exceptions etc.
# Static methods
@@ -16,6 +17,7 @@ var_dump($firstElement); // string(5) "lorem"
1. [Base test case (with common methods and data providers)](Base-test-case.md)
2. [Collection of elements](Collection-of-elements.md)
3. [**Static methods**](Static-methods.md)
3. [Exceptions](Exceptions.md)
4. [**Static methods**](Static-methods.md)
[&lsaquo; Back to `Readme`](../README.md)

View File

@@ -31,7 +31,7 @@ assets.installWithSymlink = 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>
# Meritoo <github@meritoo.pl>
# 2017-06-06
#
cache.clearWithWarmup = false
@@ -81,7 +81,7 @@ dir.reports.coverage = ${dir.reports}/phpunit_coverage
# Disabled, because unnecessary right now
# phpdocumentor/phpdocumentor cannot be installed via Composer
#
# Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
# Meritoo <github@meritoo.pl>
# 2017-02-22
#
#dir.docs = ${dir.build}/docs

View File

@@ -4,7 +4,7 @@
The AutoloaderTask is required to load binaries installed by Composer.
The "autoloaderpath" attribute of this task is not required, because it's default value is: vendor/autoload.php.
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
Meritoo <github@meritoo.pl>
2017-02-23
-->
<autoloader />
@@ -48,7 +48,7 @@
a) phpdocumentor/phpdocumentor v2.9.0 requires symfony/validator ~2.2
b) symfony/validator ~2.2 causes to remove symfony/symfony 3.*
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
Meritoo <github@meritoo.pl>
2017-02-22
-->
@@ -73,7 +73,7 @@
a) phpdocumentor/phpdocumentor v2.9.0 requires symfony/validator ~2.2
b) symfony/validator ~2.2 causes to remove symfony/symfony 3.*
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
Meritoo <github@meritoo.pl>
2017-02-22
-->
<!--<target name="build:doc"-->
@@ -113,7 +113,7 @@
a) phpdocumentor/phpdocumentor v2.9.0 requires symfony/validator ~2.2
b) symfony/validator ~2.2 causes to remove symfony/symfony 3.*
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
Meritoo <github@meritoo.pl>
2017-02-22
<target name="doc:phpdoc2" description="Generates API documentations">
@@ -142,7 +142,7 @@
via Composer the Symfony2 standard is not included / available in this package. In this case the PHP Coding
Standards Fixer (http://cs.sensiolabs.org) is used.
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
Meritoo <github@meritoo.pl>
2017-02-22
-->
<target name="check:cs" description="Checks coding standard">
@@ -166,7 +166,7 @@
<!--
Previous / old version
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
Meritoo <github@meritoo.pl>
2017-02-22
<exec command="phpcpd \-\-log-pmd=${dir.reports}/pmd-cpd.xml ${dir.src}" />
@@ -204,7 +204,7 @@
<!--
Previous / old version
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
Meritoo <github@meritoo.pl>
2017-02-22
<exec command="phploc \-\-log-csv=${dir.reports}/phploc.csv ${dir.src}" />

View File

@@ -18,8 +18,8 @@ use Meritoo\Common\Utilities\Arrays;
* Collection of elements.
* It's a set of some elements, e.g. objects.
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class Collection implements Countable, ArrayAccess, IteratorAggregate
{

View File

@@ -15,27 +15,28 @@ use Meritoo\Common\Utilities\Arrays;
/**
* An exception used while type of something is unknown
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
abstract class UnknownTypeException extends Exception
{
/**
* Class constructor
* Creates exception
*
* @param string|int $unknownType The unknown type of something (value of constant)
* @param BaseType $typeInstance An instance of class that contains type of the something
* @param string $typeName Name of the something
* @return UnknownTypeException
*/
public function __construct($unknownType, BaseType $typeInstance, $typeName)
public static function create($unknownType, BaseType $typeInstance, $typeName)
{
$allTypes = $typeInstance->getAll();
$types = Arrays::values2string($allTypes, '', ', ');
$template = 'The \'%s\' type of %s is unknown. Probably doesn\'t exist or there is a typo. You should use one'
. ' of these types: %s.';
$allTypes = $typeInstance->getAll();
$types = Arrays::values2string($allTypes, '', ', ');
$message = sprintf(sprintf($template, $unknownType, $typeName, $types));
parent::__construct($message);
return new static($message);
}
}

View File

@@ -13,22 +13,24 @@ use Exception;
/**
* An exception used while name of bundle is incorrect
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class IncorrectBundleNameException extends Exception
{
/**
* Class constructor
* Creates exception
*
* @param string $bundleName Incorrect name of bundle
* @return IncorrectBundleNameException
*/
public function __construct($bundleName)
public static function create($bundleName)
{
$template = 'Name of bundle \'%s\' is incorrect. It should start with big letter and end with "Bundle". Is'
. ' there everything ok?';
$message = sprintf($template, $bundleName);
parent::__construct($message);
return new static($message);
}
}

View File

@@ -1,32 +0,0 @@
<?php
/**
* (c) Meritoo.pl, http://www.meritoo.pl
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Meritoo\Common\Exception\Date;
use Meritoo\Common\Exception\Base\UnknownTypeException;
use Meritoo\Common\Type\DatePartType;
/**
* An exception used while type of date part, e.g. "year", is unknown
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
*/
class UnknownDatePartTypeException extends UnknownTypeException
{
/**
* Class constructor
*
* @param string $unknownDatePart Type of date part, e.g. "year". One of DatePartType class constants.
* @param string $value Incorrect value
*/
public function __construct($unknownDatePart, $value)
{
parent::__construct($unknownDatePart, new DatePartType(), sprintf('date part (with value %s)', $value));
}
}

View File

@@ -11,21 +11,22 @@ namespace Meritoo\Common\Exception\File;
/**
* An exception used while file with given path is empty (has no content)
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class EmptyFileException extends \Exception
{
/**
* Class constructor
* Creates exception
*
* @param string $emptyFilePath Path of the empty file
* @return EmptyFileException
*/
public function __construct($emptyFilePath)
public static function create($emptyFilePath)
{
$template = 'File with path \'%s\' is empty (has no content). Did you provide path of proper file?';
$message = sprintf($template, $emptyFilePath);
parent::__construct($message);
return new static($message);
}
}

View File

@@ -11,16 +11,16 @@ namespace Meritoo\Common\Exception\File;
/**
* An exception used while path of given file is empty
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class EmptyFilePathException extends \Exception
{
/**
* Class constructor
* Creates exception
*/
public function __construct()
public static function create()
{
parent::__construct('Path of the file is empty. Did you provide path of proper file?');
return new static('Path of the file is empty. Did you provide path of proper file?');
}
}

View File

@@ -11,21 +11,22 @@ namespace Meritoo\Common\Exception\File;
/**
* An exception used while file with given path does not exist
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class NotExistingFileException extends \Exception
{
/**
* Class constructor
* Creates exception
*
* @param string $notExistingFilePath Path of not existing (or not readable) file
* @return NotExistingFileException
*/
public function __construct($notExistingFilePath)
public static function create($notExistingFilePath)
{
$template = 'File with path \'%s\' does not exist (or is not readable). Did you provide path of proper file?';
$message = sprintf($template, $notExistingFilePath);
parent::__construct($message);
return new static($message);
}
}

View File

@@ -13,18 +13,19 @@ use Exception;
/**
* An exception used while method cannot be called, because is disabled
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class DisabledMethodException extends Exception
{
/**
* Class constructor
* Creates exception
*
* @param string $disabledMethod Name of the disabled method
* @param string $alternativeMethod (optional) Name of the alternative method
* @return DisabledMethodException
*/
public function __construct($disabledMethod, $alternativeMethod = '')
public static function create($disabledMethod, $alternativeMethod = '')
{
$template = 'Method %s() cannot be called, because is disabled.';
@@ -33,6 +34,7 @@ class DisabledMethodException extends Exception
}
$message = sprintf($template, $disabledMethod, $alternativeMethod);
parent::__construct($message);
return new static($message);
}
}

View File

@@ -13,20 +13,21 @@ use Exception;
/**
* An exception used while name of class or trait cannot be resolved
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class CannotResolveClassNameException extends Exception
{
/**
* Class constructor
* Creates exception
*
* @param array|object|string $source Source of the class's / trait's name. It can be an array of objects,
* namespaces, object or namespace.
* @param bool $forClass (optional) If is set to true, message of this exception for class is
* prepared. Otherwise - for trait.
* @return CannotResolveClassNameException
*/
public function __construct($source, $forClass = true)
public static function create($source, $forClass = true)
{
$forWho = 'trait';
$value = '';
@@ -42,6 +43,6 @@ class CannotResolveClassNameException extends Exception
$template = 'Name of %s from given \'%s\'%s cannot be resolved. Is there everything ok?';
$message = sprintf($template, $forWho, gettype($source), $value);
parent::__construct($message);
return new static($message);
}
}

View File

@@ -14,18 +14,19 @@ use Meritoo\Common\Utilities\Reflection;
/**
* An exception used while given class has no child classes
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class MissingChildClassesException extends Exception
{
/**
* Class constructor
* Creates exception
*
* @param array|object|string $parentClass Class that hasn't child classes, but it should. An array of objects,
* strings, object or string.
* @return MissingChildClassesException
*/
public function __construct($parentClass)
public static function create($parentClass)
{
$template = 'The \'%s\' class requires one child class at least who will extend her (maybe is an abstract'
. ' class), but the child classes are missing. Did you forget to extend this class?';
@@ -33,6 +34,6 @@ class MissingChildClassesException extends Exception
$parentClassName = Reflection::getClassName($parentClass);
$message = sprintf($template, $parentClassName);
parent::__construct($message);
return new static($message);
}
}

View File

@@ -14,19 +14,20 @@ use Meritoo\Common\Utilities\Reflection;
/**
* An exception used while given class has more than one child class
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class TooManyChildClassesException extends Exception
{
/**
* Class constructor
* Creates exception
*
* @param array|object|string $parentClass Class that has more than one child class, but it shouldn't. An array
* of objects, strings, object or string.
* @param array $childClasses Child classes
* @return TooManyChildClassesException
*/
public function __construct($parentClass, array $childClasses)
public static function create($parentClass, array $childClasses)
{
$template = "The '%s' class requires one child class at most who will extend her, but more than one child"
. " class was found:\n- %s\n\nWhy did you create more than one classes that extend '%s' class?";
@@ -34,6 +35,6 @@ class TooManyChildClassesException extends Exception
$parentClassName = Reflection::getClassName($parentClass);
$message = sprintf($template, $parentClassName, implode("\n- ", $childClasses), $parentClassName);
parent::__construct($message);
return new static($message);
}
}

View File

@@ -11,22 +11,24 @@ namespace Meritoo\Common\Exception\Regex;
/**
* An exception used while length of given hexadecimal value of color is incorrect
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class IncorrectColorHexLengthException extends \Exception
{
/**
* Class constructor
* Creates exception
*
* @param string $color Incorrect hexadecimal value of color
* @return IncorrectColorHexLengthException
*/
public function __construct($color)
public static function create($color)
{
$template = 'Length of hexadecimal value of color \'%s\' is incorrect. It\'s %d, but it should be 3 or 6.'
. ' Is there everything ok?';
$message = sprintf($template, $color, strlen($color));
parent::__construct($message);
return new static($message);
}
}

View File

@@ -11,19 +11,21 @@ namespace Meritoo\Common\Exception\Regex;
/**
* An exception used while given hexadecimal value of color is invalid
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class InvalidColorHexValueException extends \Exception
{
/**
* Class constructor
* Creates exception
*
* @param string $color Invalid hexadecimal value of color
* @return InvalidColorHexValueException
*/
public function __construct($color)
public static function create($color)
{
$message = sprintf('Hexadecimal value of color \'%s\' is invalid. Is there everything ok?', $color);
parent::__construct($message);
return new static($message);
}
}

View File

@@ -11,19 +11,21 @@ namespace Meritoo\Common\Exception\Regex;
/**
* An exception used while html attributes are invalid
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class InvalidHtmlAttributesException extends \Exception
{
/**
* Class constructor
* Creates exception
*
* @param string $htmlAttributes Invalid html attributes
* @return InvalidHtmlAttributesException
*/
public function __construct($htmlAttributes)
public static function create($htmlAttributes)
{
$message = sprintf('HTML attributes \'%s\' are invalid. Is there everything ok?', $htmlAttributes);
parent::__construct($message);
return new static($message);
}
}

View File

@@ -1,23 +1,31 @@
<?php
/**
* (c) Meritoo.pl, http://www.meritoo.pl
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Meritoo\Common\Exception\Regex;
/**
* An exception used while url is invalid
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class InvalidUrlException extends \Exception
{
/**
* Class constructor
* Creates exception
*
* @param string $url Invalid url
* @return InvalidUrlException
*/
public function __construct($url)
public static function create($url)
{
$message = sprintf('Url \'%s\' is invalid. Is there everything ok?', $url);
parent::__construct($message);
return new static($message);
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* (c) Meritoo.pl, http://www.meritoo.pl
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Meritoo\Common\Exception\Type;
use Meritoo\Common\Exception\Base\UnknownTypeException;
use Meritoo\Common\Type\DatePartType;
/**
* An exception used while type of date part, e.g. "year", is unknown
*
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class UnknownDatePartTypeException extends UnknownTypeException
{
/**
* Creates exception
*
* @param string $unknownDatePart Unknown type of date part
* @param string $value Incorrect value
* @return UnknownDatePartTypeException
*/
public static function createException($unknownDatePart, $value)
{
/* @var UnknownDatePartTypeException $exception */
$exception = parent::create($unknownDatePart, new DatePartType(), sprintf('date part (with value %s)', $value));
return $exception;
}
}

View File

@@ -1,5 +1,11 @@
<?php
/**
* (c) Meritoo.pl, http://www.meritoo.pl
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Meritoo\Common\Exception\Type;
use Meritoo\Common\Exception\Base\UnknownTypeException;
@@ -8,16 +14,22 @@ use Meritoo\Common\Type\OopVisibilityType;
/**
* An exception used while the visibility of a property, a method or (as of PHP 7.1.0) a constant is unknown
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class UnknownOopVisibilityTypeException extends UnknownTypeException
{
/**
* {@inheritdoc}
* Creates exception
*
* @param string $unknownType Unknown visibility of a property, a method or (as of PHP 7.1.0) a constant
* @return UnknownOopVisibilityTypeException
*/
public function __construct($unknownType)
public static function createException($unknownType)
{
parent::__construct($unknownType, new OopVisibilityType(), 'OOP-related visibility');
/* @var UnknownOopVisibilityTypeException $exception */
$exception = parent::create($unknownType, new OopVisibilityType(), 'OOP-related visibility');
return $exception;
}
}

View File

@@ -14,8 +14,8 @@ use PHPUnit\Framework\TestCase;
/**
* Base test case with common methods and data providers
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
abstract class BaseTestCase extends TestCase
{

View File

@@ -13,8 +13,8 @@ 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
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
abstract class BaseTypeTestCase extends BaseTestCase
{

View File

@@ -22,8 +22,8 @@ use stdClass;
* BaseTestCaseTrait
* Created on 2017-11-02
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
trait BaseTestCaseTrait
{

View File

@@ -14,8 +14,8 @@ 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
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
trait BaseTypeTestCaseTrait
{

View File

@@ -14,8 +14,8 @@ use Meritoo\Common\Utilities\Reflection;
* Base / abstract type of something, e.g. type of button, order, date etc.
* Child class should contain constants - each of them represent one type.
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
abstract class BaseType
{

View File

@@ -13,8 +13,8 @@ use Meritoo\Common\Type\Base\BaseType;
/**
* Type of date part, e.g. "year"
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class DatePartType extends BaseType
{

View File

@@ -16,8 +16,8 @@ use Meritoo\Common\Utilities\Date;
* A date's period.
* Contains start and end date of the period.
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class DatePeriod extends BaseType
{

View File

@@ -7,8 +7,8 @@ use Meritoo\Common\Type\Base\BaseType;
/**
* The visibility of a property, a method or (as of PHP 7.1.0) a constant
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*
* @see http://php.net/manual/en/language.oop5.visibility.php
*/

View File

@@ -11,8 +11,8 @@ namespace Meritoo\Common\Utilities;
/**
* Useful arrays methods
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class Arrays
{
@@ -673,7 +673,7 @@ class Arrays
return null;
}
$effect = $array;
$effect = &$array;
ksort($effect, $sortFlags);
foreach ($effect as &$value) {
@@ -822,60 +822,66 @@ class Arrays
*/
public static function getLastElementsPaths(array $array, $separator = '.', $parentPath = '', $stopIfMatchedBy = '')
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return [];
}
if (!empty($stopIfMatchedBy)) {
$stopIfMatchedBy = self::makeArray($stopIfMatchedBy);
}
$paths = [];
if (!empty($array)) {
if (!empty($stopIfMatchedBy)) {
$stopIfMatchedBy = self::makeArray($stopIfMatchedBy);
foreach ($array as $key => $value) {
$path = $key;
$stopRecursion = false;
/*
* If the path of parent element is delivered,
* I have to use it and build longer path
*/
if (!empty($parentPath)) {
$pathTemplate = '%s%s%s';
$path = sprintf($pathTemplate, $parentPath, $separator, $key);
}
foreach ($array as $key => $value) {
$path = $key;
$stopRecursion = false;
/*
* Check if the key or current path matches one of patterns at which the process should be stopped,
* the recursive not used. It means that I have to pass current value and stop processing of the
* array (don't go to the next step).
*/
if (!empty($stopIfMatchedBy)) {
foreach ($stopIfMatchedBy as $rawPattern) {
$pattern = sprintf('|%s|', $rawPattern);
/*
* If the path of parent element is delivered,
* I have to use it and build longer path
*/
if (!empty($parentPath)) {
$pathTemplate = '%s%s%s';
$path = sprintf($pathTemplate, $parentPath, $separator, $key);
}
/*
* Check if the key or current path matches one of patterns at which the process should be stopped,
* the recursive not used. It means that I have to pass current value and stop processing of the
* array (don't go to the next step).
*/
if (!empty($stopIfMatchedBy)) {
foreach ($stopIfMatchedBy as $rawPattern) {
$pattern = sprintf('|%s|', $rawPattern);
if (preg_match($pattern, $key) || preg_match($pattern, $path)) {
$stopRecursion = true;
break;
}
if (preg_match($pattern, $key) || preg_match($pattern, $path)) {
$stopRecursion = true;
break;
}
}
}
/*
* The value is passed to the returned array if:
* - it's not an array
* or
* - the process is stopped, recursive is not used
*/
if (!is_array($value) || (is_array($value) && empty($value)) || $stopRecursion) {
$paths[$path] = $value;
continue;
}
/*
* The value is passed to the returned array if:
* - it's not an array
* or
* - the process is stopped, recursive is not used
*/
if (!is_array($value) || (is_array($value) && empty($value)) || $stopRecursion) {
$paths[$path] = $value;
continue;
}
/*
* Let's iterate through the next level, using recursive
*/
if (is_array($value)) {
$recursivePaths = self::getLastElementsPaths($value, $separator, $path, $stopIfMatchedBy);
$paths += $recursivePaths;
}
/*
* Let's iterate through the next level, using recursive
*/
if (is_array($value)) {
$recursivePaths = self::getLastElementsPaths($value, $separator, $path, $stopIfMatchedBy);
$paths += $recursivePaths;
}
}

View File

@@ -13,8 +13,8 @@ use Meritoo\Common\Exception\Bundle\IncorrectBundleNameException;
/**
* Useful methods for bundle
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class Bundle
{
@@ -41,7 +41,7 @@ class Bundle
* Given name of bundle is invalid?
*/
if (!Regex::isValidBundleName($bundleName)) {
throw new IncorrectBundleNameException($bundleName);
throw IncorrectBundleNameException::create($bundleName);
}
/*

View File

@@ -13,8 +13,8 @@ use stdClass;
/**
* Useful Composer-related methods (only static functions)
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class Composer
{

View File

@@ -11,15 +11,15 @@ namespace Meritoo\Common\Utilities;
use DateInterval;
use DateTime;
use Exception;
use Meritoo\Common\Exception\Date\UnknownDatePartTypeException;
use Meritoo\Common\Exception\Type\UnknownDatePartTypeException;
use Meritoo\Common\Type\DatePartType;
use Meritoo\Common\Type\DatePeriod;
/**
* Useful date methods
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class Date
{
@@ -255,21 +255,21 @@ class Date
* Oops, incorrect year
*/
if ($year <= 0) {
throw new UnknownDatePartTypeException(DatePartType::YEAR, $year);
throw UnknownDatePartTypeException::createException(DatePartType::YEAR, $year);
}
/*
* Oops, incorrect month
*/
if ($month < 1 || $month > 12) {
throw new UnknownDatePartTypeException(DatePartType::MONTH, $month);
throw UnknownDatePartTypeException::createException(DatePartType::MONTH, $month);
}
/*
* Oops, incorrect day
*/
if ($day < 1 || $day > 31) {
throw new UnknownDatePartTypeException(DatePartType::DAY, $day);
throw UnknownDatePartTypeException::createException(DatePartType::DAY, $day);
}
if ($month < 3) {

View File

@@ -13,8 +13,8 @@ use Generator;
/**
* Useful methods for the Generator class (only static functions)
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class GeneratorUtility
{

View File

@@ -11,8 +11,8 @@ namespace Meritoo\Common\Utilities;
/**
* Useful locale methods
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class Locale
{

View File

@@ -11,8 +11,8 @@ namespace Meritoo\Common\Utilities;
/**
* Useful methods for mime types of files
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class MimeTypes
{

View File

@@ -16,8 +16,8 @@ use Transliterator;
/**
* Miscellaneous methods (only static functions)
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class Miscellaneous
{

View File

@@ -18,8 +18,8 @@ use Doctrine\ORM\QueryBuilder;
/**
* Useful methods for query builder (the Doctrine's QueryBuilder class)
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class QueryBuilderUtility
{

View File

@@ -23,8 +23,8 @@ use ReflectionProperty;
/**
* Useful reflection methods
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class Reflection
{
@@ -206,7 +206,7 @@ class Reflection
* while using "project.name" as property - $project has $name property ($project exists in the Deal class)
* and the $project equals null
*
* Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* Meritoo <github@meritoo.pl>
* 2016-11-07
*/
if (null !== $object) {
@@ -524,7 +524,7 @@ class Reflection
* Oops, cannot resolve class
*/
if (null === $className) {
throw new CannotResolveClassNameException($class);
throw CannotResolveClassNameException::create($class);
}
$childClasses = [];
@@ -558,7 +558,6 @@ class Reflection
*
* @param array|object|string $parentClass Class who child class should be returned. An array of objects,
* namespaces, object or namespace.
* @throws CannotResolveClassNameException
* @throws MissingChildClassesException
* @throws TooManyChildClassesException
* @return mixed
@@ -572,7 +571,7 @@ class Reflection
* Oops, the base / parent class hasn't child class
*/
if (empty($childClasses)) {
throw new MissingChildClassesException($parentClass);
throw MissingChildClassesException::create($parentClass);
}
/*
@@ -580,7 +579,7 @@ class Reflection
* Oops, the base / parent class has too many child classes
*/
if (count($childClasses) > 1) {
throw new TooManyChildClassesException($parentClass, $childClasses);
throw TooManyChildClassesException::create($parentClass, $childClasses);
}
return trim($childClasses[0]);
@@ -621,7 +620,6 @@ class Reflection
* @param bool $verifyParents If is set to true, parent classes are verified if they use given
* trait. Otherwise - not.
* @throws CannotResolveClassNameException
* @throws ReflectionException
* @return bool|null
*/
public static function usesTrait($class, $trait, $verifyParents = false)
@@ -633,7 +631,7 @@ class Reflection
* Oops, cannot resolve class
*/
if (empty($className)) {
throw new CannotResolveClassNameException($class);
throw CannotResolveClassNameException::create($class);
}
/*

View File

@@ -14,8 +14,8 @@ use Meritoo\Common\Exception\Regex\InvalidColorHexValueException;
/**
* Useful regular expressions methods
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class Regex
{

View File

@@ -14,8 +14,8 @@ use Doctrine\ORM\QueryBuilder;
/**
* Useful methods for repository
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class Repository
{

View File

@@ -11,8 +11,8 @@ namespace Meritoo\Common\Utilities;
/**
* Useful uri methods (only static functions)
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class Uri
{

View File

@@ -15,8 +15,8 @@ use SimpleXMLElement;
/**
* Useful XML-related methods (only static functions)
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class Xml
{

179
src/ValueObject/Version.php Normal file
View File

@@ -0,0 +1,179 @@
<?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\ValueObject;
/**
* Version of software
*
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class Version
{
/**
* The "major" part.
* Incremented when you make incompatible API changes.
*
* @var int
*/
private $majorPart;
/**
* The "minor" part.
* Incremented when you add functionality in a backwards-compatible manner.
*
* @var int
*/
private $minorPart;
/**
* The "patch" part.
* Incremented when you make backwards-compatible bug fixes.
*
* @var int
*/
private $patchPart;
/**
* Class constructor
*
* @param int $majorPart The "major" part. Incremented when you make incompatible API changes.
* @param int $minorPart The "minor" part. Incremented when you add functionality in a backwards-compatible manner.
* @param int $patchPart The "patch" part. Incremented when you make backwards-compatible bug fixes.
*/
public function __construct($majorPart, $minorPart, $patchPart)
{
$this->majorPart = $majorPart;
$this->minorPart = $minorPart;
$this->patchPart = $patchPart;
}
/**
* Returns the "major" part.
* Incremented when you make incompatible API changes.
*
* @return int
*/
public function getMajorPart()
{
return $this->majorPart;
}
/**
* Returns the "minor" part.
* Incremented when you add functionality in a backwards-compatible manner.
*
* @return int
*/
public function getMinorPart()
{
return $this->minorPart;
}
/**
* Returns the "patch" part.
* Incremented when you make backwards-compatible bug fixes.
*
* @return int
*/
public function getPatchPart()
{
return $this->patchPart;
}
/**
* Returns string representation of instance of this class
*
* @return string
*/
public function __toString()
{
return sprintf('%d.%d.%d', $this->getMajorPart(), $this->getMinorPart(), $this->getPatchPart());
}
/**
* Returns new instance based on given version as string.
* Given version should contain 3 dot-separated integers, 1 per each part ("major", "minor" and "patch").
*
* Examples:
* "1.0.2";
* "10.4.0";
*
* @param string $version The version
* @return Version|null
*/
public static function fromString($version)
{
$version = trim($version);
/*
* No version provided?
* Nothing to do
*/
if (empty($version)) {
return null;
}
$matches = [];
$pattern = '/^(\d+)\.(\d+)\.(\d+)$/'; // e.g. "1.0.2"
$matched = preg_match($pattern, $version, $matches);
/*
* Incorrect version?
* Nothing to do
*/
if (0 === $matched || false === $matched) {
return null;
}
$majorPart = (int)$matches[1];
$minorPart = (int)$matches[2];
$patchPart = (int)$matches[3];
return new static($majorPart, $minorPart, $patchPart);
}
/**
* Returns new instance based on given version as array.
* Given version should contain 3 integers, 1 per each part ("major", "minor" and "patch").
*
* Examples:
* [1, 0, 2];
* [10, 4, 0];
*
* @param array $version The version
* @return Version|null
*/
public static function fromArray(array $version)
{
/*
* No version provided?
* Nothing to do
*/
if (empty($version)) {
return null;
}
$count = count($version);
/*
* Incorrect version?
* Nothing to do
*/
if (3 !== $count) {
return null;
}
$majorPart = (int)$version[0];
$minorPart = (int)$version[1];
$patchPart = (int)$version[2];
return new static($majorPart, $minorPart, $patchPart);
}
}

View File

@@ -17,8 +17,8 @@ use Meritoo\Common\Type\OopVisibilityType;
/**
* Test case of the collection of elements
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class CollectionTest extends BaseTestCase
{

View File

@@ -16,14 +16,14 @@ use Meritoo\Common\Type\OopVisibilityType;
/**
* Test case of the exception used while type of something is unknown
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class UnknownTypeExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(UnknownTestTypeException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(UnknownTestTypeException::class, OopVisibilityType::IS_PUBLIC, 3);
}
public function testWithoutException()
@@ -41,8 +41,8 @@ class UnknownTypeExceptionTest extends BaseTestCase
/**
* Type of something (for testing purposes)
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class TestType extends BaseType
{
@@ -54,27 +54,31 @@ class TestType extends BaseType
/**
* An exception used while type of something is unknown (for testing purposes)
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class UnknownTestTypeException extends UnknownTypeException
{
/**
* Class constructor
* Creates exception
*
* @param int|string $unknownType The unknown type of something (for testing purposes)
* @param string $unknownType The unknown type of something (for testing purposes)
* @return UnknownTestTypeException
*/
public function __construct($unknownType)
public static function createException($unknownType)
{
parent::__construct($unknownType, new TestType(), 'type of something used for testing');
/* @var UnknownTestTypeException $exception */
$exception = parent::create($unknownType, new TestType(), 'type of something used for testing');
return $exception;
}
}
/**
* Service used together with type of something (for testing purposes)
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class TestService
{

View File

@@ -9,7 +9,7 @@
namespace Meritoo\Common\Test\Exception\Date;
use Generator;
use Meritoo\Common\Exception\Date\UnknownDatePartTypeException;
use Meritoo\Common\Exception\Type\UnknownDatePartTypeException;
use Meritoo\Common\Test\Base\BaseTestCase;
use Meritoo\Common\Type\DatePartType;
use Meritoo\Common\Type\OopVisibilityType;
@@ -17,14 +17,14 @@ use Meritoo\Common\Type\OopVisibilityType;
/**
* Test case of an exception used while type of date part, e.g. "year", is unknown
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class UnknownDatePartTypeExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(UnknownDatePartTypeException::class, OopVisibilityType::IS_PUBLIC, 2, 2);
static::assertConstructorVisibilityAndArguments(UnknownDatePartTypeException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -34,9 +34,9 @@ class UnknownDatePartTypeExceptionTest extends BaseTestCase
*
* @dataProvider provideDatePartAndValue
*/
public function testConstructorMessage($unknownDatePart, $value, $expectedMessage)
public function testMessage($unknownDatePart, $value, $expectedMessage)
{
$exception = new UnknownDatePartTypeException($unknownDatePart, $value);
$exception = UnknownDatePartTypeException::createException($unknownDatePart, $value);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -16,14 +16,14 @@ use Meritoo\Common\Type\OopVisibilityType;
/**
* Test case of an exception used while file with given path is empty (has no content)
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class EmptyFileExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(EmptyFileException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(EmptyFileException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -32,9 +32,9 @@ class EmptyFileExceptionTest extends BaseTestCase
*
* @dataProvider providePathOfFile
*/
public function testConstructorMessage($emptyFilePath, $expectedMessage)
public function testMessage($emptyFilePath, $expectedMessage)
{
$exception = new EmptyFileException($emptyFilePath);
$exception = EmptyFileException::create($emptyFilePath);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -15,19 +15,19 @@ use Meritoo\Common\Type\OopVisibilityType;
/**
* Test case of an exception used while path of given file is empty
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class EmptyFilePathExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(EmptyFilePathException::class, OopVisibilityType::IS_PUBLIC);
static::assertConstructorVisibilityAndArguments(EmptyFilePathException::class, OopVisibilityType::IS_PUBLIC, 3);
}
public function testConstructorMessage()
{
$exception = new EmptyFilePathException();
$exception = EmptyFilePathException::create();
static::assertEquals('Path of the file is empty. Did you provide path of proper file?', $exception->getMessage());
}
}

View File

@@ -16,14 +16,14 @@ use Meritoo\Common\Type\OopVisibilityType;
/**
* Test case of an exception used while file with given path does not exist
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class NotExistingFileExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(NotExistingFileException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(NotExistingFileException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -34,7 +34,7 @@ class NotExistingFileExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($notExistingFilePath, $expectedMessage)
{
$exception = new NotExistingFileException($notExistingFilePath);
$exception = NotExistingFileException::create($notExistingFilePath);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -16,14 +16,14 @@ use Meritoo\Common\Type\OopVisibilityType;
/**
* Test case of an exception used while method cannot be called, because is disabled
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class DisabledMethodExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(DisabledMethodException::class, OopVisibilityType::IS_PUBLIC, 2, 1);
static::assertConstructorVisibilityAndArguments(DisabledMethodException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -36,7 +36,7 @@ class DisabledMethodExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($disabledMethod, $alternativeMethod, $expectedMessage)
{
$exception = new DisabledMethodException($disabledMethod, $alternativeMethod);
$exception = DisabledMethodException::create($disabledMethod, $alternativeMethod);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -16,14 +16,14 @@ use Meritoo\Common\Type\OopVisibilityType;
/**
* Test case of an exception used while name of class or trait cannot be resolved
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class CannotResolveClassNameExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(CannotResolveClassNameException::class, OopVisibilityType::IS_PUBLIC, 2, 1);
static::assertConstructorVisibilityAndArguments(CannotResolveClassNameException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -37,7 +37,7 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($source, $forClass, $expectedMessage)
{
$exception = new CannotResolveClassNameException($source, $forClass);
$exception = CannotResolveClassNameException::create($source, $forClass);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -16,14 +16,14 @@ use Meritoo\Common\Type\OopVisibilityType;
/**
* Test case of an exception used while given class has no child classes
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class MissingChildClassesExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(MissingChildClassesException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(MissingChildClassesException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -35,7 +35,7 @@ class MissingChildClassesExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($parentClass, $expectedMessage)
{
$exception = new MissingChildClassesException($parentClass);
$exception = MissingChildClassesException::create($parentClass);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -16,14 +16,14 @@ use Meritoo\Common\Type\OopVisibilityType;
/**
* Test case of an exception used while given class has more than one child class
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class TooManyChildClassesExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(TooManyChildClassesException::class, OopVisibilityType::IS_PUBLIC, 2, 2);
static::assertConstructorVisibilityAndArguments(TooManyChildClassesException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -36,7 +36,7 @@ class TooManyChildClassesExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($parentClass, array $childClasses, $expectedMessage)
{
$exception = new TooManyChildClassesException($parentClass, $childClasses);
$exception = TooManyChildClassesException::create($parentClass, $childClasses);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -16,14 +16,14 @@ use Meritoo\Common\Type\OopVisibilityType;
/**
* Test case of an exception used while length of given hexadecimal value of color is incorrect
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class IncorrectColorHexLengthExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(IncorrectColorHexLengthException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(IncorrectColorHexLengthException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -34,7 +34,7 @@ class IncorrectColorHexLengthExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($color, $expectedMessage)
{
$exception = new IncorrectColorHexLengthException($color);
$exception = IncorrectColorHexLengthException::create($color);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -10,24 +10,20 @@ namespace Meritoo\Common\Test\Exception\Regex;
use Generator;
use Meritoo\Common\Exception\Regex\InvalidColorHexValueException;
use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException;
use Meritoo\Common\Test\Base\BaseTestCase;
use Meritoo\Common\Type\OopVisibilityType;
/**
* Test case of an exception used while given hexadecimal value of color is invalid
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class InvalidColorHexValueExceptionTest extends BaseTestCase
{
/**
* @throws UnknownOopVisibilityTypeException
*/
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(InvalidColorHexValueException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(InvalidColorHexValueException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -38,7 +34,7 @@ class InvalidColorHexValueExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($color, $expectedMessage)
{
$exception = new InvalidColorHexValueException($color);
$exception = InvalidColorHexValueException::create($color);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -10,24 +10,20 @@ namespace Meritoo\Common\Test\Exception\Regex;
use Generator;
use Meritoo\Common\Exception\Regex\InvalidHtmlAttributesException;
use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException;
use Meritoo\Common\Test\Base\BaseTestCase;
use Meritoo\Common\Type\OopVisibilityType;
/**
* Test case of an exception used while html attributes are invalid
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class InvalidHtmlAttributesExceptionTest extends BaseTestCase
{
/**
* @throws UnknownOopVisibilityTypeException
*/
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(InvalidHtmlAttributesException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(InvalidHtmlAttributesException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -38,7 +34,7 @@ class InvalidHtmlAttributesExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($htmlAttributes, $expectedMessage)
{
$exception = new InvalidHtmlAttributesException($htmlAttributes);
$exception = InvalidHtmlAttributesException::create($htmlAttributes);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -16,14 +16,14 @@ use Meritoo\Common\Type\OopVisibilityType;
/**
* Test case of an exception used while url is invalid
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class InvalidUrlExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(InvalidUrlException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(InvalidUrlException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -34,7 +34,7 @@ class InvalidUrlExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($url, $expectedMessage)
{
$exception = new InvalidUrlException($url);
$exception = InvalidUrlException::create($url);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -17,14 +17,14 @@ use Meritoo\Common\Type\OopVisibilityType;
* Test case of an exception used while the visibility of a property, a method or (as of PHP 7.1.0) a constant is
* unknown
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class UnknownOopVisibilityTypeExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(UnknownOopVisibilityTypeException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(UnknownOopVisibilityTypeException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -35,7 +35,7 @@ class UnknownOopVisibilityTypeExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($unknownType, $expectedMessage)
{
$exception = new UnknownOopVisibilityTypeException($unknownType);
$exception = UnknownOopVisibilityTypeException::createException($unknownType);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -17,8 +17,8 @@ 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
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class BaseTestCaseTest extends BaseTestCase
{
@@ -168,8 +168,8 @@ class BaseTestCaseTest extends BaseTestCase
/**
* Simple test case
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class SimpleTestCase extends BaseTestCase
{

View File

@@ -15,8 +15,8 @@ use Meritoo\Common\Type\Base\BaseType;
/**
* Test case of the base / abstract type of something
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class BaseTypeTest extends BaseTestCase
{
@@ -184,8 +184,8 @@ class BaseTypeTest extends BaseTestCase
/**
* Empty type of something used for testing
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class TestEmptyType extends BaseType
{
@@ -194,8 +194,8 @@ class TestEmptyType extends BaseType
/**
* Type of something used for testing
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class TestType extends BaseType
{

View File

@@ -14,8 +14,8 @@ use Meritoo\Common\Type\DatePartType;
/**
* Test case of the type of date part, e.g. "year"
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class DatePartTypeTest extends BaseTypeTestCase
{

View File

@@ -17,8 +17,8 @@ use Meritoo\Common\Type\OopVisibilityType;
/**
* Test case of date's period
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class DatePeriodTest extends BaseTypeTestCase
{

View File

@@ -14,8 +14,8 @@ use Meritoo\Common\Utilities\Arrays;
/**
* Test case of the useful arrays methods
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class ArraysTest extends BaseTestCase
{

View File

@@ -16,8 +16,8 @@ use Meritoo\Common\Utilities\Bundle;
/**
* Test case of the useful methods for bundle
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class BundleTest extends BaseTestCase
{
@@ -42,7 +42,6 @@ class BundleTest extends BaseTestCase
* @param string $viewPath Path of the view / template, e.g. "MyDirectory/my-template"
* @param string $bundleName Full name of the bundle, e.g. "MyExtraBundle"
*
* @throws IncorrectBundleNameException
* @dataProvider provideViewPathAndIncorrectBundleName
*/
public function testGetBundleViewPathUsingIncorrectBundleName($viewPath, $bundleName)

View File

@@ -15,8 +15,8 @@ use Meritoo\Common\Utilities\Composer;
/**
* Test case of the useful Composer-related methods
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class ComposerTest extends BaseTestCase
{

View File

@@ -11,7 +11,7 @@ namespace Meritoo\Common\Test\Utilities;
use DateInterval;
use DateTime;
use Generator;
use Meritoo\Common\Exception\Date\UnknownDatePartTypeException;
use Meritoo\Common\Exception\Type\UnknownDatePartTypeException;
use Meritoo\Common\Test\Base\BaseTestCase;
use Meritoo\Common\Type\DatePeriod;
use Meritoo\Common\Utilities\Date;
@@ -19,8 +19,8 @@ use Meritoo\Common\Utilities\Date;
/**
* Test case of the Date methods (only static functions)
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class DateTest extends BaseTestCase
{

View File

@@ -14,8 +14,8 @@ use Meritoo\Common\Utilities\GeneratorUtility;
/**
* Test case of the useful methods for the Generator class
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class GeneratorUtilityTest extends BaseTestCase
{

View File

@@ -16,8 +16,8 @@ use ReflectionException;
/**
* Test case of the useful locale methods
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class LocaleTest extends BaseTestCase
{

View File

@@ -15,8 +15,8 @@ use Meritoo\Common\Utilities\MimeTypes;
/**
* Test case of the useful methods for mime types of files
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class MimeTypesTest extends BaseTestCase
{

View File

@@ -20,8 +20,8 @@ use stdClass;
/**
* Test case of the Miscellaneous methods (only static functions)
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class MiscellaneousTest extends BaseTestCase
{

View File

@@ -21,8 +21,8 @@ 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
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class QueryBuilderUtilityTest extends BaseTestCase
{

View File

@@ -12,8 +12,8 @@ namespace Meritoo\Common\Test\Utilities\Reflection;
* The A class.
* Used for testing the Reflection class.
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class A
{

View File

@@ -12,8 +12,8 @@ namespace Meritoo\Common\Test\Utilities\Reflection;
* The B class.
* Used for testing the Reflection class.
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class B extends A implements I
{

View File

@@ -12,8 +12,8 @@ namespace Meritoo\Common\Test\Utilities\Reflection;
* The C class.
* Used for testing the Reflection class.
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class C extends B
{

View File

@@ -12,8 +12,8 @@ namespace Meritoo\Common\Test\Utilities\Reflection;
* The D class.
* Used for testing the Reflection class.
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class D
{

View File

@@ -12,8 +12,8 @@ namespace Meritoo\Common\Test\Utilities\Reflection;
* The E trait.
* Used for testing the Reflection class.
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
trait E
{

View File

@@ -12,8 +12,8 @@ namespace Meritoo\Common\Test\Utilities\Reflection;
* The F class.
* Used for testing the Reflection class.
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class F
{

View File

@@ -12,8 +12,8 @@ namespace Meritoo\Common\Test\Utilities\Reflection;
* The G class.
* Used for testing the Reflection class.
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class G
{

View File

@@ -12,8 +12,8 @@ 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
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class H
{

View File

@@ -12,8 +12,8 @@ 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
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
interface I
{

View File

@@ -30,8 +30,8 @@ use ReflectionProperty;
/**
* Test case of the useful reflection methods
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class ReflectionTest extends BaseTestCase
{

View File

@@ -17,8 +17,8 @@ use ReflectionException;
/**
* Test case of the useful regular expressions methods
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class RegexTest extends BaseTestCase
{

View File

@@ -12,8 +12,8 @@ namespace Meritoo\Common\Test\Utilities\Repository;
* Sortable object/entity.
* Used for testing the Repository class.
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class Sortable
{

View File

@@ -17,8 +17,8 @@ use stdClass;
/**
* Test case of the useful methods for repository
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class RepositoryTest extends BaseTestCase
{

View File

@@ -15,8 +15,8 @@ use Meritoo\Common\Utilities\Uri;
/**
* Test case of the useful uri methods (only static functions)
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class UriTest extends BaseTestCase
{

View File

@@ -15,8 +15,8 @@ use SimpleXMLElement;
/**
* Test case of the useful XML-related methods (only static functions)
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class XmlTest extends BaseTestCase
{

View File

@@ -0,0 +1,188 @@
<?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\Test\Common\ValueObject;
use Generator;
use Meritoo\Common\Test\Base\BaseTestCase;
use Meritoo\Common\Type\OopVisibilityType;
use Meritoo\Common\Utilities\Reflection;
use Meritoo\Common\ValueObject\Version;
/**
* Test case for the version of software
*
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class VersionTest extends BaseTestCase
{
public function testConstructor()
{
static::assertConstructorVisibilityAndArguments(Version::class, OopVisibilityType::IS_PUBLIC, 3, 3);
}
public function testNewInstance()
{
$version = new Version(1, 0, 2);
static::assertInstanceOf(Version::class, $version);
static::assertSame(1, Reflection::getPropertyValue($version, 'majorPart'));
static::assertSame(0, Reflection::getPropertyValue($version, 'minorPart'));
static::assertSame(2, Reflection::getPropertyValue($version, 'patchPart'));
}
/**
* @param Version $version The version
* @param string $expected Expected string
*
* @dataProvider provideConvertedToString
*/
public function testToString(Version $version, $expected)
{
static::assertSame($expected, (string)$version);
}
/**
* @param string $version The version
* @param Version $expected (optional) Expected version
*
* @dataProvider provideAsString
*/
public function testFromString($version, Version $expected = null)
{
static::assertEquals($expected, Version::fromString($version));
}
/**
* @param array $version The version
* @param Version $expected (optional) Expected version
*
* @dataProvider provideAsArray
*/
public function testFromArray(array $version, Version $expected = null)
{
static::assertEquals($expected, Version::fromArray($version));
}
/**
* Provide instance of version and expected version converted to string
*
* @return Generator
*/
public function provideConvertedToString()
{
yield[
new Version(0, 0, 0),
'0.0.0',
];
yield[
new Version(1, 0, 2),
'1.0.2',
];
yield[
new Version(10, 5, 41),
'10.5.41',
];
}
/**
* Provide version as string and expected instance of version
*
* @return Generator
*/
public function provideAsString()
{
yield[
'',
null,
];
yield[
'1.0',
null,
];
yield[
'10',
null,
];
yield[
'0.0.0',
new Version(0, 0, 0),
];
yield[
'1.0.2',
new Version(1, 0, 2),
];
yield[
'10.5.41',
new Version(10, 5, 41),
];
}
/**
* Provide version as array and expected instance of version
*
* @return Generator
*/
public function provideAsArray()
{
yield[
[],
null,
];
yield[
[
1,
0,
],
null,
];
yield[
[
10,
],
null,
];
yield[
[
0,
0,
0,
],
new Version(0, 0, 0),
];
yield[
[
1,
0,
2,
],
new Version(1, 0, 2),
];
yield[
[
10,
5,
41,
],
new Version(10, 5, 41),
];
}
}