Created
October 15, 2011 11:36
-
-
Save hidenorigoto/1289441 to your computer and use it in GitHub Desktop.
Behat入門
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
# language: ja | |
フィーチャ: 初めてのフィーチャ | |
PHPerとして | |
PHP 5.3.2以降を使いたい | |
なぜならSymfony2が動作する必須要件だからだ | |
シナリオ: PHPのバージョンを調べる | |
もし PHPのバージョン番号を取得する | |
ならば 取得したバージョン番号が "5.3.2" 以上であること |
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
<?php | |
use Behat\Behat\Context\ClosuredContextInterface, | |
Behat\Behat\Context\TranslatedContextInterface, | |
Behat\Behat\Context\BehatContext, | |
Behat\Behat\Exception\PendingException; | |
use Behat\Gherkin\Node\PyStringNode, | |
Behat\Gherkin\Node\TableNode; | |
/** | |
* Features context. | |
*/ | |
class FeatureContext extends BehatContext | |
{ | |
/** | |
* Initializes context. | |
* Every scenario gets it's own context object. | |
* | |
* @param array $parameters context parameters (set them up through behat.yml) | |
*/ | |
public function __construct(array $parameters) | |
{ | |
// Initialize your context here | |
} | |
/** | |
* @Given /^PHPのバージョン番号を取得する$/ | |
*/ | |
public function PHPのバージョン番号を取得する() | |
{ | |
throw new PendingException(); | |
} | |
/** | |
* @Given /^取得したバージョン番号が "([^"]*)" 以上であること$/ | |
*/ | |
public function 取得したバージョン番号が●以上であること($version) | |
{ | |
throw new PendingException(); | |
} | |
} |
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
<?php | |
use Behat\Behat\Context\ClosuredContextInterface, | |
Behat\Behat\Context\TranslatedContextInterface, | |
Behat\Behat\Context\BehatContext, | |
Behat\Behat\Exception\PendingException; | |
use Behat\Gherkin\Node\PyStringNode, | |
Behat\Gherkin\Node\TableNode; | |
/** | |
* Features context. | |
*/ | |
class FeatureContext extends BehatContext | |
{ | |
private $output; | |
/** | |
* Initializes context. | |
* Every scenario gets it's own context object. | |
* | |
* @param array $parameters context parameters (set them up through behat.yml) | |
*/ | |
public function __construct(array $parameters) | |
{ | |
// Initialize your context here | |
} | |
/** | |
* @Given /^PHPのバージョン番号を取得する$/ | |
*/ | |
public function PHPのバージョン番号を取得する() | |
{ | |
$this->output = phpversion(); | |
} | |
/** | |
* @Given /^取得したバージョン番号が "([^"]*)" 以上であること$/ | |
*/ | |
public function 取得したバージョン番号が●以上であること($version) | |
{ | |
if (false === version_compare($this->output, $version, '>=')) { | |
throw new Exception( | |
'取得したバージョン番号は' . $this->output | |
); | |
} | |
} | |
} |
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
<?php | |
use Behat\Behat\Context\ClosuredContextInterface, | |
Behat\Behat\Context\TranslatedContextInterface, | |
Behat\Behat\Context\BehatContext, | |
Behat\Behat\Exception\PendingException; | |
use Behat\Gherkin\Node\PyStringNode, | |
Behat\Gherkin\Node\TableNode; | |
require_once __DIR__ . '/../../Domain/Environment.php'; | |
/** | |
* Features context. | |
*/ | |
class FeatureContext extends BehatContext | |
{ | |
private $output; | |
/** | |
* Initializes context. | |
* Every scenario gets it's own context object. | |
* | |
* @param array $parameters context parameters (set them up through behat.yml) | |
*/ | |
public function __construct(array $parameters) | |
{ | |
// Initialize your context here | |
$this->output = null; | |
} | |
/** | |
* @Given /^PHPのバージョン番号を取得する$/ | |
*/ | |
public function PHPのバージョン番号を取得する() | |
{ | |
$env = new Domain\Environment(); | |
$this->output = $env->getPhpVersion(); | |
if (null === $this->output) { | |
throw new Exception( | |
'PHPバージョンの取得失敗' | |
); | |
} | |
} | |
/** | |
* @Given /^取得したバージョン番号が "([^"]*)" 以上であること$/ | |
*/ | |
public function 取得したバージョン番号が●以上であること($version) | |
{ | |
if (false === version_compare($this->output, $version, '>=')) { | |
throw new Exception( | |
'取得したバージョン番号は' . $this->output | |
); | |
} | |
} | |
} |
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
<?php | |
namespace Domain; | |
class Environment | |
{ | |
public function getPhpVersion() | |
{ | |
return phpversion(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment