[ Avaa Bypassed ]




Upload:

Command:

hmhc3928@18.225.55.42: ~ $
<?php

namespace PhpOption\Tests;

use PhpOption\None;
use PhpOption\Option;
use PhpOption\Some;

/**
 * Tests for Option::ensure() method
 *
 * @covers \PhpOption\Option::ensure
 */
class EnsureTest extends \PHPUnit_Framework_TestCase
{
    protected function ensure($value, $noneValue = null)
    {
        $option = Option::ensure($value, $noneValue);
        $this->assertInstanceOf('PhpOption\Option', $option);
        return $option;
    }

    public function testMixedValue()
    {
        $option = $this->ensure(1);
        $this->assertTrue($option->isDefined());
        $this->assertSame(1, $option->get());
        $this->assertFalse($this->ensure(null)->isDefined());
        $this->assertFalse($this->ensure(1,1)->isDefined());
    }

    public function testReturnValue()
    {
        $option = $this->ensure(function() { return 1; });
        $this->assertTrue($option->isDefined());
        $this->assertSame(1, $option->get());
        $this->assertFalse($this->ensure(function() { return null; })->isDefined());
        $this->assertFalse($this->ensure(function() { return 1; }, 1)->isDefined());
    }

    public function testOptionReturnsAsSameInstance()
    {
        $option = $this->ensure(1);
        $this->assertSame($option, $this->ensure($option));
    }

    public function testOptionReturnedFromClosure()
    {
        $option = $this->ensure(function() { return Some::create(1); });
        $this->assertTrue($option->isDefined());
        $this->assertSame(1, $option->get());

        $option = $this->ensure(function() { return None::create(); });
        $this->assertFalse($option->isDefined());
    }

    public function testClosureReturnedFromClosure()
    {
        $option = $this->ensure(function() { return function() {}; });
        $this->assertTrue($option->isDefined());
        $this->assertInstanceOf('Closure', $option->get());
    }
}

Filemanager

Name Type Size Permission Actions
EnsureTest.php File 1.85 KB 0644
LazyOptionTest.php File 6.29 KB 0644
NoneTest.php File 3.02 KB 0644
OptionTest.php File 2.9 KB 0644
PerformanceTest.php File 2.12 KB 0644
SomeTest.php File 5.23 KB 0644