Skip to content

Commit

Permalink
add tests for Support\Optional
Browse files Browse the repository at this point in the history
  • Loading branch information
binotaliu committed Apr 29, 2018
1 parent 4faf96d commit 4a49ba5
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/Support/SupportOptionalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Illuminate\Tests\Support;

use PHPUnit\Framework\TestCase;
use Illuminate\Support\Optional;

class SupportOptionalTest extends TestCase
{
public function testGetExistItemOnObject()
{
$expected = 'test';

$targetObj = new \stdClass;
$targetObj->item = $expected;

$optional = new Optional($targetObj);

$this->assertEquals($expected, $optional->item);
}

public function testGetNotExistItemOnObject()
{
$targetObj = new \stdClass;

$optional = new Optional($targetObj);

$this->assertNull($optional->item);
}

public function testGetExistItemOnArray()
{
$expected = 'test';

$targetArr = [
'item' => $expected,
];

$optional = new Optional($targetArr);

$this->assertEquals($expected, $optional['item']);
}

public function testGetNotExistItemOnArray()
{
$targetObj = [];

$optional = new Optional($targetObj);

$this->assertNull($optional['item']);
}
}

0 comments on commit 4a49ba5

Please sign in to comment.