public function testOrElseOnSomeWithCallback()
 {
     $option = Option::create(0)->orElse(function () {
         throw new RuntimeException('orElse on some');
     });
     $this->assertSame(0, $option->get());
 }
 public function testTestGetOrCallOnSome()
 {
     $value = Option::create(0)->getOrCall(function () {
         return 1;
     });
     $this->assertSame(0, $value);
 }
Beispiel #3
0
 public function __construct()
 {
     parent::__construct();
     $this->mapIdentity = function ($value) {
         return $value;
     };
     $this->mapIdentityOption = function ($value) {
         return Option::create($value);
     };
 }
 public function testEachOnSome()
 {
     $option = Option::create(0)->each(function ($value) {
         $this->assertSame(0, $value);
     });
 }
 public function testMagicInvokeOnSomeWithoutParameter()
 {
     $option = Option::create(0);
     $this->assertSame(0, $option());
 }
 public function testGetOrElseOnSomeWithCallback()
 {
     $this->assertSame(0, Option::create(0)->getOrElse(function () {
         throw new RuntimeException('getOrElse on some');
     }));
 }
 public function testMagicGetOnArrayWithoutKey()
 {
     $array = ['defined' => ['key' => 0]];
     $this->assertSame($this->none, Option::create($array)->undefined->key);
 }
 public function testMagicIssetOnArrayWithoutKey()
 {
     $array = ['defined' => ['key' => 0]];
     $this->assertFalse(isset(Option::create($array)->undefined->key));
 }
 public function testCreateNoneFromCallbackWithCustomEmptyCallback()
 {
     $option = Option::create(function () {
         return 0;
     }, function ($value) {
         return $value === 0;
     });
     $this->assertSame($this->none, $option);
 }
Beispiel #10
0
 public function orElse($default)
 {
     return Option::create($this->getOrElse($default));
 }
Beispiel #11
0
 public function testGetOnSome()
 {
     $this->assertSame(0, Option::create(0)->get());
 }
Beispiel #12
0
 public function __get($name)
 {
     return Option::create($this->getPropertyOrKey($name));
 }
 public function testGetOrThrowOnSome()
 {
     $this->assertSame(0, Option::create(0)->getOrThrow(new RuntimeException()));
 }
 public function testMagicToStringOnSome()
 {
     $this->assertSame('0', (string) Option::create(0));
 }