Created
April 19, 2014 23:31
-
-
Save nexik/11100704 to your computer and use it in GitHub Desktop.
SpecBDD in Codeception
This file contains hidden or 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
| <?php | |
| namespace Codeception\Module; | |
| use Codeception\Module; | |
| use Codeception\PHPUnit\AssertWrapper; | |
| use Closure; | |
| class DevHelper extends Module | |
| { | |
| private $testSubject; | |
| /** | |
| * @param callable $callable | |
| * @param array $params | |
| * @return \Codeception\Module\Result | |
| */ | |
| public function specify(Closure $callable, $params = []) | |
| { | |
| $test = $callable->bindTo($this->getTestSubject()); | |
| return new Result(call_user_func_array($test, $params)); | |
| } | |
| public function getTestSubject() | |
| { | |
| return $this->testSubject; | |
| } | |
| public function setTestSubject($subject) | |
| { | |
| $this->testSubject = $subject; | |
| return $this; | |
| } | |
| } | |
| class Result extends AssertWrapper | |
| { | |
| public function __construct($result) | |
| { | |
| $this->result = $result; | |
| } | |
| public function shouldReturn($value) | |
| { | |
| $this->assert(array('Equals', $this->result, $value)); | |
| } | |
| } |
This file contains hidden or 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
| <?php | |
| /** | |
| * This file is part Phalcon Nest (Phalcon SOLID bootstrap project for RAD) | |
| * | |
| * For the full copyright and license information, please view the LICENSE | |
| * file that was distributed with this source code. | |
| * | |
| * @license MIT | |
| */ | |
| namespace Nest; | |
| /** | |
| * Registry | |
| * | |
| * @author Tomasz Ślązok <[email protected]> | |
| */ | |
| class Registry | |
| { | |
| /** | |
| * @var array | |
| */ | |
| private $registry = []; | |
| /** | |
| * @param $key | |
| * @param null $default | |
| * @return null | |
| */ | |
| public function get($key, $default = null) | |
| { | |
| if (isset($this->registry[$key])) { | |
| return $this->registry[$key]; | |
| } | |
| return $default; | |
| } | |
| /** | |
| * @param $key | |
| * @param $value | |
| */ | |
| public function set($key, $value) | |
| { | |
| $this->registry[$key] = $value; | |
| } | |
| } |
This file contains hidden or 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
| <?php | |
| namespace unit; | |
| use Nest\Registry; | |
| /** | |
| * unit/RegistryCest | |
| * | |
| * @mixin \Nest\Registry | |
| * @author Tomasz Ślązok <[email protected]> | |
| */ | |
| class RegistryCest | |
| { | |
| public function testRegistry(\Dev $developer) | |
| { | |
| $developer->setTestSubject(new Registry()); | |
| $developer->expect('Registry return null for non existed key'); | |
| $developer->specify(function () { | |
| return $this->get('non_existed'); | |
| })->shouldReturn(null); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I see two possibilities:
Of course we can invented new syntax for Specifications but I think this is out of scope for me now.