Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Ouzo Goodies
askalon
post
Post #1





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 30.12.2014

Ostrzeżenie: (0%)
-----


Hej,

Wyodrębniliśmy z frameworka Ouzo najciekawsze funkcjonalności. Dla tych, którzy nie chcą migrować całego projektu (MVC i ORM-a) na Ouzo, teraz wystarczy tylko dodać zależność do Ouzo Goodies i używać m.in. płynnych asercji, mockowania, extractora i wielu innych przydatnych utili.

Więcej na:
https://github.com/letsdrink/ouzo-goodies

Kilka przykładów:

Fluent arrays:
  1. $result = FluentArray::from($users)
  2. ->map(Functions::extractField('name'))
  3. ->filter(Functions::notEmpty())
  4. ->unique()
  5. ->toArray();


Fluent functions:
  1. $product = new Product(['name' => 'super phone']);
  2.  
  3. $function = FluentFunctions::extractField('name')
  4. ->removePrefix('super')
  5. ->prepend(' extra')
  6. ->append('! ')
  7. ->surroundWith("***");
  8.  
  9. $result = Functions::call($function, $product); //=> '*** extra phone! ***'


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


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


Comparators:
  1. $product1 = new Product(['name' => 'b']);
  2. $product2 = new Product(['name' => 'c']);
  3. $product3 = new Product(['name' => 'a']);
  4.  
  5. $result = Arrays::sort([$product1, $product2, $product3], Comparator::compareBy('name'));


Fluent assertions for arrays:
  1. $animals = ['cat', 'dog', 'pig'];
  2. Assert::thatArray($animals)->hasSize(3)->contains('cat');


Fluent assertions for strings:
  1. Assert::thatString("Frodo")
  2. ->startsWith("Fro")
  3. ->endsWith("do")
  4. ->contains("rod")
  5. ->doesNotContain("fro")
  6. ->hasSize(5);


Mocking:
  1. $mock = Mock::mock();
  2. Mock::when($mock)->someMethod('arg')->thenReturn('result');
  3.  
  4. $result = $mock->someMethod('arg');
  5.  
  6. $this->assertEquals("result", $result);


Zapraszamy do korzystania i czekamy na konstruktywny feedback smile.gif

Ten post edytował askalon 30.12.2014, 14:09:55
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 19:10