-
Notifications
You must be signed in to change notification settings - Fork 22
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 #8 from pdaw/master
Integration with beberlei/assert library, resolves #3
- Loading branch information
Showing
8 changed files
with
198 additions
and
40 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,2 +1,3 @@ | ||
/vendor/ | ||
composer.lock | ||
/tests/cache/ |
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 |
---|---|---|
@@ -1,27 +1,51 @@ | ||
<?php | ||
/** | ||
* PHP Deal framework | ||
* | ||
* @copyright Copyright 2014, Lisachenko Alexander <lisachenko.it@gmail.com> | ||
* | ||
* This source file is subject to the license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace PhpDeal\Functional; | ||
|
||
use PhpDeal\Exception\ContractViolation; | ||
use PhpDeal\Stub\EnsureStub; | ||
|
||
class EnsureContractTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var EnsureStub | ||
*/ | ||
private $stub; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->stub = new EnsureStub(); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
unset($this->stub); | ||
parent::tearDown(); | ||
} | ||
|
||
public function testEnsureValid() | ||
{ | ||
$ensureStub = new EnsureStub(); | ||
$ensureStub->increment(50); | ||
$this->stub->increment(50); | ||
} | ||
|
||
/** | ||
* @expectedException \PhpDeal\Exception\ContractViolation | ||
*/ | ||
public function testEnsureInvalid() | ||
{ | ||
$this->setExpectedException(ContractViolation::class); | ||
$ensureStub = new EnsureStub(); | ||
$ensureStub->badIncrement(40); | ||
$this->stub->badIncrement(40); | ||
} | ||
|
||
public function testEnsureCanHandleResult() | ||
{ | ||
$ensureStub = new EnsureStub(); | ||
$ensureStub->returnPrivateValue(); | ||
$this->stub->returnPrivateValue(); | ||
} | ||
} |
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,29 +1,55 @@ | ||
<?php | ||
/** | ||
* PHP Deal framework | ||
* | ||
* @copyright Copyright 2014, Lisachenko Alexander <lisachenko.it@gmail.com> | ||
* | ||
* This source file is subject to the license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace PhpDeal\Functional; | ||
|
||
use PhpDeal\Exception\ContractViolation; | ||
use PhpDeal\Stub\Speed; | ||
|
||
class InvariantContractTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var Speed | ||
*/ | ||
private $stub; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->stub = new Speed(); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
unset($this->stub); | ||
parent::tearDown(); | ||
} | ||
|
||
public function testInvariantValid() | ||
{ | ||
$speed = new Speed(); | ||
$speed->accelerate(10, 30); // let's have a speed 300m/s | ||
$this->stub->accelerate(10, 30); // let's have a speed 300m/s | ||
} | ||
|
||
/** | ||
* @expectedException \PhpDeal\Exception\ContractViolation | ||
*/ | ||
public function testInvariantViolated() | ||
{ | ||
$this->setExpectedException(ContractViolation::class); | ||
$speed = new Speed(); | ||
$speed->accelerate(10, 3e7); // let's have a speed 3*1e8 m/s, faster than light! | ||
$this->stub->accelerate(10, 3e7); // let's have a speed 3*1e8 m/s, faster than light! | ||
} | ||
|
||
/** | ||
* @expectedException \PhpDeal\Exception\ContractViolation | ||
*/ | ||
public function testInvariantViolatedAfterSeveralMethods() | ||
{ | ||
$this->setExpectedException(ContractViolation::class); | ||
$speed = new Speed(); | ||
$speed->accelerate(10, 30); // let's have a speed 300m/s | ||
$speed->decelerate(20, 20); // Negative speed? | ||
$this->stub->accelerate(10, 30); // let's have a speed 300m/s | ||
$this->stub->decelerate(20, 20); // Negative speed? | ||
} | ||
} |
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,27 +1,84 @@ | ||
<?php | ||
/** | ||
* PHP Deal framework | ||
* | ||
* @copyright Copyright 2014, Lisachenko Alexander <lisachenko.it@gmail.com> | ||
* | ||
* This source file is subject to the license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace PhpDeal\Functional; | ||
|
||
use PhpDeal\Exception\ContractViolation; | ||
use PhpDeal\Stub\VerifyStub; | ||
|
||
class VerifyContractTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var VerifyStub | ||
*/ | ||
private $stub; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->stub = new VerifyStub(); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
unset($this->stub); | ||
parent::tearDown(); | ||
} | ||
|
||
public function testVerifyValid() | ||
{ | ||
$verifyStub = new VerifyStub(); | ||
$verifyStub->testNumeric(-200); | ||
$this->stub->testNumeric(-200); | ||
} | ||
|
||
/** | ||
* @expectedException \PhpDeal\Exception\ContractViolation | ||
*/ | ||
public function testVerifyInvalid() | ||
{ | ||
$this->setExpectedException(ContractViolation::class); | ||
$verifyStub = new VerifyStub(); | ||
$verifyStub->testNumeric('message'); | ||
$this->stub->testNumeric('message'); | ||
} | ||
|
||
public function testAccessToPrivateFields() | ||
{ | ||
$verifyStub = new VerifyStub(); | ||
$verifyStub->testAccessToPrivateField(50); | ||
$this->stub->testAccessToPrivateField(50); | ||
} | ||
|
||
public function testVerifyWithAssertValid() | ||
{ | ||
$this->stub->add(100); | ||
} | ||
|
||
public function providerVerifyWithAssertInvalid() | ||
{ | ||
return [ | ||
[ | ||
'value' => "" | ||
], | ||
[ | ||
'value' => 5.5 | ||
], | ||
[ | ||
'value' => null | ||
], | ||
[ | ||
'value' => [] | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
* @dataProvider providerVerifyWithAssertInvalid | ||
* @expectedException \PhpDeal\Exception\ContractViolation | ||
*/ | ||
public function testVerifyWithAssertInvalid($value) | ||
{ | ||
$this->stub->add($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