-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add optional type Resolve #16 * Use php5 compatible version
- Loading branch information
Christian Blank
authored
May 28, 2017
1 parent
437f897
commit 79bd1ff
Showing
8 changed files
with
120 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace spec\StructureCheck\Type; | ||
|
||
use StructureCheck\Result; | ||
use StructureCheck\Type\OptionalType; | ||
use PhpSpec\ObjectBehavior; | ||
use StructureCheck\Type\TypeInterface; | ||
|
||
class OptionalTypeSpec extends ObjectBehavior | ||
{ | ||
function it_is_initializable(TypeInterface $childType) | ||
{ | ||
$this->beConstructedWith($childType); | ||
$this->shouldHaveType(OptionalType::class); | ||
} | ||
|
||
function it_should_return_the_value_from_the_child(TypeInterface $childType) { | ||
$this->beConstructedWith($childType); | ||
$childType->check(false)->willReturn(new Result(false, [])); | ||
$this->check(false)->isValid()->shouldBe(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace StructureCheck\Type; | ||
|
||
use StructureCheck\ResultInterface; | ||
|
||
/** | ||
* Class OptionalType | ||
* @package StructureCheck\Type | ||
* @author Christian Blank <[email protected]> | ||
*/ | ||
class OptionalType implements TypeInterface | ||
{ | ||
/** | ||
* @var TypeInterface | ||
*/ | ||
private $child; | ||
|
||
/** | ||
* OptionalType constructor. | ||
* @param TypeInterface $child | ||
*/ | ||
public function __construct(TypeInterface $child) | ||
{ | ||
$this->child = $child; | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
* | ||
* @return ResultInterface | ||
*/ | ||
public function check($value) | ||
{ | ||
return $this->child->check($value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace StructureCheck\Test\Integration\Type; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use StructureCheck\Checker; | ||
use StructureCheck\CheckerInterface; | ||
use StructureCheck\Type\AnyType; | ||
use StructureCheck\Type\ObjectType; | ||
use StructureCheck\Type\OptionalType; | ||
|
||
/** | ||
* Class ObjectTypeTest | ||
* @package StructureCheck\Test\Integration\Type | ||
* @author Christian Blank <[email protected]> | ||
*/ | ||
class ObjectTypeTest extends TestCase | ||
{ | ||
/** | ||
* @var CheckerInterface | ||
*/ | ||
private $checker; | ||
|
||
/** | ||
* | ||
*/ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->checker = new Checker(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itShouldHandleAbsenceOfOptionalDeclaredType() | ||
{ | ||
$structure = new ObjectType([ | ||
'opt' => new OptionalType(new AnyType()) | ||
]); | ||
|
||
$actual = $structure->check([]); | ||
|
||
$this->assertSame(true, $actual->isValid()); | ||
} | ||
} |