forked from boundedcontext/bounded-context
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from m1x0n/feature/invariant-messages
Invariant messages
- Loading branch information
Showing
8 changed files
with
118 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
vendor/ | ||
.idea/tasks.xml | ||
.idea/workspace.xml | ||
.idea/ |
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,18 @@ | ||
<?php | ||
|
||
use BoundedContext\Contracts\Core\Collectable; | ||
|
||
class CollectableItem implements Collectable | ||
{ | ||
protected $secret; | ||
|
||
public function __construct($value) | ||
{ | ||
$this->secret = $value; | ||
} | ||
|
||
public function value() | ||
{ | ||
return $this->secret; | ||
} | ||
} |
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,8 @@ | ||
<?php | ||
|
||
use BoundedContext\Contracts\Projection\Queryable; | ||
|
||
class FakeQueryable implements Queryable | ||
{ | ||
|
||
} |
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,44 @@ | ||
<?php | ||
|
||
use BoundedContext\Contracts\Business\Invariant; | ||
|
||
class InvariantMessagesTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public function test_valid_positive_assumption() | ||
{ | ||
$exists = true; | ||
$invariant = new LogicInvariant(new FakeQueryable()); | ||
$invariant->assuming([$exists])->asserts(); | ||
} | ||
|
||
public function test_invalid_positive_assumption() | ||
{ | ||
$this->setExpectedException( | ||
Invariant\Exception::class, | ||
'Universe does exist' | ||
); | ||
|
||
$exists = true; | ||
$invariant = new LogicInvariant(new FakeQueryable()); | ||
$invariant->assuming([$exists])->not()->asserts(); | ||
} | ||
|
||
public function test_valid_negative_assumption() | ||
{ | ||
$exists = false; | ||
$invariant = new LogicInvariant(new FakeQueryable()); | ||
$invariant->assuming([$exists])->not()->asserts(); | ||
} | ||
|
||
public function test_invalid_negative_assumption() | ||
{ | ||
$this->setExpectedException( | ||
Invariant\Exception::class, | ||
"Universe does not exist" | ||
); | ||
|
||
$exists = false; | ||
$invariant = new LogicInvariant(new FakeQueryable()); | ||
$invariant->assuming([$exists])->asserts(); | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
use BoundedContext\Business\Invariant\AbstractInvariant; | ||
use BoundedContext\Contracts\Business\Invariant\Invariant; | ||
|
||
class LogicInvariant extends AbstractInvariant implements Invariant | ||
{ | ||
protected $error_message_positive = "Universe does exist"; | ||
protected $error_message_negative = "Universe does not exist"; | ||
|
||
protected $flag; | ||
|
||
protected function assumptions($flag) | ||
{ | ||
$this->flag = $flag; | ||
} | ||
|
||
protected function satisfier() | ||
{ | ||
return !!$this->flag; | ||
} | ||
} |