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()); }
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'))); }
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)); }
/** * @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)); }