ouzo-goodies

[READ-ONLY] Utility classes, test assertions and mocking framework extracted from Ouzo framework.

Github星跟踪图

Ouzo Goodies

What is it

Utility classes, test assertions and mocking framework extracted from Ouzo framework. We are compatible with PHP 7.2 and later.

Build Status
Coverage Status
Latest Stable Version
Total Downloads
License

How to use it

Couple of examples.

Fluent arrays:

$result = FluentArray::from($users)
             ->map(Functions::extractField('name'))
             ->filter(Functions::notEmpty())
             ->unique()
             ->toArray();

Fluent iterator:

$result = FluentIterator::fromArray([1, 2, 3])
             ->cycle()
             ->limit(10)
             ->reindex()
             ->toArray(); // [1, 2, 3, 1, 2, 3, 1, 2, 3, 1]

Fluent functions:

$product = new Product(['name' => 'super phone']);

$function = FluentFunctions::extractField('name')
      ->removePrefix('super')
      ->prepend(' extra')
      ->append('! ')
      ->surroundWith("***");

$result = Functions::call($function, $product); //=> '*** extra phone! ***'
$phones = Arrays::filter($products, FluentFunctions::extractField('type')->equals('PHONE'));

Extract (from Functions):

$cities = Arrays::map($users, Functions::extract()->getAddress('home')->city);

Clock:

$string = Clock::now()
    ->plusYears(1)
    ->plusMonths(2)
    ->minusDays(3)
    ->format();

Comparators:

$product1 = new Product(['name' => 'b']);
$product2 = new Product(['name' => 'c']);
$product3 = new Product(['name' => 'a']);

$result = Arrays::sort([$product1, $product2, $product3], Comparator::compareBy('name'));

Fluent assertions for arrays:

$animals = ['cat', 'dog', 'pig'];
Assert::thatArray($animals)->hasSize(3)->contains('cat');

Fluent assertions for strings:

Assert::thatString("Frodo")
     ->startsWith("Fro")
     ->endsWith("do")
     ->contains("rod")
     ->doesNotContain("fro")
     ->hasSize(5);

Mocking:

$mock = Mock::create();
Mock::when($mock)->someMethod('arg')->thenReturn('123');

$result = $mock->someMethod('arg');

$this->assertEquals('123', $result);
Mock::verify($mock)->method('arg');

Exception assertions:

$foo = new Foo();

CatchException::when($foo)->method();

CatchException::assertThat()->isInstanceOf("FooException");

This is just a taste of Ouzo. Look at the documentation for more goodies.

Where to get it

Download from github or simply add composer dependency:

composer require letsdrink/ouzo-goodies

Ouzo Goodies at packagist.

Documentation

Tutorials:

Utilities:

  • Arrays - Helper functions for arrays.
  • FluentArray - Interface for manipulating arrays in a chained fashion.
  • Iterators - Helper functions for iterators.
  • FluentIterator- Interface for manipulating iterators in a chained fashion.
  • Strings - Helper functions for strings.
  • Objects- Helper functions that can operate on any PHP object.
  • Functions - Static utility methods returning closures that can be used with Arrays and FluentArray, or other PHP functions.
  • FluentFunctions - Fluent utility for function composition.
  • Cache - General-purpose cache.
  • Path - Helper functions for path operations.
  • Clock - DateTime replacement.
  • Comparators - Sorting.

Tests:

Check out full docs at http://ouzo.readthedocs.org

PhpStorm plugins:

For ideas, questions, discussions write to ouzo-framework@googlegroups.com.

Support for PHP 5.6, 7.0 and 7.1

Ouzo has dropped support for PHP versions older than 7.2 since Ouzo 2.x. If you want to use Ouzo with PHP 5.6, 7.0 or 7.1, please try Ouzo 1.x branch.

主要指标

概览
名称与所有者letsdrink/ouzo-goodies
主编程语言PHP
编程语言PHP (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2014-12-16 17:41:44
推送于2023-06-28 21:00:51
最后一次提交2023-06-27 18:14:08
发布数7
最新版本名称1.8.0 (发布于 )
第一版名称1.4.0 (发布于 )
用户参与
星数128
关注者数13
派生数5
提交数368
已启用问题?
问题数0
打开的问题数0
拉请求数0
打开的拉请求数0
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?