mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 17:41:50 +01:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c70fdd673 | ||
|
|
204e8793ac | ||
|
|
3dd37ae202 | ||
|
|
ef017c9d6a | ||
|
|
5030dc2062 | ||
|
|
2c76158093 | ||
|
|
0b560fdf18 | ||
|
|
284d403061 | ||
|
|
7dbb3f9b2e | ||
|
|
fba821b798 | ||
|
|
3985c70076 | ||
|
|
921d4e6106 | ||
|
|
7aa2239dbd | ||
|
|
e1fefcdeae | ||
|
|
94a464cb4d | ||
|
|
463ee751b2 | ||
|
|
89af7145f6 | ||
|
|
09c8569938 | ||
|
|
5ab2cd9de8 | ||
|
|
60eff29e82 | ||
|
|
5aa5ff4380 | ||
|
|
6483a8f5b7 | ||
|
|
5c0ef79b15 | ||
|
|
324f64f912 | ||
|
|
5940ebba9a | ||
|
|
787b8c697c | ||
|
|
96c02cdc3d | ||
|
|
87d7bff5f5 | ||
|
|
bd7c874e88 | ||
|
|
e1ffb78214 | ||
|
|
d4dc274763 |
8
.styleci.yml
Normal file
8
.styleci.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
preset: symfony
|
||||||
|
|
||||||
|
disabled:
|
||||||
|
- phpdoc_annotation_without_dot
|
||||||
|
- cast_spaces
|
||||||
|
- concat_without_spaces
|
||||||
|
- blank_line_before_return
|
||||||
|
- trim_array_spaces
|
||||||
12
.travis.yml
Normal file
12
.travis.yml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
language: php
|
||||||
|
|
||||||
|
php:
|
||||||
|
- 5.6
|
||||||
|
- 7.0
|
||||||
|
- 7.1
|
||||||
|
|
||||||
|
install:
|
||||||
|
- composer install
|
||||||
|
|
||||||
|
script:
|
||||||
|
- php ./vendor/bin/phpunit
|
||||||
98
README.md
98
README.md
@@ -1,25 +1,105 @@
|
|||||||
# Meritoo Common Library
|
# Meritoo Common Library
|
||||||
Useful classes, methods, extensions etc.
|
Common and useful classes, methods, exceptions etc.
|
||||||
|
|
||||||
|
[](https://travis-ci.org/meritoo/common-library) [](https://packagist.org/packages/meritoo/common-library) [](https://styleci.io/repos/101790028) [](https://github.com/meritoo/common-library) [](https://github.com/meritoo/common-library) [](https://coveralls.io/github/meritoo/common-library?branch=master)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Run [Composer](https://getcomposer.org) to install new package:
|
Run [Composer](https://getcomposer.org) to install this package in your project:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ composer require meritoo/common-library
|
$ composer require meritoo/common-library
|
||||||
```
|
```
|
||||||
|
|
||||||
> How to install Composer: https://getcomposer.org/download
|
> How to install Composer: https://getcomposer.org/download
|
||||||
|
|
||||||
## Usage
|
## Static methods
|
||||||
|
|
||||||
This package contains a lot of 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:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
use Meritoo\Common\Utilities\Arrays;
|
use Meritoo\Common\Utilities\Arrays;
|
||||||
|
|
||||||
$firstElement = Arrays::getFirstElement(['lorem' 'ipsum']);
|
$firstElement = Arrays::getFirstElement(['lorem', 'ipsum']);
|
||||||
// result: "lorem"
|
var_dump($firstElement); // string(5) "lorem"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Base test case with common methods and data providers
|
||||||
|
|
||||||
|
Located here: `Meritoo\Common\Test\Base\BaseTestCase`. Just extend the `BaseTestCase` class and use it like in `Meritoo\Common\Test\Utilities\DateTest` class:
|
||||||
|
|
||||||
|
```php
|
||||||
|
class DateTest extends BaseTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param mixed $value Empty value, e.g. ""
|
||||||
|
* @dataProvider provideEmptyValue
|
||||||
|
*/
|
||||||
|
public function testGetDateTimeEmptyValue($value)
|
||||||
|
{
|
||||||
|
self::assertFalse(Date::getDateTime($value));
|
||||||
|
}
|
||||||
|
|
||||||
|
(...)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
or in `Meritoo\Common\Test\Utilities\MimeTypesTest` class:
|
||||||
|
|
||||||
|
```php
|
||||||
|
class MimeTypesTest extends BaseTestCase
|
||||||
|
{
|
||||||
|
(...)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param bool $mimeType The mime type, e.g. "video/mpeg"
|
||||||
|
* @dataProvider provideBooleanValue
|
||||||
|
*/
|
||||||
|
public function testGetExtensionBooleanMimeType($mimeType)
|
||||||
|
{
|
||||||
|
self::assertEquals('', MimeTypes::getExtension($mimeType));
|
||||||
|
}
|
||||||
|
|
||||||
|
(...)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Collection of elements
|
||||||
|
|
||||||
|
Located here: `Meritoo\Common\Collection\Collection`. It's a set of some elements, e.g. objects. It's iterable and countable. Provides very useful methods. Some of them:
|
||||||
|
- `getFirst()` - returns the first element in the collection
|
||||||
|
- `getLast()` - returns the last element in the collection
|
||||||
|
- `isEmpty()` - returns information if collection is empty
|
||||||
|
- `add($element, $index = null)` - adds given element (at the end of collection)
|
||||||
|
- `addMultiple($elements, $useIndexes = false)` - adds given elements (at the end of collection)
|
||||||
|
- `prepend($element)` - prepends given element (adds given element at the beginning of collection)
|
||||||
|
- `remove($element)` - removes given element
|
||||||
|
|
||||||
|
Examples of usage below.
|
||||||
|
|
||||||
|
#### An empty collection
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Meritoo\Common\Collection\Collection;
|
||||||
|
|
||||||
|
$emptyCollection = new Collection();
|
||||||
|
var_dump($emptyCollection->isEmpty()); // bool(true)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Simple collection
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Meritoo\Common\Collection\Collection;
|
||||||
|
|
||||||
|
$elements = [
|
||||||
|
'lorem',
|
||||||
|
'ipsum',
|
||||||
|
123 => 'dolor',
|
||||||
|
345 => 'sit',
|
||||||
|
];
|
||||||
|
|
||||||
|
$simpleCollection = new Collection($elements);
|
||||||
|
var_dump($simpleCollection->has('dolor')); // bool(true)
|
||||||
```
|
```
|
||||||
|
|
||||||
Enjoy!
|
Enjoy!
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project name="Meritoo Common Library" 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"/>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "meritoo/common-library",
|
"name": "meritoo/common-library",
|
||||||
"description": "Useful classes, methods, extensions etc.",
|
"description": "Useful classes, methods, extensions etc.",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "0.0.2",
|
"version": "0.0.10",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Meritoo.pl",
|
"name": "Meritoo.pl",
|
||||||
@@ -17,18 +17,18 @@
|
|||||||
"symfony/http-foundation": "^3.3"
|
"symfony/http-foundation": "^3.3"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^4.8 || ^5.0",
|
"phpunit/phpunit": "^5.7",
|
||||||
"squizlabs/php_codesniffer": "^2.8",
|
"squizlabs/php_codesniffer": "^2.9",
|
||||||
"phpmd/phpmd": "^2.6",
|
"phpmd/phpmd": "^2.6",
|
||||||
"sebastian/phpcpd": "^3.0",
|
"sebastian/phpcpd": "^3.0",
|
||||||
"pdepend/pdepend": "^2.5",
|
"pdepend/pdepend": "^2.5",
|
||||||
"phploc/phploc": "^3.0",
|
"phploc/phploc": "^4.0",
|
||||||
"friendsofphp/php-cs-fixer": "^2.1"
|
"friendsofphp/php-cs-fixer": "^2.6"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Meritoo\\Common\\": "src/Meritoo/Common/",
|
"Meritoo\\Common\\": "src/Meritoo/Common/",
|
||||||
"Meritoo\\Common\\Tests\\": "tests/Meritoo/Common/Tests/"
|
"Meritoo\\Common\\Test\\": "tests/Meritoo/Common/Test/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
550
composer.lock
generated
550
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project name="Meritoo Common Library" 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"/>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project name="Meritoo Common Library" basedir="." default="build:main" phingVersion="2.14.0">
|
<project name="Meritoo Package" basedir="." default="build:main" phingVersion="2.14.0">
|
||||||
<!--
|
<!--
|
||||||
The AutoloaderTask is required to load binaries installed by Composer.
|
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.
|
The "autoloaderpath" attribute of this task is not required, because it's default value is: vendor/autoload.php.
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
bootstrap="./vendor/autoload.php"
|
bootstrap="./vendor/autoload.php"
|
||||||
>
|
>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="Meritoo's Common Library Test Suite">
|
<testsuite name="Meritoo Package - Main Test Suite">
|
||||||
<directory>./tests/</directory>
|
<directory>./tests/</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
|
|||||||
284
src/Meritoo/Common/Collection/Collection.php
Normal file
284
src/Meritoo/Common/Collection/Collection.php
Normal file
@@ -0,0 +1,284 @@
|
|||||||
|
<?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\Collection;
|
||||||
|
|
||||||
|
use ArrayAccess;
|
||||||
|
use ArrayIterator;
|
||||||
|
use Countable;
|
||||||
|
use IteratorAggregate;
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
class Collection implements Countable, ArrayAccess, IteratorAggregate
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The elements of collection
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $elements;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor
|
||||||
|
*
|
||||||
|
* @param array $elements (optional) The elements of collection
|
||||||
|
*/
|
||||||
|
public function __construct(array $elements = [])
|
||||||
|
{
|
||||||
|
$this->elements = $elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
* Required by interface Countable
|
||||||
|
*/
|
||||||
|
public function count()
|
||||||
|
{
|
||||||
|
return count($this->elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
* Required by interface ArrayAccess
|
||||||
|
*/
|
||||||
|
public function offsetExists($offset)
|
||||||
|
{
|
||||||
|
return $this->exists($offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
* Required by interface ArrayAccess
|
||||||
|
*/
|
||||||
|
public function offsetGet($offset)
|
||||||
|
{
|
||||||
|
if ($this->exists($offset)) {
|
||||||
|
return $this->elements[$offset];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
* Required by interface ArrayAccess
|
||||||
|
*/
|
||||||
|
public function offsetSet($offset, $value)
|
||||||
|
{
|
||||||
|
$this->elements[$offset] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
* Required by interface ArrayAccess
|
||||||
|
*/
|
||||||
|
public function offsetUnset($offset)
|
||||||
|
{
|
||||||
|
if ($this->exists($offset)) {
|
||||||
|
unset($this->elements[$offset]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
* Required by interface IteratorAggregate
|
||||||
|
*/
|
||||||
|
public function getIterator()
|
||||||
|
{
|
||||||
|
return new ArrayIterator($this->elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds given element (at the end of collection)
|
||||||
|
*
|
||||||
|
* @param mixed $element The element to add
|
||||||
|
* @param mixed $index (optional) Index / key of the element
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function add($element, $index = null)
|
||||||
|
{
|
||||||
|
if (null === $index) {
|
||||||
|
$this->elements[] = $element;
|
||||||
|
} else {
|
||||||
|
$this->elements[$index] = $element;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds given elements (at the end of collection)
|
||||||
|
*
|
||||||
|
* @param array|Collection $elements The elements to add
|
||||||
|
* @param bool|false $useIndexes (optional) If is set to true, indexes of given elements will be used in
|
||||||
|
* this collection. Otherwise - not.
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function addMultiple($elements, $useIndexes = false)
|
||||||
|
{
|
||||||
|
if (!empty($elements)) {
|
||||||
|
foreach ($elements as $index => $element) {
|
||||||
|
if (!$useIndexes) {
|
||||||
|
$index = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->add($element, $index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepends given element (adds given element at the beginning of collection)
|
||||||
|
*
|
||||||
|
* @param mixed $element The element to prepend
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function prepend($element)
|
||||||
|
{
|
||||||
|
array_unshift($this->elements, $element);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes given element
|
||||||
|
*
|
||||||
|
* @param mixed $element The element to remove
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function remove($element)
|
||||||
|
{
|
||||||
|
if ($this->count() > 0) {
|
||||||
|
foreach ($this->elements as $index => $existing) {
|
||||||
|
if ($element === $existing) {
|
||||||
|
unset($this->elements[$index]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns information if collection is empty
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isEmpty()
|
||||||
|
{
|
||||||
|
return empty($this->elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns information if given element is first in the collection
|
||||||
|
*
|
||||||
|
* @param mixed $element The element to verify
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isFirst($element)
|
||||||
|
{
|
||||||
|
return reset($this->elements) === $element;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns information if given element is last in the collection
|
||||||
|
*
|
||||||
|
* @param mixed $element The element to verify
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isLast($element)
|
||||||
|
{
|
||||||
|
return end($this->elements) === $element;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns information if the collection has given element, iow. if given element exists in the collection
|
||||||
|
*
|
||||||
|
* @param mixed $element The element to verify
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function has($element)
|
||||||
|
{
|
||||||
|
$index = Arrays::getIndexOf($this->elements, $element);
|
||||||
|
|
||||||
|
return null !== $index && false !== $index;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns previous element for given element
|
||||||
|
*
|
||||||
|
* @param mixed $element The element to verify
|
||||||
|
* @return mixed|null
|
||||||
|
*/
|
||||||
|
public function getPrevious($element)
|
||||||
|
{
|
||||||
|
return Arrays::getPreviousElement($this->elements, $element);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns next element for given element
|
||||||
|
*
|
||||||
|
* @param mixed $element The element to verify
|
||||||
|
* @return mixed|null
|
||||||
|
*/
|
||||||
|
public function getNext($element)
|
||||||
|
{
|
||||||
|
return Arrays::getNextElement($this->elements, $element);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the first element in the collection
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getFirst()
|
||||||
|
{
|
||||||
|
return Arrays::getFirstElement($this->elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the last element in the collection
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getLast()
|
||||||
|
{
|
||||||
|
return Arrays::getLastElement($this->elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array representation of the collection
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray()
|
||||||
|
{
|
||||||
|
return $this->elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns information if element with given index/key exists
|
||||||
|
*
|
||||||
|
* @param string|int $index The index/key of element
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function exists($index)
|
||||||
|
{
|
||||||
|
return isset($this->elements[$index]) || array_key_exists($index, $this->elements);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An exception used while given part of date is incorrect, e.g. value of year is incorrect
|
|
||||||
*
|
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
|
||||||
* @copyright Meritoo.pl
|
|
||||||
*/
|
|
||||||
class IncorrectDatePartException extends Exception
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Class constructor
|
|
||||||
*
|
|
||||||
* @param string $value Incorrect value
|
|
||||||
* @param string $datePart Type of date part, e.g. "year". One of \Meritoo\Common\Type\DatePartType class constants.
|
|
||||||
*/
|
|
||||||
public function __construct($value, $datePart)
|
|
||||||
{
|
|
||||||
$message = sprintf('Value of %s \'%s\' is incorrect. Is there everything ok?', $datePart, $value);
|
|
||||||
parent::__construct($message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?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));
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/Meritoo/Common/Exception/File/EmptyFileException.php
Normal file
31
src/Meritoo/Common/Exception/File/EmptyFileException.php
Normal file
@@ -0,0 +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\File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An exception used while file with given path is empty (has no content)
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
class EmptyFileException extends \Exception
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Class constructor
|
||||||
|
*
|
||||||
|
* @param string $emptyFilePath Path of the empty file
|
||||||
|
*/
|
||||||
|
public function __construct($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);
|
||||||
|
}
|
||||||
|
}
|
||||||
26
src/Meritoo/Common/Exception/File/EmptyFilePathException.php
Normal file
26
src/Meritoo/Common/Exception/File/EmptyFilePathException.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?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\File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An exception used while path of given file is empty
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
class EmptyFilePathException extends \Exception
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Class constructor
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct('Path of the file is empty. Did you provide path of proper file?');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +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\File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An exception used while file with given path does not exist
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
class NotExistingFileException extends \Exception
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Class constructor
|
||||||
|
*
|
||||||
|
* @param string $notExistingFilePath Path of not existing (or not readable) file
|
||||||
|
*/
|
||||||
|
public function __construct($notExistingFilePath)
|
||||||
|
{
|
||||||
|
$template = 'File with path \'%s\' does not exist (or is not readable). Did you provide proper path of file?';
|
||||||
|
$message = sprintf($template, $notExistingFilePath);
|
||||||
|
|
||||||
|
parent::__construct($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Meritoo\Common\Exception\Type;
|
||||||
|
|
||||||
|
use Meritoo\Common\Exception\Base\UnknownTypeException;
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
class UnknownOopVisibilityTypeException extends UnknownTypeException
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function __construct($unknownType)
|
||||||
|
{
|
||||||
|
parent::__construct($unknownType, new OopVisibilityType(), 'OOP-related visibility');
|
||||||
|
}
|
||||||
|
}
|
||||||
205
src/Meritoo/Common/Test/Base/BaseTestCase.php
Normal file
205
src/Meritoo/Common/Test/Base/BaseTestCase.php
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Meritoo\Common\Test\Base;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use Generator;
|
||||||
|
use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException;
|
||||||
|
use Meritoo\Common\Type\OopVisibilityType;
|
||||||
|
use Meritoo\Common\Utilities\Miscellaneous;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use ReflectionClass;
|
||||||
|
use ReflectionMethod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base test case with common methods and data providers
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
abstract class BaseTestCase extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 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 function verifyMethodVisibilityAndArguments(
|
||||||
|
$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 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
|
||||||
|
*/
|
||||||
|
protected function verifyConstructorVisibilityAndArguments(
|
||||||
|
$classNamespace,
|
||||||
|
$visibilityType,
|
||||||
|
$argumentsCount = 0,
|
||||||
|
$requiredArgumentsCount = 0
|
||||||
|
) {
|
||||||
|
/*
|
||||||
|
* Let's grab the constructor
|
||||||
|
*/
|
||||||
|
$reflection = new ReflectionClass($classNamespace);
|
||||||
|
$method = $reflection->getConstructor();
|
||||||
|
|
||||||
|
return $this->verifyMethodVisibilityAndArguments($classNamespace, $method, $visibilityType, $argumentsCount, $requiredArgumentsCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
60
src/Meritoo/Common/Test/Base/BaseTypeTestCase.php
Normal file
60
src/Meritoo/Common/Test/Base/BaseTypeTestCase.php
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Meritoo\Common\Test\Base;
|
||||||
|
|
||||||
|
use Generator;
|
||||||
|
use Meritoo\Common\Type\Base\BaseType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base test case for the type of something
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
abstract class BaseTypeTestCase extends BaseTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 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 @@ abstract class BaseType
|
|||||||
*/
|
*/
|
||||||
public function getAll()
|
public function getAll()
|
||||||
{
|
{
|
||||||
if ($this->all === null) {
|
if (null === $this->all) {
|
||||||
$this->all = Reflection::getConstants($this);
|
$this->all = Reflection::getConstants($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
<?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\Type;
|
namespace Meritoo\Common\Type;
|
||||||
|
|
||||||
use Meritoo\Common\Type\Base\BaseType;
|
use Meritoo\Common\Type\Base\BaseType;
|
||||||
|
|||||||
37
src/Meritoo/Common/Type/OopVisibilityType.php
Normal file
37
src/Meritoo/Common/Type/OopVisibilityType.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Meritoo\Common\Type;
|
||||||
|
|
||||||
|
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
|
||||||
|
*
|
||||||
|
* @see http://php.net/manual/en/language.oop5.visibility.php
|
||||||
|
*/
|
||||||
|
class OopVisibilityType extends BaseType
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The "private" visibility of OOP
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
const IS_PRIVATE = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The "protected" visibility of OOP
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
const IS_PROTECTED = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The "public" visibility of OOP
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
const IS_PUBLIC = 1;
|
||||||
|
}
|
||||||
@@ -415,7 +415,7 @@ class Arrays
|
|||||||
* var autoGeneratedVariable = new Array(...);autoGeneratedVariable[0] = new Array(...);
|
* var autoGeneratedVariable = new Array(...);autoGeneratedVariable[0] = new Array(...);
|
||||||
* autoGeneratedVariable[1] = new Array(...);
|
* autoGeneratedVariable[1] = new Array(...);
|
||||||
*/
|
*/
|
||||||
if ($counter === 1) {
|
if (1 === $counter) {
|
||||||
$effect .= "\n";
|
$effect .= "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -758,7 +758,7 @@ class Arrays
|
|||||||
foreach ($exploded as $item) {
|
foreach ($exploded as $item) {
|
||||||
$exploded2 = explode($valuesKeysSeparator, $item);
|
$exploded2 = explode($valuesKeysSeparator, $item);
|
||||||
|
|
||||||
if (count($exploded2) == 2) {
|
if (2 == count($exploded2)) {
|
||||||
$key = trim($exploded2[0]);
|
$key = trim($exploded2[0]);
|
||||||
$value = trim($exploded2[1]);
|
$value = trim($exploded2[1]);
|
||||||
|
|
||||||
@@ -1124,7 +1124,7 @@ class Arrays
|
|||||||
if (!empty($array)) {
|
if (!empty($array)) {
|
||||||
$childPosition = 1;
|
$childPosition = 1;
|
||||||
|
|
||||||
if ($startPosition !== null) {
|
if (null !== $startPosition) {
|
||||||
$array[$keyName] = $startPosition;
|
$array[$keyName] = $startPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1316,7 +1316,7 @@ class Arrays
|
|||||||
*
|
*
|
||||||
* If one of the above is true, not all elements of given array are empty
|
* If one of the above is true, not all elements of given array are empty
|
||||||
*/
|
*/
|
||||||
if ((!is_array($element) && $strictNull && $element !== null) || !empty($element)) {
|
if ((!is_array($element) && $strictNull && null !== $element) || !empty($element)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1353,7 +1353,7 @@ class Arrays
|
|||||||
* Values should be compared only and both arrays are one-dimensional?
|
* Values should be compared only and both arrays are one-dimensional?
|
||||||
* Let's find difference by using simple function
|
* Let's find difference by using simple function
|
||||||
*/
|
*/
|
||||||
if ($valuesOnly && self::getDimensionsCount($array1) == 1 && self::getDimensionsCount($array2) == 1) {
|
if ($valuesOnly && 1 == self::getDimensionsCount($array1) && 1 == self::getDimensionsCount($array2)) {
|
||||||
return array_diff($array1, $array2);
|
return array_diff($array1, $array2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1381,7 +1381,7 @@ class Arrays
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($difference !== null) {
|
if (null !== $difference) {
|
||||||
$effect[] = $difference;
|
$effect[] = $difference;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1472,7 +1472,7 @@ class Arrays
|
|||||||
* Start index not provided?
|
* Start index not provided?
|
||||||
* Let's look for the first index / key of given array
|
* Let's look for the first index / key of given array
|
||||||
*/
|
*/
|
||||||
if ($startIndex === null) {
|
if (null === $startIndex) {
|
||||||
$startIndex = self::getFirstKey($array);
|
$startIndex = self::getFirstKey($array);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1617,7 +1617,7 @@ class Arrays
|
|||||||
* Index of element or of element's key is unknown?
|
* Index of element or of element's key is unknown?
|
||||||
* Probably the element does not exist in given array, so... nothing to do
|
* Probably the element does not exist in given array, so... nothing to do
|
||||||
*/
|
*/
|
||||||
if ($elementKey === null || $indexOfKey === null) {
|
if (null === $elementKey || null === $indexOfKey) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class Composer
|
|||||||
* Unknown data from the composer.json file or there is no node with given name?
|
* Unknown data from the composer.json file or there is no node with given name?
|
||||||
* Nothing to do
|
* Nothing to do
|
||||||
*/
|
*/
|
||||||
if ($data === null || !isset($data->{$nodeName})) {
|
if (null === $data || !isset($data->{$nodeName})) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace Meritoo\Common\Utilities;
|
|||||||
|
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Meritoo\Common\Exception\Date\IncorrectDatePartException;
|
use Meritoo\Common\Exception\Date\UnknownDatePartTypeException;
|
||||||
use Meritoo\Common\Type\DatePartType;
|
use Meritoo\Common\Type\DatePartType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,10 +129,10 @@ class Date
|
|||||||
$dateStart = new DateTime();
|
$dateStart = new DateTime();
|
||||||
$dateEnd = new DateTime();
|
$dateEnd = new DateTime();
|
||||||
|
|
||||||
if ($period == DatePeriod::LAST_YEAR || $period == DatePeriod::NEXT_YEAR) {
|
if (DatePeriod::LAST_YEAR == $period || DatePeriod::NEXT_YEAR == $period) {
|
||||||
$yearDifference = 1;
|
$yearDifference = 1;
|
||||||
|
|
||||||
if ($period == DatePeriod::LAST_YEAR) {
|
if (DatePeriod::LAST_YEAR == $period) {
|
||||||
$yearDifference *= -1;
|
$yearDifference *= -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ class Date
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dateStart !== null && $dateEnd !== null) {
|
if (null !== $dateStart && null !== $dateEnd) {
|
||||||
$dateStart->setTime(0, 0, 0);
|
$dateStart->setTime(0, 0, 0);
|
||||||
$dateEnd->setTime(23, 59, 59);
|
$dateEnd->setTime(23, 59, 59);
|
||||||
|
|
||||||
@@ -231,7 +231,7 @@ class Date
|
|||||||
* @param int $day The day value
|
* @param int $day The day value
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
* @throws IncorrectDatePartException
|
* @throws UnknownDatePartTypeException
|
||||||
*/
|
*/
|
||||||
public static function getDayOfWeek($year, $month, $day)
|
public static function getDayOfWeek($year, $month, $day)
|
||||||
{
|
{
|
||||||
@@ -243,21 +243,21 @@ class Date
|
|||||||
* Oops, incorrect year
|
* Oops, incorrect year
|
||||||
*/
|
*/
|
||||||
if ($year <= 0) {
|
if ($year <= 0) {
|
||||||
throw new IncorrectDatePartException($year, DatePartType::YEAR);
|
throw new UnknownDatePartTypeException(DatePartType::YEAR, $year);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Oops, incorrect month
|
* Oops, incorrect month
|
||||||
*/
|
*/
|
||||||
if ($month < 1 || $month > 12) {
|
if ($month < 1 || $month > 12) {
|
||||||
throw new IncorrectDatePartException($month, DatePartType::MONTH);
|
throw new UnknownDatePartTypeException(DatePartType::MONTH, $month);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Oops, incorrect day
|
* Oops, incorrect day
|
||||||
*/
|
*/
|
||||||
if ($day < 1 || $day > 31) {
|
if ($day < 1 || $day > 31) {
|
||||||
throw new IncorrectDatePartException($day, DatePartType::DAY);
|
throw new UnknownDatePartTypeException(DatePartType::DAY, $day);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($month < 3) {
|
if ($month < 3) {
|
||||||
@@ -311,7 +311,7 @@ class Date
|
|||||||
|
|
||||||
$encoding = mb_detect_encoding($name);
|
$encoding = mb_detect_encoding($name);
|
||||||
|
|
||||||
if ($encoding === false) {
|
if (false === $encoding) {
|
||||||
$name = mb_convert_encoding($name, 'UTF-8', 'ISO-8859-2');
|
$name = mb_convert_encoding($name, 'UTF-8', 'ISO-8859-2');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,46 +378,46 @@ class Date
|
|||||||
self::DATE_DIFFERENCE_UNIT_MINUTES,
|
self::DATE_DIFFERENCE_UNIT_MINUTES,
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($differenceUnit === null || $differenceUnit == self::DATE_DIFFERENCE_UNIT_YEARS) {
|
if (null === $differenceUnit || self::DATE_DIFFERENCE_UNIT_YEARS == $differenceUnit) {
|
||||||
$diff = $dateEnd->diff($dateStart);
|
$diff = $dateEnd->diff($dateStart);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Difference between dates in years should be returned only?
|
* Difference between dates in years should be returned only?
|
||||||
*/
|
*/
|
||||||
if ($differenceUnit == self::DATE_DIFFERENCE_UNIT_YEARS) {
|
if (self::DATE_DIFFERENCE_UNIT_YEARS == $differenceUnit) {
|
||||||
return $diff->y;
|
return $diff->y;
|
||||||
}
|
}
|
||||||
|
|
||||||
$difference[self::DATE_DIFFERENCE_UNIT_YEARS] = $diff->y;
|
$difference[self::DATE_DIFFERENCE_UNIT_YEARS] = $diff->y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($differenceUnit === null || $differenceUnit == self::DATE_DIFFERENCE_UNIT_MONTHS) {
|
if (null === $differenceUnit || self::DATE_DIFFERENCE_UNIT_MONTHS == $differenceUnit) {
|
||||||
$diff = $dateEnd->diff($dateStart);
|
$diff = $dateEnd->diff($dateStart);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Difference between dates in months should be returned only?
|
* Difference between dates in months should be returned only?
|
||||||
*/
|
*/
|
||||||
if ($differenceUnit == self::DATE_DIFFERENCE_UNIT_MONTHS) {
|
if (self::DATE_DIFFERENCE_UNIT_MONTHS == $differenceUnit) {
|
||||||
return $diff->m;
|
return $diff->m;
|
||||||
}
|
}
|
||||||
|
|
||||||
$difference[self::DATE_DIFFERENCE_UNIT_MONTHS] = $diff->m;
|
$difference[self::DATE_DIFFERENCE_UNIT_MONTHS] = $diff->m;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($differenceUnit === null || in_array($differenceUnit, $relatedUnits)) {
|
if (null === $differenceUnit || in_array($differenceUnit, $relatedUnits)) {
|
||||||
$days = (int)floor($dateDiff / $daySeconds);
|
$days = (int)floor($dateDiff / $daySeconds);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Difference between dates in days should be returned only?
|
* Difference between dates in days should be returned only?
|
||||||
*/
|
*/
|
||||||
if ($differenceUnit == self::DATE_DIFFERENCE_UNIT_DAYS) {
|
if (self::DATE_DIFFERENCE_UNIT_DAYS == $differenceUnit) {
|
||||||
return $days;
|
return $days;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* All units should be returned?
|
* All units should be returned?
|
||||||
*/
|
*/
|
||||||
if ($differenceUnit === null) {
|
if (null === $differenceUnit) {
|
||||||
$difference[self::DATE_DIFFERENCE_UNIT_DAYS] = $days;
|
$difference[self::DATE_DIFFERENCE_UNIT_DAYS] = $days;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,20 +427,20 @@ class Date
|
|||||||
$daysInSeconds = $days * $daySeconds;
|
$daysInSeconds = $days * $daySeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($differenceUnit === null || in_array($differenceUnit, $relatedUnits)) {
|
if (null === $differenceUnit || in_array($differenceUnit, $relatedUnits)) {
|
||||||
$hours = (int)floor(($dateDiff - $daysInSeconds) / $hourSeconds);
|
$hours = (int)floor(($dateDiff - $daysInSeconds) / $hourSeconds);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Difference between dates in hours should be returned only?
|
* Difference between dates in hours should be returned only?
|
||||||
*/
|
*/
|
||||||
if ($differenceUnit == self::DATE_DIFFERENCE_UNIT_HOURS) {
|
if (self::DATE_DIFFERENCE_UNIT_HOURS == $differenceUnit) {
|
||||||
return $hours;
|
return $hours;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* All units should be returned?
|
* All units should be returned?
|
||||||
*/
|
*/
|
||||||
if ($differenceUnit === null) {
|
if (null === $differenceUnit) {
|
||||||
$difference[self::DATE_DIFFERENCE_UNIT_HOURS] = $hours;
|
$difference[self::DATE_DIFFERENCE_UNIT_HOURS] = $hours;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,13 +450,13 @@ class Date
|
|||||||
$hoursInSeconds = $hours * $hourSeconds;
|
$hoursInSeconds = $hours * $hourSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($differenceUnit === null || $differenceUnit == self::DATE_DIFFERENCE_UNIT_MINUTES) {
|
if (null === $differenceUnit || self::DATE_DIFFERENCE_UNIT_MINUTES == $differenceUnit) {
|
||||||
$minutes = (int)floor(($dateDiff - $daysInSeconds - $hoursInSeconds) / 60);
|
$minutes = (int)floor(($dateDiff - $daysInSeconds - $hoursInSeconds) / 60);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Difference between dates in minutes should be returned only?
|
* Difference between dates in minutes should be returned only?
|
||||||
*/
|
*/
|
||||||
if ($differenceUnit == self::DATE_DIFFERENCE_UNIT_MINUTES) {
|
if (self::DATE_DIFFERENCE_UNIT_MINUTES == $differenceUnit) {
|
||||||
return $minutes;
|
return $minutes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,7 +524,7 @@ class Date
|
|||||||
*/
|
*/
|
||||||
public static function getRandomDate(DateTime $startDate = null, $start = 1, $end = 100, $intervalTemplate = 'P%sD')
|
public static function getRandomDate(DateTime $startDate = null, $start = 1, $end = 100, $intervalTemplate = 'P%sD')
|
||||||
{
|
{
|
||||||
if ($startDate === null) {
|
if (null === $startDate) {
|
||||||
$startDate = new DateTime();
|
$startDate = new DateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -590,7 +590,7 @@ class Date
|
|||||||
*/
|
*/
|
||||||
$dateFromFormat = DateTime::createFromFormat($dateFormat, $value);
|
$dateFromFormat = DateTime::createFromFormat($dateFormat, $value);
|
||||||
|
|
||||||
if ($dateFromFormat === false) {
|
if (false === $dateFromFormat) {
|
||||||
/*
|
/*
|
||||||
* Nothing to do more, because:
|
* Nothing to do more, because:
|
||||||
* a) instance of the DateTime was created
|
* a) instance of the DateTime was created
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ class DatePeriod
|
|||||||
/*
|
/*
|
||||||
* Unknown date or format is invalid?
|
* Unknown date or format is invalid?
|
||||||
*/
|
*/
|
||||||
if ($date === null || !Date::isValidDateFormat($format)) {
|
if (null === $date || !Date::isValidDateFormat($format)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class Miscellaneous
|
|||||||
|
|
||||||
if (!empty($directoryContent)) {
|
if (!empty($directoryContent)) {
|
||||||
foreach ($directoryContent as $fileName) {
|
foreach ($directoryContent as $fileName) {
|
||||||
if ($fileName != '.' && $fileName != '..') {
|
if ('.' != $fileName && '..' != $fileName) {
|
||||||
$content = null;
|
$content = null;
|
||||||
|
|
||||||
if (!empty($startFileName) && !$startFileFound) {
|
if (!empty($startFileName) && !$startFileFound) {
|
||||||
@@ -80,7 +80,7 @@ class Miscellaneous
|
|||||||
$content = self::getDirectoryContent($directoryPath . $fileName, true, $maxFilesCount - $count);
|
$content = self::getDirectoryContent($directoryPath . $fileName, true, $maxFilesCount - $count);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($content !== null) {
|
if (null !== $content) {
|
||||||
$files[$fileName] = $content;
|
$files[$fileName] = $content;
|
||||||
|
|
||||||
if (!empty($maxFilesCount)) {
|
if (!empty($maxFilesCount)) {
|
||||||
@@ -365,7 +365,7 @@ class Miscellaneous
|
|||||||
* Oops, cannot instantiate converter
|
* Oops, cannot instantiate converter
|
||||||
* Nothing to do
|
* Nothing to do
|
||||||
*/
|
*/
|
||||||
if ($converter === null) {
|
if (null === $converter) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,7 +460,7 @@ class Miscellaneous
|
|||||||
* Value to find is neither a string nor an array OR it's an empty string?
|
* Value to find is neither a string nor an array OR it's an empty string?
|
||||||
* Nothing to do
|
* Nothing to do
|
||||||
*/
|
*/
|
||||||
if ((!$searchIsString && !$searchIsArray) || ($searchIsString && strlen($search) == 0)) {
|
if ((!$searchIsString && !$searchIsArray) || ($searchIsString && 0 == strlen($search))) {
|
||||||
return $effect;
|
return $effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -612,7 +612,7 @@ class Miscellaneous
|
|||||||
$effect = mb_substr($text, 0, $maxLength, 'utf-8');
|
$effect = mb_substr($text, 0, $maxLength, 'utf-8');
|
||||||
$lastSpacePosition = mb_strrpos($effect, ' ', 'utf-8');
|
$lastSpacePosition = mb_strrpos($effect, ' ', 'utf-8');
|
||||||
|
|
||||||
if ($lastSpacePosition !== false) {
|
if (false !== $lastSpacePosition) {
|
||||||
$effect = mb_substr($effect, 0, $lastSpacePosition, 'utf-8');
|
$effect = mb_substr($effect, 0, $lastSpacePosition, 'utf-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -730,7 +730,7 @@ class Miscellaneous
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (scandir($directoryPath) as $item) {
|
foreach (scandir($directoryPath) as $item) {
|
||||||
if ($item == '.' || $item == '..') {
|
if ('.' == $item || '..' == $item) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -776,7 +776,7 @@ class Miscellaneous
|
|||||||
foreach ($members as $key => $value) {
|
foreach ($members as $key => $value) {
|
||||||
$value = mb_strtolower($value);
|
$value = mb_strtolower($value);
|
||||||
|
|
||||||
if ($key == 0) {
|
if (0 == $key) {
|
||||||
$effect .= self::lowercaseFirst($value);
|
$effect .= self::lowercaseFirst($value);
|
||||||
} else {
|
} else {
|
||||||
$effect .= self::uppercaseFirst($value);
|
$effect .= self::uppercaseFirst($value);
|
||||||
@@ -812,7 +812,7 @@ class Miscellaneous
|
|||||||
|
|
||||||
if ($restLowercase) {
|
if ($restLowercase) {
|
||||||
$effect = mb_strtolower($effect);
|
$effect = mb_strtolower($effect);
|
||||||
} elseif ($restLowercase === false) {
|
} elseif (false === $restLowercase) {
|
||||||
$effect = mb_strtoupper($effect);
|
$effect = mb_strtoupper($effect);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -850,7 +850,7 @@ class Miscellaneous
|
|||||||
|
|
||||||
if ($restLowercase) {
|
if ($restLowercase) {
|
||||||
$effect = mb_strtolower($effect);
|
$effect = mb_strtolower($effect);
|
||||||
} elseif ($restLowercase === false) {
|
} elseif (false === $restLowercase) {
|
||||||
$effect = mb_strtoupper($effect);
|
$effect = mb_strtoupper($effect);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1032,6 +1032,8 @@ class Miscellaneous
|
|||||||
$separator = DIRECTORY_SEPARATOR;
|
$separator = DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
foreach ($paths as $path) {
|
foreach ($paths as $path) {
|
||||||
|
$path = trim($path);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Empty paths are useless
|
* Empty paths are useless
|
||||||
*/
|
*/
|
||||||
@@ -1153,7 +1155,7 @@ class Miscellaneous
|
|||||||
{
|
{
|
||||||
$value = filter_input($globalSourceType, $variableName);
|
$value = filter_input($globalSourceType, $variableName);
|
||||||
|
|
||||||
if ($value === null) {
|
if (null === $value) {
|
||||||
$globalSource = null;
|
$globalSource = null;
|
||||||
|
|
||||||
switch ($globalSourceType) {
|
switch ($globalSourceType) {
|
||||||
@@ -1178,7 +1180,7 @@ class Miscellaneous
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($globalSource !== null && isset($globalSource[$variableName])) {
|
if (null !== $globalSource && isset($globalSource[$variableName])) {
|
||||||
$value = $globalSource[$variableName];
|
$value = $globalSource[$variableName];
|
||||||
|
|
||||||
if (!ini_get('magic_quotes_gpc')) {
|
if (!ini_get('magic_quotes_gpc')) {
|
||||||
@@ -1232,7 +1234,7 @@ class Miscellaneous
|
|||||||
/*
|
/*
|
||||||
* First line is only HTTP status and is unneeded so skip it
|
* First line is only HTTP status and is unneeded so skip it
|
||||||
*/
|
*/
|
||||||
if ($i === 0) {
|
if (0 === $i) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1242,7 +1244,7 @@ class Miscellaneous
|
|||||||
/*
|
/*
|
||||||
* If the header is a "set-cookie" let's save it to "cookies" array
|
* If the header is a "set-cookie" let's save it to "cookies" array
|
||||||
*/
|
*/
|
||||||
if ($key === 'Set-Cookie') {
|
if ('Set-Cookie' === $key) {
|
||||||
$cookieParameters = explode(';', $value);
|
$cookieParameters = explode(';', $value);
|
||||||
|
|
||||||
$name = '';
|
$name = '';
|
||||||
@@ -1260,7 +1262,7 @@ class Miscellaneous
|
|||||||
* First parameter will be always a cookie name and it's value. It is not needed to run
|
* First parameter will be always a cookie name and it's value. It is not needed to run
|
||||||
* further actions for them, so save the values and move to next parameter.
|
* further actions for them, so save the values and move to next parameter.
|
||||||
*/
|
*/
|
||||||
if ($j === 0) {
|
if (0 === $j) {
|
||||||
$name = trim($param[0]);
|
$name = trim($param[0]);
|
||||||
$value = trim($param[1]);
|
$value = trim($param[1]);
|
||||||
continue;
|
continue;
|
||||||
@@ -1416,7 +1418,7 @@ class Miscellaneous
|
|||||||
if ($asHexadecimal) {
|
if ($asHexadecimal) {
|
||||||
$hexadecimal = dechex($colorComponent);
|
$hexadecimal = dechex($colorComponent);
|
||||||
|
|
||||||
if (strlen($hexadecimal) == 1) {
|
if (1 == strlen($hexadecimal)) {
|
||||||
return sprintf('0%s', $hexadecimal, $hexadecimal);
|
return sprintf('0%s', $hexadecimal, $hexadecimal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1471,4 +1473,37 @@ class Miscellaneous
|
|||||||
|
|
||||||
return $invertedColor;
|
return $invertedColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns project's root path.
|
||||||
|
* Looks for directory that contains composer.json.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getProjectRootPath()
|
||||||
|
{
|
||||||
|
$projectRootPath = '';
|
||||||
|
|
||||||
|
$fileName = 'composer.json';
|
||||||
|
$directoryPath = __DIR__;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Path of directory it's not the path of last directory?
|
||||||
|
*/
|
||||||
|
while (DIRECTORY_SEPARATOR !== $directoryPath) {
|
||||||
|
$filePath = static::concatenatePaths($directoryPath, $fileName);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Is here file we are looking for?
|
||||||
|
* Maybe it's a project's root path
|
||||||
|
*/
|
||||||
|
if (file_exists($filePath)) {
|
||||||
|
$projectRootPath = $directoryPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
$directoryPath = dirname($directoryPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $projectRootPath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ class QueryBuilderUtility
|
|||||||
$compareOperator = '=';
|
$compareOperator = '=';
|
||||||
|
|
||||||
if (is_array($value) && !empty($value)) {
|
if (is_array($value) && !empty($value)) {
|
||||||
if (count($value) == 2) {
|
if (2 == count($value)) {
|
||||||
$compareOperator = $value[1];
|
$compareOperator = $value[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ class QueryBuilderUtility
|
|||||||
|
|
||||||
$predicate = sprintf('%s.%s %s :%s', $alias, $column, $compareOperator, $column);
|
$predicate = sprintf('%s.%s %s :%s', $alias, $column, $compareOperator, $column);
|
||||||
|
|
||||||
if ($value === null) {
|
if (null === $value) {
|
||||||
$predicate = $queryBuilder->expr()->isNull(sprintf('%s.%s', $alias, $column));
|
$predicate = $queryBuilder->expr()->isNull(sprintf('%s.%s', $alias, $column));
|
||||||
unset($criteria[$column]);
|
unset($criteria[$column]);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ class Reflection
|
|||||||
* Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* 2016-11-07
|
* 2016-11-07
|
||||||
*/
|
*/
|
||||||
if ($object !== null) {
|
if (null !== $object) {
|
||||||
unset($exploded[0]);
|
unset($exploded[0]);
|
||||||
|
|
||||||
$property = implode('.', $exploded);
|
$property = implode('.', $exploded);
|
||||||
@@ -246,7 +246,7 @@ class Reflection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$valueFound && $reflectionProperty !== null) {
|
if (!$valueFound && null !== $reflectionProperty) {
|
||||||
/*
|
/*
|
||||||
* Oops, we have got exception.
|
* Oops, we have got exception.
|
||||||
*
|
*
|
||||||
@@ -285,7 +285,7 @@ class Reflection
|
|||||||
foreach ($objects as $entity) {
|
foreach ($objects as $entity) {
|
||||||
$value = self::getPropertyValue($entity, $property, $force);
|
$value = self::getPropertyValue($entity, $property, $force);
|
||||||
|
|
||||||
if ($value !== null) {
|
if (null !== $value) {
|
||||||
$values[] = $value;
|
$values[] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -345,7 +345,7 @@ class Reflection
|
|||||||
if ($withoutNamespace) {
|
if ($withoutNamespace) {
|
||||||
$classOnly = Miscellaneous::getLastElementOfString($name, '\\');
|
$classOnly = Miscellaneous::getLastElementOfString($name, '\\');
|
||||||
|
|
||||||
if ($classOnly !== null) {
|
if (null !== $classOnly) {
|
||||||
$name = $classOnly;
|
$name = $classOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,7 +427,7 @@ class Reflection
|
|||||||
$className = self::getClassName($source);
|
$className = self::getClassName($source);
|
||||||
$reflection = new ReflectionClass($className);
|
$reflection = new ReflectionClass($className);
|
||||||
|
|
||||||
if ($filter === null) {
|
if (null === $filter) {
|
||||||
$filter = ReflectionProperty::IS_PRIVATE
|
$filter = ReflectionProperty::IS_PRIVATE
|
||||||
+ ReflectionProperty::IS_PROTECTED
|
+ ReflectionProperty::IS_PROTECTED
|
||||||
+ ReflectionProperty::IS_PUBLIC
|
+ ReflectionProperty::IS_PUBLIC
|
||||||
@@ -477,7 +477,7 @@ class Reflection
|
|||||||
/*
|
/*
|
||||||
* Oops, cannot resolve class
|
* Oops, cannot resolve class
|
||||||
*/
|
*/
|
||||||
if ($className === null) {
|
if (null === $className) {
|
||||||
throw new CannotResolveClassNameException($class);
|
throw new CannotResolveClassNameException($class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -603,7 +603,7 @@ class Reflection
|
|||||||
if (!$uses && $verifyParents) {
|
if (!$uses && $verifyParents) {
|
||||||
$parentClassName = self::getParentClassName($className);
|
$parentClassName = self::getParentClassName($className);
|
||||||
|
|
||||||
if ($parentClassName !== null) {
|
if (null !== $parentClassName) {
|
||||||
return self::usesTrait($parentClassName, $trait, true);
|
return self::usesTrait($parentClassName, $trait, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -624,7 +624,7 @@ class Reflection
|
|||||||
$reflection = new ReflectionClass($className);
|
$reflection = new ReflectionClass($className);
|
||||||
$parentClass = $reflection->getParentClass();
|
$parentClass = $reflection->getParentClass();
|
||||||
|
|
||||||
if ($parentClass === null || $parentClass === false) {
|
if (null === $parentClass || false === $parentClass) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class Regex
|
|||||||
$taxid = preg_replace('/[\s-]/', '', $taxidString);
|
$taxid = preg_replace('/[\s-]/', '', $taxidString);
|
||||||
$sum = 0;
|
$sum = 0;
|
||||||
|
|
||||||
if (strlen($taxid) == 10 && is_numeric($taxid)) {
|
if (10 == strlen($taxid) && is_numeric($taxid)) {
|
||||||
for ($x = 0; $x <= 8; ++$x) {
|
for ($x = 0; $x <= 8; ++$x) {
|
||||||
$sum += $taxid[$x] * $weights[$x];
|
$sum += $taxid[$x] * $weights[$x];
|
||||||
}
|
}
|
||||||
@@ -185,9 +185,9 @@ class Regex
|
|||||||
$pattern = '|' . $filterExpression . '|';
|
$pattern = '|' . $filterExpression . '|';
|
||||||
$matchesCount = preg_match($pattern, $value, $matches);
|
$matchesCount = preg_match($pattern, $value, $matches);
|
||||||
|
|
||||||
$remove = $matchesCount == 0;
|
$remove = 0 == $matchesCount;
|
||||||
} else {
|
} else {
|
||||||
if ($value == '') {
|
if ('' == $value) {
|
||||||
$value = '\'\'';
|
$value = '\'\'';
|
||||||
} elseif (is_string($value)) {
|
} elseif (is_string($value)) {
|
||||||
$value = '\'' . $value . '\'';
|
$value = '\'' . $value . '\'';
|
||||||
@@ -431,7 +431,7 @@ class Regex
|
|||||||
public static function startsWith($string, $beginning)
|
public static function startsWith($string, $beginning)
|
||||||
{
|
{
|
||||||
if (!empty($string) && !empty($beginning)) {
|
if (!empty($string) && !empty($beginning)) {
|
||||||
if (strlen($beginning) == 1 && !self::isLetterOrDigit($beginning)) {
|
if (1 == strlen($beginning) && !self::isLetterOrDigit($beginning)) {
|
||||||
$beginning = '\\' . $beginning;
|
$beginning = '\\' . $beginning;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,7 +452,7 @@ class Regex
|
|||||||
*/
|
*/
|
||||||
public static function endsWith($string, $ending)
|
public static function endsWith($string, $ending)
|
||||||
{
|
{
|
||||||
if (strlen($ending) == 1 && !self::isLetterOrDigit($ending)) {
|
if (1 == strlen($ending) && !self::isLetterOrDigit($ending)) {
|
||||||
$ending = '\\' . $ending;
|
$ending = '\\' . $ending;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -537,7 +537,7 @@ class Regex
|
|||||||
*/
|
*/
|
||||||
public static function contains($haystack, $needle)
|
public static function contains($haystack, $needle)
|
||||||
{
|
{
|
||||||
if (strlen($needle) == 1 && !self::isLetterOrDigit($needle)) {
|
if (1 == strlen($needle) && !self::isLetterOrDigit($needle)) {
|
||||||
$needle = '\\' . $needle;
|
$needle = '\\' . $needle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -653,7 +653,7 @@ class Regex
|
|||||||
}
|
}
|
||||||
|
|
||||||
$modulo = $sum % 11;
|
$modulo = $sum % 11;
|
||||||
$numberControl = ($modulo == 10) ? 0 : $modulo;
|
$numberControl = (10 == $modulo) ? 0 : $modulo;
|
||||||
|
|
||||||
return $numberControl == $nip[9];
|
return $numberControl == $nip[9];
|
||||||
}
|
}
|
||||||
@@ -698,10 +698,10 @@ class Regex
|
|||||||
$color = Miscellaneous::replace($color, '/#/', '');
|
$color = Miscellaneous::replace($color, '/#/', '');
|
||||||
$length = strlen($color);
|
$length = strlen($color);
|
||||||
|
|
||||||
if ($length === 3) {
|
if (3 === $length) {
|
||||||
$color = Miscellaneous::replace($color, '/(.)(.)(.)/', '$1$1$2$2$3$3');
|
$color = Miscellaneous::replace($color, '/(.)(.)(.)/', '$1$1$2$2$3$3');
|
||||||
} else {
|
} else {
|
||||||
if ($length !== 6) {
|
if (6 !== $length) {
|
||||||
if ($throwException) {
|
if ($throwException) {
|
||||||
throw new IncorrectColorHexLengthException($color);
|
throw new IncorrectColorHexLengthException($color);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,14 +31,14 @@ class Repository
|
|||||||
{
|
{
|
||||||
$position = self::getExtremePosition($items, $asLast);
|
$position = self::getExtremePosition($items, $asLast);
|
||||||
|
|
||||||
if ($position === null && $force) {
|
if (null === $position && $force) {
|
||||||
$position = 0;
|
$position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($position !== null && !empty($items)) {
|
if (null !== $position && !empty($items)) {
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
if (method_exists($item, 'getPosition')) {
|
if (method_exists($item, 'getPosition')) {
|
||||||
if ($item->getPosition() === null) {
|
if (null === $item->getPosition()) {
|
||||||
if ($asLast) {
|
if ($asLast) {
|
||||||
++$position;
|
++$position;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,103 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Meritoo\Common\Utilities;
|
|
||||||
|
|
||||||
use DateTime;
|
|
||||||
use Generator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test case with common methods and data providers
|
|
||||||
*
|
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
|
||||||
* @copyright Meritoo.pl
|
|
||||||
*/
|
|
||||||
class TestCase extends \PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* 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['suprise/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 = '')
|
|
||||||
{
|
|
||||||
if (!empty($directoryPath)) {
|
|
||||||
$directoryPath = '/' . $directoryPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sprintf('%s/../../../../data/tests/%s%s', __DIR__, $fileName, $directoryPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -40,7 +40,7 @@ class Xml
|
|||||||
$query = $path->query('/*/*');
|
$query = $path->query('/*/*');
|
||||||
$nodesCount = $query->length;
|
$nodesCount = $query->length;
|
||||||
|
|
||||||
if ($nodesCount == 0) {
|
if (0 == $nodesCount) {
|
||||||
return $element1;
|
return $element1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
329
tests/Meritoo/Common/Test/Collection/CollectionTest.php
Normal file
329
tests/Meritoo/Common/Test/Collection/CollectionTest.php
Normal file
@@ -0,0 +1,329 @@
|
|||||||
|
<?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\Collection;
|
||||||
|
|
||||||
|
use ArrayIterator;
|
||||||
|
use Meritoo\Common\Collection\Collection;
|
||||||
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
|
use Meritoo\Common\Type\OopVisibilityType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests of the collection of elements
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
class CollectionTest extends BaseTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* An empty collection
|
||||||
|
*
|
||||||
|
* @var Collection
|
||||||
|
*/
|
||||||
|
private $emptyCollection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple collection
|
||||||
|
*
|
||||||
|
* @var Collection
|
||||||
|
*/
|
||||||
|
private $simpleCollection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Elements of simple collection
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $simpleElements;
|
||||||
|
|
||||||
|
public function testEmptyCollection()
|
||||||
|
{
|
||||||
|
static::assertEquals(0, $this->emptyCollection->count());
|
||||||
|
static::assertCount(0, $this->emptyCollection);
|
||||||
|
static::assertEmpty($this->emptyCollection);
|
||||||
|
|
||||||
|
static::assertTrue($this->emptyCollection->isEmpty());
|
||||||
|
static::assertEquals([], $this->emptyCollection->toArray());
|
||||||
|
static::assertEmpty($this->emptyCollection->toArray());
|
||||||
|
|
||||||
|
static::assertNull($this->emptyCollection->getFirst());
|
||||||
|
static::assertNull($this->emptyCollection->getLast());
|
||||||
|
static::assertNull($this->emptyCollection[1]);
|
||||||
|
static::assertNull($this->emptyCollection['abc']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotEmptyCollection()
|
||||||
|
{
|
||||||
|
static::assertEquals(4, $this->simpleCollection->count());
|
||||||
|
static::assertCount(4, $this->simpleCollection);
|
||||||
|
static::assertNotEmpty($this->simpleCollection);
|
||||||
|
|
||||||
|
static::assertFalse($this->simpleCollection->isEmpty());
|
||||||
|
static::assertEquals($this->simpleElements, $this->simpleCollection->toArray());
|
||||||
|
static::assertNotEmpty($this->simpleCollection->toArray());
|
||||||
|
|
||||||
|
static::assertEquals('lorem', $this->simpleCollection->getFirst());
|
||||||
|
static::assertEquals('sit', $this->simpleCollection->getLast());
|
||||||
|
static::assertEquals('dolor', $this->simpleCollection[123]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCount()
|
||||||
|
{
|
||||||
|
static::assertEquals(0, $this->emptyCollection->count());
|
||||||
|
static::assertEquals(4, $this->simpleCollection->count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOffsetExists()
|
||||||
|
{
|
||||||
|
static::assertFalse(isset($this->emptyCollection['abc']));
|
||||||
|
static::assertFalse(isset($this->simpleCollection['abc']));
|
||||||
|
|
||||||
|
static::assertTrue(isset($this->simpleCollection[0]));
|
||||||
|
static::assertTrue(isset($this->simpleCollection[345]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOffsetGet()
|
||||||
|
{
|
||||||
|
static::assertNull($this->emptyCollection['abc']);
|
||||||
|
static::assertNull($this->simpleCollection['abc']);
|
||||||
|
|
||||||
|
static::assertEquals('lorem', $this->simpleCollection[0]);
|
||||||
|
static::assertEquals('sit', $this->simpleCollection[345]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOffsetSet()
|
||||||
|
{
|
||||||
|
$this->emptyCollection['test1'] = 1234;
|
||||||
|
$this->simpleCollection['test2'] = 5678;
|
||||||
|
|
||||||
|
static::assertTrue($this->emptyCollection->has(1234));
|
||||||
|
static::assertEquals(1234, $this->emptyCollection['test1']);
|
||||||
|
|
||||||
|
static::assertTrue($this->simpleCollection->has(5678));
|
||||||
|
static::assertEquals(5678, $this->simpleCollection['test2']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOffsetUnset()
|
||||||
|
{
|
||||||
|
unset($this->simpleCollection[0]);
|
||||||
|
|
||||||
|
static::assertFalse($this->simpleCollection->has('lorem'));
|
||||||
|
static::assertEquals('ipsum', $this->simpleCollection[1]);
|
||||||
|
static::assertEquals(3, $this->simpleCollection->count());
|
||||||
|
|
||||||
|
unset($this->simpleCollection[123]);
|
||||||
|
|
||||||
|
static::assertFalse($this->simpleCollection->has('dolor'));
|
||||||
|
static::assertEquals('ipsum', $this->simpleCollection[1]);
|
||||||
|
static::assertEquals(2, $this->simpleCollection->count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetIterator()
|
||||||
|
{
|
||||||
|
static::assertInstanceOf(ArrayIterator::class, $this->simpleCollection->getIterator());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAdd()
|
||||||
|
{
|
||||||
|
$this->emptyCollection->add('test1');
|
||||||
|
|
||||||
|
static::assertTrue($this->emptyCollection->has('test1'));
|
||||||
|
static::assertEquals(1, $this->emptyCollection->count());
|
||||||
|
static::assertEquals('test1', $this->emptyCollection[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAddWithIndex()
|
||||||
|
{
|
||||||
|
$this->emptyCollection->add('test2', 1234);
|
||||||
|
|
||||||
|
static::assertTrue($this->emptyCollection->has('test2'));
|
||||||
|
static::assertEquals(1, $this->emptyCollection->count());
|
||||||
|
static::assertEquals('test2', $this->emptyCollection[1234]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAddMultipleUsingEmptyArray()
|
||||||
|
{
|
||||||
|
$this->emptyCollection->addMultiple([]);
|
||||||
|
|
||||||
|
static::assertEquals(0, $this->emptyCollection->count());
|
||||||
|
static::assertTrue($this->emptyCollection->isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAddMultiple()
|
||||||
|
{
|
||||||
|
$elements = [
|
||||||
|
'test1',
|
||||||
|
'test2',
|
||||||
|
1234 => 'test3',
|
||||||
|
5678 => 'test4',
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->emptyCollection->addMultiple($elements);
|
||||||
|
|
||||||
|
static::assertFalse($this->emptyCollection->isEmpty());
|
||||||
|
static::assertEquals(4, $this->emptyCollection->count());
|
||||||
|
|
||||||
|
static::assertEquals('test1', $this->emptyCollection[0]);
|
||||||
|
static::assertEquals('test2', $this->emptyCollection[1]);
|
||||||
|
static::assertEquals('test3', $this->emptyCollection[2]);
|
||||||
|
static::assertEquals('test4', $this->emptyCollection[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAddMultipleUsingIndexes()
|
||||||
|
{
|
||||||
|
$elements = [
|
||||||
|
'test1',
|
||||||
|
'test2',
|
||||||
|
1234 => 'test3',
|
||||||
|
5678 => 'test4',
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->emptyCollection->addMultiple($elements, true);
|
||||||
|
|
||||||
|
static::assertFalse($this->emptyCollection->isEmpty());
|
||||||
|
static::assertEquals(4, $this->emptyCollection->count());
|
||||||
|
|
||||||
|
static::assertEquals('test1', $this->emptyCollection[0]);
|
||||||
|
static::assertEquals('test2', $this->emptyCollection[1]);
|
||||||
|
static::assertEquals('test3', $this->emptyCollection[1234]);
|
||||||
|
static::assertEquals('test4', $this->emptyCollection[5678]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPrepend()
|
||||||
|
{
|
||||||
|
$this->emptyCollection->prepend('lorem-ipsum');
|
||||||
|
|
||||||
|
static::assertFalse($this->emptyCollection->isEmpty());
|
||||||
|
static::assertEquals(1, $this->emptyCollection->count());
|
||||||
|
static::assertEquals('lorem-ipsum', $this->emptyCollection[0]);
|
||||||
|
|
||||||
|
$this->simpleCollection->prepend('lorem-ipsum');
|
||||||
|
|
||||||
|
static::assertFalse($this->simpleCollection->isEmpty());
|
||||||
|
static::assertEquals(5, $this->simpleCollection->count());
|
||||||
|
static::assertEquals('lorem-ipsum', $this->simpleCollection[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRemoveNotExistingElement()
|
||||||
|
{
|
||||||
|
$this->emptyCollection->remove('abc');
|
||||||
|
|
||||||
|
static::assertTrue($this->emptyCollection->isEmpty());
|
||||||
|
static::assertEquals(0, $this->emptyCollection->count());
|
||||||
|
|
||||||
|
$this->simpleCollection->remove('abc');
|
||||||
|
|
||||||
|
static::assertFalse($this->simpleCollection->isEmpty());
|
||||||
|
static::assertEquals(4, $this->simpleCollection->count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRemove()
|
||||||
|
{
|
||||||
|
static::assertFalse($this->simpleCollection->isEmpty());
|
||||||
|
static::assertEquals(4, $this->simpleCollection->count());
|
||||||
|
static::assertEquals('ipsum', $this->simpleCollection[1]);
|
||||||
|
|
||||||
|
$this->simpleCollection->remove('ipsum');
|
||||||
|
|
||||||
|
static::assertFalse($this->simpleCollection->isEmpty());
|
||||||
|
static::assertEquals(3, $this->simpleCollection->count());
|
||||||
|
static::assertNull($this->simpleCollection[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsEmpty()
|
||||||
|
{
|
||||||
|
static::assertTrue($this->emptyCollection->isEmpty());
|
||||||
|
static::assertFalse($this->simpleCollection->isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsFirst()
|
||||||
|
{
|
||||||
|
static::assertFalse($this->emptyCollection->isFirst('abc'));
|
||||||
|
static::assertFalse($this->simpleCollection->isFirst('abc'));
|
||||||
|
static::assertFalse($this->simpleCollection->isFirst('dolor'));
|
||||||
|
static::assertTrue($this->simpleCollection->isFirst('lorem'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsLast()
|
||||||
|
{
|
||||||
|
static::assertFalse($this->emptyCollection->isLast('abc'));
|
||||||
|
static::assertFalse($this->simpleCollection->isLast('abc'));
|
||||||
|
static::assertFalse($this->simpleCollection->isLast('dolor'));
|
||||||
|
static::assertTrue($this->simpleCollection->isLast('sit'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHas()
|
||||||
|
{
|
||||||
|
static::assertFalse($this->emptyCollection->has('abc'));
|
||||||
|
static::assertFalse($this->simpleCollection->has('abc'));
|
||||||
|
static::assertTrue($this->simpleCollection->has('lorem'));
|
||||||
|
static::assertTrue($this->simpleCollection->has('dolor'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPrevious()
|
||||||
|
{
|
||||||
|
static::assertNull($this->emptyCollection->getPrevious('abc'));
|
||||||
|
static::assertNull($this->simpleCollection->getPrevious('abc'));
|
||||||
|
static::assertNull($this->simpleCollection->getPrevious('lorem'));
|
||||||
|
|
||||||
|
static::assertEquals('lorem', $this->simpleCollection->getPrevious('ipsum'));
|
||||||
|
static::assertEquals('dolor', $this->simpleCollection->getPrevious('sit'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetNext()
|
||||||
|
{
|
||||||
|
static::assertNull($this->emptyCollection->getNext('abc'));
|
||||||
|
static::assertNull($this->simpleCollection->getNext('abc'));
|
||||||
|
static::assertNull($this->simpleCollection->getNext('sit'));
|
||||||
|
|
||||||
|
static::assertEquals('dolor', $this->simpleCollection->getNext('ipsum'));
|
||||||
|
static::assertEquals('sit', $this->simpleCollection->getNext('dolor'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetFirst()
|
||||||
|
{
|
||||||
|
static::assertNull($this->emptyCollection->getFirst());
|
||||||
|
static::assertEquals('lorem', $this->simpleCollection->getFirst());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetLast()
|
||||||
|
{
|
||||||
|
static::assertNull($this->emptyCollection->getLast());
|
||||||
|
static::assertEquals('sit', $this->simpleCollection->getLast());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testToArray()
|
||||||
|
{
|
||||||
|
static::assertEquals([], $this->emptyCollection->toArray());
|
||||||
|
static::assertEquals($this->simpleElements, $this->simpleCollection->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testExistsVisibilityAndArguments()
|
||||||
|
{
|
||||||
|
$this->verifyMethodVisibilityAndArguments(Collection::class, 'exists', OopVisibilityType::IS_PRIVATE, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->simpleElements = [
|
||||||
|
'lorem',
|
||||||
|
'ipsum',
|
||||||
|
123 => 'dolor',
|
||||||
|
345 => 'sit',
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->emptyCollection = new Collection();
|
||||||
|
$this->simpleCollection = new Collection($this->simpleElements);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,10 +6,11 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Exception\Base;
|
namespace Meritoo\Common\Test\Exception\Base;
|
||||||
|
|
||||||
use Meritoo\Common\Exception\Base\UnknownTypeException;
|
use Meritoo\Common\Exception\Base\UnknownTypeException;
|
||||||
use Meritoo\Common\Type\Base\BaseType;
|
use Meritoo\Common\Type\Base\BaseType;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the exception used while type of something is unknown
|
* Tests of the exception used while type of something is unknown
|
||||||
@@ -17,7 +18,7 @@ use Meritoo\Common\Type\Base\BaseType;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class UnknownTypeExceptionTest extends \PHPUnit_Framework_TestCase
|
class UnknownTypeExceptionTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testWithoutException()
|
public function testWithoutException()
|
||||||
{
|
{
|
||||||
@@ -6,10 +6,11 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Type\Base;
|
namespace Meritoo\Common\Test\Type\Base;
|
||||||
|
|
||||||
use Generator;
|
use Generator;
|
||||||
use Meritoo\Common\Type\Base\BaseType;
|
use Meritoo\Common\Type\Base\BaseType;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the base / abstract type of something
|
* Tests of the base / abstract type of something
|
||||||
@@ -17,7 +18,7 @@ use Meritoo\Common\Type\Base\BaseType;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class BaseTypeTest extends \PHPUnit_Framework_TestCase
|
class BaseTypeTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param BaseType $type Type of something
|
* @param BaseType $type Type of something
|
||||||
@@ -6,9 +6,9 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Type;
|
namespace Meritoo\Common\Test\Type;
|
||||||
|
|
||||||
use Generator;
|
use Meritoo\Common\Test\Base\BaseTypeTestCase;
|
||||||
use Meritoo\Common\Type\DatePartType;
|
use Meritoo\Common\Type\DatePartType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,11 +17,14 @@ use Meritoo\Common\Type\DatePartType;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class DatePartTypeTest extends \PHPUnit_Framework_TestCase
|
class DatePartTypeTest extends BaseTypeTestCase
|
||||||
{
|
{
|
||||||
public function testGetAll()
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function getAllExpectedTypes()
|
||||||
{
|
{
|
||||||
$expectedTypes = [
|
return [
|
||||||
'DAY' => DatePartType::DAY,
|
'DAY' => DatePartType::DAY,
|
||||||
'HOUR' => DatePartType::HOUR,
|
'HOUR' => DatePartType::HOUR,
|
||||||
'MINUTE' => DatePartType::MINUTE,
|
'MINUTE' => DatePartType::MINUTE,
|
||||||
@@ -29,29 +32,20 @@ class DatePartTypeTest extends \PHPUnit_Framework_TestCase
|
|||||||
'SECOND' => DatePartType::SECOND,
|
'SECOND' => DatePartType::SECOND,
|
||||||
'YEAR' => DatePartType::YEAR,
|
'YEAR' => DatePartType::YEAR,
|
||||||
];
|
];
|
||||||
|
|
||||||
$all = (new DatePartType())->getAll();
|
|
||||||
self::assertEquals($expectedTypes, $all);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $toVerifyType Concrete type to verify (of given instance of type)
|
* {@inheritdoc}
|
||||||
* @param bool $isCorrect Expected information if given type is correct
|
|
||||||
*
|
|
||||||
* @dataProvider provideConcreteType
|
|
||||||
*/
|
*/
|
||||||
public function testIsCorrectType($toVerifyType, $isCorrect)
|
protected function getTestedTypeInstance()
|
||||||
{
|
{
|
||||||
$type = new DatePartType();
|
return new DatePartType();
|
||||||
self::assertEquals($isCorrect, $type->isCorrectType($toVerifyType));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides type of something for testing the isCorrectType() method
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return Generator
|
|
||||||
*/
|
*/
|
||||||
public function provideConcreteType()
|
public function provideTypeToVerify()
|
||||||
{
|
{
|
||||||
yield[
|
yield[
|
||||||
'',
|
'',
|
||||||
@@ -6,9 +6,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Utilities;
|
namespace Meritoo\Common\Test\Utilities;
|
||||||
|
|
||||||
use Meritoo\Common\Utilities\Arrays;
|
use Meritoo\Common\Utilities\Arrays;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the useful arrays methods
|
* Tests of the useful arrays methods
|
||||||
@@ -16,7 +17,7 @@ use Meritoo\Common\Utilities\Arrays;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class ArraysTest extends \PHPUnit_Framework_TestCase
|
class ArraysTest extends TestCase
|
||||||
{
|
{
|
||||||
private $simpleArray;
|
private $simpleArray;
|
||||||
private $simpleArrayWithKeys;
|
private $simpleArrayWithKeys;
|
||||||
@@ -6,9 +6,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Utilities;
|
namespace Meritoo\Common\Test\Utilities;
|
||||||
|
|
||||||
use Meritoo\Common\Utilities\Bundle;
|
use Meritoo\Common\Utilities\Bundle;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the useful methods for bundle
|
* Tests of the useful methods for bundle
|
||||||
@@ -16,7 +17,7 @@ use Meritoo\Common\Utilities\Bundle;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class BundleTest extends \PHPUnit_Framework_TestCase
|
class BundleTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testGetBundleViewPathEmptyPathAndBundle()
|
public function testGetBundleViewPathEmptyPathAndBundle()
|
||||||
{
|
{
|
||||||
@@ -6,10 +6,11 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Utilities;
|
namespace Meritoo\Common\Test\Utilities;
|
||||||
|
|
||||||
|
use Generator;
|
||||||
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
use Meritoo\Common\Utilities\Composer;
|
use Meritoo\Common\Utilities\Composer;
|
||||||
use Meritoo\Common\Utilities\TestCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the useful Composer-related methods
|
* Tests of the useful Composer-related methods
|
||||||
@@ -17,7 +18,7 @@ use Meritoo\Common\Utilities\TestCase;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class ComposerTest extends TestCase
|
class ComposerTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Path of existing composer.json used as source of data for tests
|
* Path of existing composer.json used as source of data for tests
|
||||||
@@ -60,7 +61,7 @@ class ComposerTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* Provides names and values of existing nodes
|
* Provides names and values of existing nodes
|
||||||
*
|
*
|
||||||
* @return \Generator
|
* @return Generator
|
||||||
*/
|
*/
|
||||||
public function getExistingNode()
|
public function getExistingNode()
|
||||||
{
|
{
|
||||||
@@ -1,11 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Utilities;
|
/**
|
||||||
|
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Meritoo\Common\Test\Utilities;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Generator;
|
use Generator;
|
||||||
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
|
use Meritoo\Common\Type\OopVisibilityType;
|
||||||
use Meritoo\Common\Utilities\DatePeriod;
|
use Meritoo\Common\Utilities\DatePeriod;
|
||||||
use Meritoo\Common\Utilities\TestCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of date's period
|
* Tests of date's period
|
||||||
@@ -13,8 +20,13 @@ use Meritoo\Common\Utilities\TestCase;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class DatePeriodTest extends TestCase
|
class DatePeriodTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
|
public function testConstructorVisibilityAndArguments()
|
||||||
|
{
|
||||||
|
$this->verifyConstructorVisibilityAndArguments(DatePeriod::class, OopVisibilityType::IS_PUBLIC, 2, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param DateTime $startDate (optional) Start date of period
|
* @param DateTime $startDate (optional) Start date of period
|
||||||
* @param DateTime $endDate (optional) End date of period
|
* @param DateTime $endDate (optional) End date of period
|
||||||
@@ -6,14 +6,14 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Utilities;
|
namespace Meritoo\Common\Test\Utilities;
|
||||||
|
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Generator;
|
use Generator;
|
||||||
use Meritoo\Common\Exception\Date\IncorrectDatePartException;
|
use Meritoo\Common\Exception\Date\UnknownDatePartTypeException;
|
||||||
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
use Meritoo\Common\Utilities\Date;
|
use Meritoo\Common\Utilities\Date;
|
||||||
use Meritoo\Common\Utilities\TestCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the Date methods (only static functions)
|
* Tests of the Date methods (only static functions)
|
||||||
@@ -21,7 +21,7 @@ use Meritoo\Common\Utilities\TestCase;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class DateTest extends TestCase
|
class DateTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param mixed $value Empty value, e.g. ""
|
* @param mixed $value Empty value, e.g. ""
|
||||||
@@ -218,7 +218,7 @@ class DateTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetDayOfWeekIncorrectValues($year, $month, $day)
|
public function testGetDayOfWeekIncorrectValues($year, $month, $day)
|
||||||
{
|
{
|
||||||
$this->expectException(IncorrectDatePartException::class);
|
$this->expectException(UnknownDatePartTypeException::class);
|
||||||
self::assertEmpty(Date::getDayOfWeek($year, $month, $day));
|
self::assertEmpty(Date::getDayOfWeek($year, $month, $day));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -454,8 +454,11 @@ class DateTest extends TestCase
|
|||||||
$start = 1;
|
$start = 1;
|
||||||
$end = 100;
|
$end = 100;
|
||||||
|
|
||||||
$intervalMinDate = (clone $startDate)->add(new DateInterval(sprintf('P%dD', $start)));
|
$minDate = clone $startDate;
|
||||||
$intervalMaxDate = (clone $startDate)->add(new DateInterval(sprintf('P%dD', $end)));
|
$maxDate = clone $startDate;
|
||||||
|
|
||||||
|
$intervalMinDate = $minDate->add(new DateInterval(sprintf('P%dD', $start)));
|
||||||
|
$intervalMaxDate = $maxDate->add(new DateInterval(sprintf('P%dD', $end)));
|
||||||
|
|
||||||
$randomDate = Date::getRandomDate();
|
$randomDate = Date::getRandomDate();
|
||||||
self::assertTrue($randomDate >= $intervalMinDate && $randomDate <= $intervalMaxDate);
|
self::assertTrue($randomDate >= $intervalMinDate && $randomDate <= $intervalMaxDate);
|
||||||
@@ -471,7 +474,9 @@ class DateTest extends TestCase
|
|||||||
public function testGetRandomDateIncorrectEnd(DateTime $startDate, $start, $end)
|
public function testGetRandomDateIncorrectEnd(DateTime $startDate, $start, $end)
|
||||||
{
|
{
|
||||||
$randomDate = Date::getRandomDate($startDate, $start, $end);
|
$randomDate = Date::getRandomDate($startDate, $start, $end);
|
||||||
$intervalDate = (clone $startDate)->add(new DateInterval(sprintf('P%dD', $start)));
|
|
||||||
|
$cloned = clone $startDate;
|
||||||
|
$intervalDate = $cloned->add(new DateInterval(sprintf('P%dD', $start)));
|
||||||
|
|
||||||
self::assertTrue($randomDate >= $intervalDate && $randomDate <= $intervalDate);
|
self::assertTrue($randomDate >= $intervalDate && $randomDate <= $intervalDate);
|
||||||
}
|
}
|
||||||
@@ -487,8 +492,11 @@ class DateTest extends TestCase
|
|||||||
{
|
{
|
||||||
$randomDate = Date::getRandomDate($startDate, $start, $end);
|
$randomDate = Date::getRandomDate($startDate, $start, $end);
|
||||||
|
|
||||||
$intervalMinDate = (clone $startDate)->add(new DateInterval(sprintf('P%dD', $start)));
|
$minDate = clone $startDate;
|
||||||
$intervalMaxDate = (clone $startDate)->add(new DateInterval(sprintf('P%dD', $end)));
|
$maxDate = clone $startDate;
|
||||||
|
|
||||||
|
$intervalMinDate = $minDate->add(new DateInterval(sprintf('P%dD', $start)));
|
||||||
|
$intervalMaxDate = $maxDate->add(new DateInterval(sprintf('P%dD', $end)));
|
||||||
|
|
||||||
self::assertTrue($randomDate >= $intervalMinDate && $randomDate <= $intervalMaxDate);
|
self::assertTrue($randomDate >= $intervalMinDate && $randomDate <= $intervalMaxDate);
|
||||||
}
|
}
|
||||||
@@ -6,10 +6,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Utilities;
|
namespace Meritoo\Common\Test\Utilities;
|
||||||
|
|
||||||
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
use Meritoo\Common\Utilities\GeneratorUtility;
|
use Meritoo\Common\Utilities\GeneratorUtility;
|
||||||
use Meritoo\Common\Utilities\TestCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the useful methods for the Generator class
|
* Tests of the useful methods for the Generator class
|
||||||
@@ -17,7 +17,7 @@ use Meritoo\Common\Utilities\TestCase;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class GeneratorUtilityTest extends TestCase
|
class GeneratorUtilityTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function testGetGeneratorElements()
|
public function testGetGeneratorElements()
|
||||||
{
|
{
|
||||||
@@ -6,11 +6,11 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Utilities;
|
namespace Meritoo\Common\Test\Utilities;
|
||||||
|
|
||||||
use Generator;
|
use Generator;
|
||||||
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
use Meritoo\Common\Utilities\Locale;
|
use Meritoo\Common\Utilities\Locale;
|
||||||
use Meritoo\Common\Utilities\TestCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the useful locale methods
|
* Tests of the useful locale methods
|
||||||
@@ -18,7 +18,7 @@ use Meritoo\Common\Utilities\TestCase;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class LocaleTest extends TestCase
|
class LocaleTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param mixed $languageCode Empty value, e.g. ""
|
* @param mixed $languageCode Empty value, e.g. ""
|
||||||
@@ -6,11 +6,11 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Utilities;
|
namespace Meritoo\Common\Test\Utilities;
|
||||||
|
|
||||||
use Generator;
|
use Generator;
|
||||||
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
use Meritoo\Common\Utilities\MimeTypes;
|
use Meritoo\Common\Utilities\MimeTypes;
|
||||||
use Meritoo\Common\Utilities\TestCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the useful methods for mime types of files
|
* Tests of the useful methods for mime types of files
|
||||||
@@ -18,7 +18,7 @@ use Meritoo\Common\Utilities\TestCase;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class MimeTypesTest extends TestCase
|
class MimeTypesTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param mixed $mimeType Empty value, e.g. ""
|
* @param mixed $mimeType Empty value, e.g. ""
|
||||||
@@ -6,14 +6,14 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Utilities;
|
namespace Meritoo\Common\Test\Utilities;
|
||||||
|
|
||||||
use Generator;
|
use Generator;
|
||||||
use Meritoo\Common\Exception\Regex\IncorrectColorHexLengthException;
|
use Meritoo\Common\Exception\Regex\IncorrectColorHexLengthException;
|
||||||
use Meritoo\Common\Exception\Regex\InvalidColorHexValueException;
|
use Meritoo\Common\Exception\Regex\InvalidColorHexValueException;
|
||||||
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
use Meritoo\Common\Utilities\Locale;
|
use Meritoo\Common\Utilities\Locale;
|
||||||
use Meritoo\Common\Utilities\Miscellaneous;
|
use Meritoo\Common\Utilities\Miscellaneous;
|
||||||
use Meritoo\Common\Utilities\TestCase;
|
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,7 +22,7 @@ use stdClass;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class MiscellaneousTest extends TestCase
|
class MiscellaneousTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
private $stringSmall;
|
private $stringSmall;
|
||||||
private $stringCommaSeparated;
|
private $stringCommaSeparated;
|
||||||
@@ -503,16 +503,35 @@ class MiscellaneousTest extends TestCase
|
|||||||
self::assertEquals('lorem ipsum', Miscellaneous::trimSmart(' lorem ipsum '));
|
self::assertEquals('lorem ipsum', Miscellaneous::trimSmart(' lorem ipsum '));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConcatenatePaths()
|
/**
|
||||||
|
* @param mixed $emptyPaths Empty paths co concatenate
|
||||||
|
* @dataProvider provideEmptyValue
|
||||||
|
*/
|
||||||
|
public function testConcatenatePathsWithEmptyPaths($emptyPaths)
|
||||||
|
{
|
||||||
|
self::assertEquals('', Miscellaneous::concatenatePaths($emptyPaths));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConcatenatePathsWithOneEmptyPath()
|
||||||
|
{
|
||||||
|
$paths = [
|
||||||
|
'first/directory',
|
||||||
|
'second/one',
|
||||||
|
'',
|
||||||
|
'and/the/third',
|
||||||
|
];
|
||||||
|
|
||||||
|
$concatenated = Miscellaneous::concatenatePaths($paths);
|
||||||
|
unset($paths[2]);
|
||||||
|
$imploded = implode('/', $paths);
|
||||||
|
|
||||||
|
self::assertEquals('/' . $imploded, $concatenated);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConcatenatePathsInNixOs()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Common cases
|
* For *nix operating system
|
||||||
*/
|
|
||||||
self::assertEquals('', Miscellaneous::concatenatePaths(null));
|
|
||||||
self::assertEquals('', Miscellaneous::concatenatePaths([]));
|
|
||||||
|
|
||||||
/*
|
|
||||||
* *nix operating system
|
|
||||||
*/
|
*/
|
||||||
$paths1 = [
|
$paths1 = [
|
||||||
'first/directory',
|
'first/directory',
|
||||||
@@ -522,7 +541,10 @@ class MiscellaneousTest extends TestCase
|
|||||||
|
|
||||||
self::assertEquals('/' . implode('/', $paths1), Miscellaneous::concatenatePaths($paths1));
|
self::assertEquals('/' . implode('/', $paths1), Miscellaneous::concatenatePaths($paths1));
|
||||||
self::assertEquals('/' . implode('/', $paths1), Miscellaneous::concatenatePaths($paths1[0], $paths1[1], $paths1[2]));
|
self::assertEquals('/' . implode('/', $paths1), Miscellaneous::concatenatePaths($paths1[0], $paths1[1], $paths1[2]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConcatenatePathsInWindowsOs()
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* For Windows operating system
|
* For Windows operating system
|
||||||
*/
|
*/
|
||||||
@@ -720,6 +742,11 @@ class MiscellaneousTest extends TestCase
|
|||||||
self::assertSame($expected, Miscellaneous::fillMissingZeros($number, $length, $before));
|
self::assertSame($expected, Miscellaneous::fillMissingZeros($number, $length, $before));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetProjectRootPath()
|
||||||
|
{
|
||||||
|
self::assertNotEmpty(Miscellaneous::getProjectRootPath());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides string to convert characters to latin characters and not lower cased and not human-readable
|
* Provides string to convert characters to latin characters and not lower cased and not human-readable
|
||||||
*
|
*
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Utilities\Reflection;
|
/**
|
||||||
|
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Meritoo\Common\Test\Utilities\Reflection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The A class.
|
* The A class.
|
||||||
20
tests/Meritoo/Common/Test/Utilities/Reflection/B.php
Normal file
20
tests/Meritoo/Common/Test/Utilities/Reflection/B.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Meritoo\Common\Test\Utilities\Reflection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The B class.
|
||||||
|
* Used for testing the Reflection class.
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
class B extends A
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Utilities\Reflection;
|
/**
|
||||||
|
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Meritoo\Common\Test\Utilities\Reflection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The C class.
|
* The C class.
|
||||||
20
tests/Meritoo/Common/Test/Utilities/Reflection/D.php
Normal file
20
tests/Meritoo/Common/Test/Utilities/Reflection/D.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Meritoo\Common\Test\Utilities\Reflection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The D class.
|
||||||
|
* Used for testing the Reflection class.
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
class D
|
||||||
|
{
|
||||||
|
}
|
||||||
20
tests/Meritoo/Common/Test/Utilities/Reflection/E.php
Normal file
20
tests/Meritoo/Common/Test/Utilities/Reflection/E.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Meritoo\Common\Test\Utilities\Reflection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The E trait.
|
||||||
|
* Used for testing the Reflection class.
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
trait E
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -6,20 +6,20 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Utilities;
|
namespace Meritoo\Common\Test\Utilities;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Generator;
|
use Generator;
|
||||||
use Meritoo\Common\Exception\Reflection\CannotResolveClassNameException;
|
use Meritoo\Common\Exception\Reflection\CannotResolveClassNameException;
|
||||||
use Meritoo\Common\Exception\Reflection\MissingChildClassesException;
|
use Meritoo\Common\Exception\Reflection\MissingChildClassesException;
|
||||||
use Meritoo\Common\Exception\Reflection\TooManyChildClassesException;
|
use Meritoo\Common\Exception\Reflection\TooManyChildClassesException;
|
||||||
use Meritoo\Common\Tests\Utilities\Reflection\A;
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
use Meritoo\Common\Tests\Utilities\Reflection\B;
|
use Meritoo\Common\Test\Utilities\Reflection\A;
|
||||||
use Meritoo\Common\Tests\Utilities\Reflection\C;
|
use Meritoo\Common\Test\Utilities\Reflection\B;
|
||||||
use Meritoo\Common\Tests\Utilities\Reflection\D;
|
use Meritoo\Common\Test\Utilities\Reflection\C;
|
||||||
use Meritoo\Common\Tests\Utilities\Reflection\E;
|
use Meritoo\Common\Test\Utilities\Reflection\D;
|
||||||
|
use Meritoo\Common\Test\Utilities\Reflection\E;
|
||||||
use Meritoo\Common\Utilities\Reflection;
|
use Meritoo\Common\Utilities\Reflection;
|
||||||
use Meritoo\Common\Utilities\TestCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the useful reflection methods
|
* Tests of the useful reflection methods
|
||||||
@@ -27,7 +27,7 @@ use Meritoo\Common\Utilities\TestCase;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class ReflectionTest extends TestCase
|
class ReflectionTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param mixed $invalidClass Empty value, e.g. ""
|
* @param mixed $invalidClass Empty value, e.g. ""
|
||||||
@@ -88,7 +88,7 @@ class ReflectionTest extends TestCase
|
|||||||
/*
|
/*
|
||||||
* Existing class
|
* Existing class
|
||||||
*/
|
*/
|
||||||
self::assertEquals('Meritoo\Common\Tests\Utilities', Reflection::getClassNamespace(self::class));
|
self::assertEquals('Meritoo\Common\Test\Utilities', Reflection::getClassNamespace(self::class));
|
||||||
self::assertEquals(DateTime::class, Reflection::getClassNamespace(new DateTime()));
|
self::assertEquals(DateTime::class, Reflection::getClassNamespace(new DateTime()));
|
||||||
|
|
||||||
self::assertEquals(DateTime::class, Reflection::getClassNamespace([
|
self::assertEquals(DateTime::class, Reflection::getClassNamespace([
|
||||||
@@ -8,16 +8,17 @@
|
|||||||
|
|
||||||
namespace Meritoo\Common\Utilities;
|
namespace Meritoo\Common\Utilities;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the useful regular expressions methods
|
* Tests of the useful regular expressions methods
|
||||||
*
|
*
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class RegexTest extends \PHPUnit_Framework_TestCase
|
class RegexTest extends TestCase
|
||||||
{
|
{
|
||||||
private $simpleText;
|
private $simpleText;
|
||||||
|
|
||||||
private $camelCaseText;
|
private $camelCaseText;
|
||||||
|
|
||||||
public function testGetCamelCaseParts()
|
public function testGetCamelCaseParts()
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Utilities;
|
namespace Meritoo\Common\Test\Utilities;
|
||||||
|
|
||||||
use Meritoo\Common\Utilities\TestCase;
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
use Meritoo\Common\Utilities\Uri;
|
use Meritoo\Common\Utilities\Uri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,7 +17,7 @@ use Meritoo\Common\Utilities\Uri;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class UriTest extends TestCase
|
class UriTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function testAddProtocolToUrl()
|
public function testAddProtocolToUrl()
|
||||||
{
|
{
|
||||||
@@ -6,9 +6,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Utilities;
|
namespace Meritoo\Common\Test\Utilities;
|
||||||
|
|
||||||
use Meritoo\Common\Utilities\Xml;
|
use Meritoo\Common\Utilities\Xml;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
use SimpleXMLElement;
|
use SimpleXMLElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,7 +18,7 @@ use SimpleXMLElement;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class XmlTest extends \PHPUnit_Framework_TestCase
|
class XmlTest extends TestCase
|
||||||
{
|
{
|
||||||
private $simpleXml;
|
private $simpleXml;
|
||||||
private $advancedXml;
|
private $advancedXml;
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Utilities\Reflection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The B class.
|
|
||||||
* Used for testing the Reflection class.
|
|
||||||
*
|
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
|
||||||
* @copyright Meritoo.pl
|
|
||||||
*/
|
|
||||||
class B extends A
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Utilities\Reflection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The D class.
|
|
||||||
* Used for testing the Reflection class.
|
|
||||||
*
|
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
|
||||||
* @copyright Meritoo.pl
|
|
||||||
*/
|
|
||||||
class D
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Meritoo\Common\Tests\Utilities\Reflection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The E trait.
|
|
||||||
* Used for testing the Reflection class.
|
|
||||||
*
|
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
|
||||||
* @copyright Meritoo.pl
|
|
||||||
*/
|
|
||||||
trait E
|
|
||||||
{
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user