forked from greydnls/spec
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding missing basic specification classes
- Loading branch information
Showing
14 changed files
with
205 additions
and
14 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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bakame\Specification; | ||
|
||
final class AndNotX implements Specification | ||
{ | ||
public function __construct( | ||
private Specification $specificationA, | ||
private Specification $specificationB | ||
) { | ||
} | ||
|
||
public function isSatisfiedBy(mixed $subject): bool | ||
{ | ||
return $this->specificationA->isSatisfiedBy($subject) | ||
&& !$this->specificationB->isSatisfiedBy($subject); | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bakame\Specification; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
|
||
final class AndNotXSpec extends ObjectBehavior | ||
{ | ||
public function let(Specification $spec1, Specification $spec2): void | ||
{ | ||
$this->beConstructedWith($spec1, $spec2); | ||
} | ||
|
||
public function it_is_initializable(): void | ||
{ | ||
$this->shouldHaveType(AndNotX::class); | ||
} | ||
|
||
public function it_implements_the_specification_interface(): void | ||
{ | ||
$this->shouldImplement(Specification::class); | ||
} | ||
|
||
public function it_will_pass_with_both_spec_being_satisfied(Specification $spec1, Specification $spec2): void | ||
{ | ||
$spec1->isSatisfiedBy('anything')->willReturn(true); | ||
$spec2->isSatisfiedBy('anything')->willReturn(false); | ||
|
||
$this->isSatisfiedBy('anything')->shouldEqual(true); | ||
} | ||
|
||
public function it_will_fail_with_at_least_one_spec_not_being_satisfied(Specification $spec1, Specification $spec2): void | ||
{ | ||
$spec1->isSatisfiedBy('anything')->willReturn(false); | ||
$spec2->isSatisfiedBy('anything')->willReturn(true); | ||
|
||
$this->isSatisfiedBy('anything')->shouldEqual(false); | ||
} | ||
|
||
public function it_will_fail_with_both_spec_failing(Specification $spec1, Specification $spec2): void | ||
{ | ||
$spec1->isSatisfiedBy('anything')->willReturn(false); | ||
$spec2->isSatisfiedBy('anything')->willReturn(false); | ||
|
||
$this->isSatisfiedBy('anything')->shouldEqual(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bakame\Specification; | ||
|
||
final class AndX implements Specification | ||
|
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
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bakame\Specification; | ||
|
||
final class OrNotX implements Specification | ||
{ | ||
public function __construct( | ||
private Specification $specificationA, | ||
private Specification $specificationB | ||
) { | ||
} | ||
|
||
public function isSatisfiedBy(mixed $subject): bool | ||
{ | ||
return $this->specificationA->isSatisfiedBy($subject) | ||
|| !$this->specificationB->isSatisfiedBy($subject); | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bakame\Specification; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
|
||
final class OrNotXSpec extends ObjectBehavior | ||
{ | ||
public function let(Specification $spec1, Specification $spec2): void | ||
{ | ||
$this->beConstructedWith($spec1, $spec2); | ||
} | ||
|
||
public function it_is_initializable(): void | ||
{ | ||
$this->shouldHaveType(OrNotX::class); | ||
} | ||
|
||
public function it_implements_the_specification_interface(): void | ||
{ | ||
$this->shouldImplement(Specification::class); | ||
} | ||
|
||
public function it_will_pass_with_both_spec_being_satisfied(Specification $spec1, Specification $spec2): void | ||
{ | ||
$spec1->isSatisfiedBy('anything')->willReturn(true); | ||
$spec2->isSatisfiedBy('anything')->willReturn(true); | ||
|
||
$this->isSatisfiedBy('anything')->shouldEqual(true); | ||
} | ||
|
||
public function it_will_pass_with_at_least_one_spec_not_being_satisfied(Specification $spec1, Specification $spec2): void | ||
{ | ||
$spec1->isSatisfiedBy('anything')->willReturn(false); | ||
$spec2->isSatisfiedBy('anything')->willReturn(true); | ||
|
||
$this->isSatisfiedBy('anything')->shouldEqual(false); | ||
} | ||
|
||
public function it_will_fail_with_both_spec_failing(Specification $spec1, Specification $spec2): void | ||
{ | ||
$spec1->isSatisfiedBy('anything')->willReturn(false); | ||
$spec2->isSatisfiedBy('anything')->willReturn(false); | ||
|
||
$this->isSatisfiedBy('anything')->shouldEqual(true); | ||
} | ||
} |
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,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bakame\Specification; | ||
|
||
final class OrX implements Specification | ||
|
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,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bakame\Specification; | ||
|
||
interface Specification | ||
|