6 Commits
0.0.5 ... 0.0.7

Author SHA1 Message Date
Meritoo
94a464cb4d Readme - TravisCI badge - do not support PHP 7.2, because friendsofphp/php-cs-fixer package can be run using PHP lower than 7.2 only
Details:
$ composer install
Your requirements could not be resolved to an installable set of packages
friendsofphp/php-cs-fixer v2.3.2 requires php ^5.6 || >=7.0 <7.2 -> your PHP version (7.3.0-dev) does not satisfy that requirement
2017-09-19 18:09:13 +02:00
Meritoo
463ee751b2 Readme - TravisCI badge - do not support nightly build of PHP, because friendsofphp/php-cs-fixer pacakge cane be run using maximum PHP 7.2
Details:
$ composer install
Your requirements could not be resolved to an installable set of packages
friendsofphp/php-cs-fixer v2.3.2 requires php ^5.6 || >=7.0 <7.2 -> your PHP version (7.3.0-dev) does not satisfy that requirement
2017-09-19 17:55:41 +02:00
Meritoo
89af7145f6 Readme - TravisCI badge - fix bug related to PHP 5.6 while running PHPUnit
Bug:
PHP Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in tests/Meritoo/Common/Test/Utilities/DateTest.php
2017-09-19 17:53:07 +02:00
Meritoo
09c8569938 Readme - TravisCI badge - update configuration file 2017-09-19 17:37:58 +02:00
Meritoo
5ab2cd9de8 Readme - add badges - TravisCI, Packagist, StyleCI, GitHub commits, GitHub license, Coverage 2017-09-19 17:10:03 +02:00
Meritoo
60eff29e82 Readme - update usage information and add examples 2017-09-19 17:06:29 +02:00
5 changed files with 110 additions and 11 deletions

1
.styleci.yml Normal file
View File

@@ -0,0 +1 @@
preset: symfony

12
.travis.yml Normal file
View File

@@ -0,0 +1,12 @@
language: php
php:
- 5.6
- 7.0
- 7.1
install:
- composer install
script:
- php ./vendor/bin/phpunit

View File

@@ -1,4 +1,4 @@
# Meritoo Common Library
# Meritoo Common Library [![Travis](https://img.shields.io/travis/rust-lang/rust.svg?style=flat-square)](https://travis-ci.org/meritoo/common-library) [![Packagist](https://img.shields.io/packagist/v/meritoo/common-library.svg?style=flat-square)](https://packagist.org/packages/meritoo/common-library) [![StyleCI](https://styleci.io/repos/101790028/shield?branch=master)](https://styleci.io/repos/101790028) [![license](https://img.shields.io/github/license/meritoo/common-library.svg?style=flat-square)](https://github.com/meritoo/common-library) [![GitHub commits](https://img.shields.io/github/commits-since/meritoo/common-library/0.0.1.svg?style=flat-square)](https://github.com/meritoo/common-library) [![Coverage Status](https://coveralls.io/repos/github/meritoo/common-library/badge.svg?branch=master)](https://coveralls.io/github/meritoo/common-library?branch=master)
Useful classes, methods, extensions etc.
## Installation
@@ -11,15 +11,93 @@ Run [Composer](https://getcomposer.org) to install new package:
> 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
use Meritoo\Common\Utilities\Arrays;
$firstElement = Arrays::getFirstElement(['lorem' 'ipsum']);
// result: "lorem"
$firstElement = Arrays::getFirstElement(['lorem', 'ipsum']);
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!

View File

@@ -2,7 +2,7 @@
"name": "meritoo/common-library",
"description": "Useful classes, methods, extensions etc.",
"license": "MIT",
"version": "0.0.5",
"version": "0.0.7",
"authors": [
{
"name": "Meritoo.pl",

View File

@@ -454,8 +454,11 @@ class DateTest extends BaseTestCase
$start = 1;
$end = 100;
$intervalMinDate = (clone $startDate)->add(new DateInterval(sprintf('P%dD', $start)));
$intervalMaxDate = (clone $startDate)->add(new DateInterval(sprintf('P%dD', $end)));
$minDate = clone $startDate;
$maxDate = clone $startDate;
$intervalMinDate = $minDate->add(new DateInterval(sprintf('P%dD', $start)));
$intervalMaxDate = $maxDate->add(new DateInterval(sprintf('P%dD', $end)));
$randomDate = Date::getRandomDate();
self::assertTrue($randomDate >= $intervalMinDate && $randomDate <= $intervalMaxDate);
@@ -471,7 +474,9 @@ class DateTest extends BaseTestCase
public function testGetRandomDateIncorrectEnd(DateTime $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);
}
@@ -487,8 +492,11 @@ class DateTest extends BaseTestCase
{
$randomDate = Date::getRandomDate($startDate, $start, $end);
$intervalMinDate = (clone $startDate)->add(new DateInterval(sprintf('P%dD', $start)));
$intervalMaxDate = (clone $startDate)->add(new DateInterval(sprintf('P%dD', $end)));
$minDate = clone $startDate;
$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);
}