This repository has been archived by the owner on May 4, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a2cd9e4
Showing
10 changed files
with
451 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2010 Konstantin Kudryashov <ever.zet@gmail.com> | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
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,89 @@ | ||
# sfBehatPlugin # | ||
|
||
*Cucumber-style BDD in symfony.* | ||
|
||
sfBehatPlugin is a plugin for symfony applications. It help to write Cucumber-like Behat features to test symfony applications. | ||
|
||
## Prerequisites ## | ||
|
||
1. Behat is written on PHP 5.3, so you need PHP 5.3.2 to run your features; | ||
2. Download last version of Behat from [http://github.com/everzet/Behat](http://github.com/everzet/Behat); | ||
3. Symlink `Behat/bin/behat` to your bin folder (`/usr/local/bin` for example). | ||
|
||
## Installation ## | ||
|
||
### Using git clone ### | ||
|
||
Use this to install as a plugin in a symfony app: | ||
|
||
$ cd plugins && git clone git://github.com/everzet/sfBehatPlugin.git | ||
|
||
### Using git submodules ### | ||
|
||
Use this if you prefer to use git submodules for plugins: | ||
|
||
$ git submodule add git://github.com/everzet/sfBehatPlugin.git plugins/sfBehatPlugin | ||
$ git submodule init | ||
$ git submodule update | ||
|
||
and enable plugin in your ProjectConfigurations class. | ||
|
||
## Usage ## | ||
|
||
### Prepare ### | ||
|
||
After installation, you need to create features folders for your applications inside symfony's `test` folder. To do this, simply run: | ||
|
||
symfony behat:generate frontend | ||
|
||
where `frontend` is your application name. | ||
|
||
### Generate Features ### | ||
|
||
To begin with Behat, you need to create your first feature file. Run: | ||
|
||
symfony behat:generate-feature frontend main | ||
|
||
where `frontend` & `main` is your application & module names to test | ||
|
||
### Run Features ### | ||
|
||
You can either run all app tests with: | ||
|
||
behat test/features/frontend | ||
|
||
or specific feature with: | ||
|
||
behat test/features/frontend/main.feature | ||
|
||
## Write Features ## | ||
|
||
### Available Steps ### | ||
|
||
To see available steps - open `steps/browser_steps.php` under your app features. | ||
|
||
### Write New Steps ### | ||
|
||
You can create new steps simply by placing definitions in any `*.php` file under `steps/` folder in your app features. | ||
|
||
### Specify App Routes ### | ||
|
||
sfBehatPlugin has base steps to run over your application. One of them is `/^I am on(?: the)? (.*)$/`. This step tries to guess page path from route names, but you can specify path manually in `support/paths.php`: | ||
|
||
<?php | ||
$this->pathTo = function($page) use($world) { | ||
switch ($page) { | ||
|
||
case 'articles list': | ||
return '/articles/list'; | ||
|
||
} | ||
}; | ||
|
||
|
||
## Contributors ## | ||
|
||
* everzet (lead): [http://github.com/everzet](http://github.com/everzet) | ||
|
||
Behat is maintained by ever.zet [http://github.com/everzet](http://github.com/everzet) | ||
Cucumber is maintained by aslakhellesoy [http://github.com/aslakhellesoy](http://github.com/aslakhellesoy) |
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,23 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the sfBehatPlugin package. | ||
* (c) 2010 Konstantin Kudryashov <ever.zet@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
class sfBehatLimeNoOutput extends lime_output | ||
{ | ||
public function __construct($force_colors = false, $base_dir = null) {} | ||
public function diag() {} | ||
public function comment($message) {} | ||
public function info($message) {} | ||
public function error($message, $file = null, $line = null, $traces = array()) {} | ||
protected function print_trace($method = null, $file = null, $line = null) {} | ||
public function echoln($message, $colorizer_parameter = null, $colorize = true) {} | ||
public function green_bar($message) {} | ||
public function red_bar($message) {} | ||
protected function strip_base_dir($text) {} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the sfBehatPlugin package. | ||
* (c) 2010 Konstantin Kudryashov <ever.zet@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
// Require PHPUnit assertions | ||
require_once 'PHPUnit/Autoload.php'; | ||
require_once 'PHPUnit/Framework/Assert/Functions.php'; | ||
|
||
// Hide lime output | ||
require_once sfConfig::get('sf_symfony_lib_dir') . '/vendor/lime/lime.php'; | ||
require_once __DIR__ . '/../lime/sfBehatLimeNoOutput.class.php'; | ||
|
||
// Init site browser | ||
$tester = new lime_test(null, array('output' => new sfBehatLimeNoOutput())); | ||
$this->browser = new sfTestFunctional(new sfBrowser(), $tester); | ||
|
||
// Helpful closures | ||
$this->getRequest = function() use($world) { | ||
return $world->browser->getRequest(); | ||
}; | ||
$this->getContext = function() use($world) { | ||
return $world->browser->getContext(); | ||
}; | ||
$this->getResponse = function() use($world) { | ||
return $world->browser->getResponse(); | ||
}; | ||
|
||
$this->guessPath = function($page) use($world) { | ||
$routes = sfContext::getInstance()->getRouting()->getRoutes(); | ||
$route = strtolower(strtr($page, array(' ' => '_'))); | ||
|
||
if (array_key_exists($route, $routes)) { | ||
return strtr($routes[$route]->getPattern(), array(':sf_format' => 'html')); | ||
} else { | ||
return $world->pathTo($page); | ||
} | ||
}; |
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,74 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the sfBehatPlugin package. | ||
* (c) 2010 Konstantin Kudryashov <ever.zet@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/** | ||
* Feature generating task | ||
* | ||
* @package sfBehatPlugin | ||
* @author Konstantin Kudryashov <ever.zet@gmail.com> | ||
*/ | ||
class behatGenerateFeatureTask extends sfBaseTask | ||
{ | ||
protected function configure() | ||
{ | ||
$this->addArguments(array( | ||
new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'), | ||
new sfCommandArgument('module', sfCommandArgument::REQUIRED, 'The module name') | ||
)); | ||
|
||
$this->namespace = 'behat'; | ||
$this->name = 'generate-feature'; | ||
$this->briefDescription = 'Generates feature'; | ||
$this->detailedDescription = <<<EOF | ||
The [behat:generate-feature|INFO] task generates feature for specific module. | ||
Call it with: | ||
[php symfony behat:generate-feature|INFO] | ||
EOF; | ||
} | ||
|
||
protected function execute($arguments = array(), $options = array()) | ||
{ | ||
$app = $arguments['application']; | ||
$module = $arguments['module']; | ||
|
||
$featurePath = sfConfig::get('sf_test_dir').'/features/'.$app.'/'.$module.'.feature'; | ||
|
||
if (!is_dir($testAppDir)) | ||
{ | ||
throw new sfCommandException(sprintf('The app "%s" features doesn\'t exists. Create features folder with `behat:genereate`', $testAppDir)); | ||
} | ||
|
||
if (is_file($featurePath)) | ||
{ | ||
throw new sfCommandException(sprintf('The feature "%s" already exists in app.', $module, $app)); | ||
} | ||
|
||
if (is_readable(sfConfig::get('sf_data_dir').'/skeleton/feature')) | ||
{ | ||
$skeletonDir = sfConfig::get('sf_data_dir').'/skeleton/feature'; | ||
} | ||
else | ||
{ | ||
$skeletonDir = dirname(__FILE__).'/skeleton/feature'; | ||
} | ||
|
||
$constants = array( | ||
'APP_NAME' => $app, | ||
'MODULE_NAME' => $module | ||
); | ||
|
||
// create basic feature | ||
$this->getFilesystem()->copy($skeletonDir.'/feature.feature', $featurePath); | ||
|
||
// customize feature file | ||
$this->getFilesystem()->replaceTokens($featurePath, '##', '##', $constants); | ||
} | ||
} |
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,62 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the sfBehatPlugin package. | ||
* (c) 2010 Konstantin Kudryashov <ever.zet@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/** | ||
* Features folder generator task | ||
* | ||
* @package sfBehatPlugin | ||
* @author Konstantin Kudryashov <ever.zet@gmail.com> | ||
*/ | ||
class behatGenerateTask extends sfBaseTask | ||
{ | ||
protected function configure() | ||
{ | ||
$this->addArguments(array( | ||
new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'), | ||
)); | ||
|
||
$this->addOptions(array( | ||
new sfCommandOption('override', null, sfCommandOption::PARAMETER_NONE, 'Overwrite old files with new'), | ||
)); | ||
|
||
$this->namespace = 'behat'; | ||
$this->name = 'generate'; | ||
$this->briefDescription = 'Generates features folder'; | ||
$this->detailedDescription = <<<EOF | ||
The [behat:generate|INFO] task generates features folder for specific app. | ||
Call it with: | ||
[php symfony behat:generate|INFO] | ||
EOF; | ||
} | ||
|
||
protected function execute($arguments = array(), $options = array()) | ||
{ | ||
$app = $arguments['application']; | ||
$override = $options['override']; | ||
|
||
$testAppDir = sfConfig::get('sf_test_dir').'/features/'.$app; | ||
|
||
if (is_readable(sfConfig::get('sf_data_dir').'/skeleton/features')) | ||
{ | ||
$skeletonDir = sfConfig::get('sf_data_dir').'/skeleton/features'; | ||
} | ||
else | ||
{ | ||
$skeletonDir = dirname(__FILE__).'/skeleton/features'; | ||
} | ||
|
||
// create basic application features | ||
$finder = sfFinder::type('any')->discard('.sf'); | ||
$this->getFilesystem()->mirror($skeletonDir.'/app', $testAppDir, $finder, array( | ||
'override' => $override | ||
)); | ||
} | ||
} |
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,7 @@ | ||
Feature: ##MODULE_NAME## | ||
|
||
Scenario: Index page | ||
Given I am on homepage | ||
When I go to ##MODULE_NAME##/index | ||
Then Response status code is 200 | ||
And I should see "This is a temporary page" |
Oops, something went wrong.