Пример #1
0
 public function testGetWithoutArgumentsAndConstructor()
 {
     $some = new \PhpOption\LazyOption(array($this->subject, 'execute'));
     $this->subject->expects($this->once())->method('execute')->will($this->returnValue(\PhpOption\Some::create('foo')));
     $this->assertEquals('foo', $some->get());
     $this->assertEquals('foo', $some->getOrElse(null));
     $this->assertEquals('foo', $some->getOrCall('does_not_exist'));
     $this->assertEquals('foo', $some->getOrThrow(new \RuntimeException('does_not_exist')));
     $this->assertFalse($some->isEmpty());
 }
Пример #2
0
 public function testOrElse()
 {
     $some = \PhpOption\Some::create('foo');
     $lazy = \PhpOption\LazyOption::create(function() use ($some) {return $some;});
     $this->assertSame($some, $lazy->orElse(\PhpOption\None::create()));
     $this->assertSame($some, $lazy->orElse(\PhpOption\Some::create('bar')));
 }
Пример #3
0
 public function testFoldLeftRight()
 {
     $callback = function () {
     };
     $option = $this->getMockForAbstractClass('PhpOption\\Option');
     $option->expects($this->once())->method('foldLeft')->with(5, $callback)->will($this->returnValue(6));
     $lazyOption = new LazyOption(function () use($option) {
         return $option;
     });
     $this->assertSame(6, $lazyOption->foldLeft(5, $callback));
     $option->expects($this->once())->method('foldRight')->with(5, $callback)->will($this->returnValue(6));
     $lazyOption = new LazyOption(function () use($option) {
         return $option;
     });
     $this->assertSame(6, $lazyOption->foldRight(5, $callback));
 }
Пример #4
0
 /**
  * @param array $criteria
  * @param array $orderBy
  * @return PhpOption\Option
  */
 public function findOneBy(array $criteria, array $orderBy = null)
 {
     return PhpOption\LazyOption::create(array($this, '__phpOption_findOneBy_Callback'), array($criteria, $orderBy));
 }