Skip to content

Instantly share code, notes, and snippets.

@jrub
Created July 7, 2011 09:22
Show Gist options
  • Save jrub/1069169 to your computer and use it in GitHub Desktop.
Save jrub/1069169 to your computer and use it in GitHub Desktop.
All wrong. See http://goo.gl/RKKAp . // Trying to get Mink RC1 working with MinkBundle using old closures steps style
<?php
namespace MyProject\MyBundle\Features\Context;
use Behat\Behat\Context\ClosuredContextInterface as ClosuredContext,
Behat\Behat\Context\TranslatedContextInterface as TranslatedContext,
Behat\Behat\Context\BehatContext;
use Behat\Mink\Behat\Context\MinkContext;
use Symfony\Component\Finder\Finder;
// load features/support/bootstrap.php file if it exists
if (file_exists(__DIR__ . '/../support/bootstrap.php')) {
require_once __DIR__ . '/../support/bootstrap.php';
}
/**
* LS feature context with closure definitions.
*/
class ClosuredFeatureContext extends MinkContext implements ClosuredContext, TranslatedContext
{
/**
* Environment parameters.
*
* @var array
*/
public $parameters = array();
/**
* Initializes context.
*
* @param array $parameters
*/
public function __construct(array $parameters) {
$this->parameters = $parameters;
// load features/support/env.php file if it exists
if (file_exists(__DIR__ . '/../support/env.php')) {
$world = $this;
require(__DIR__ . '/../support/env.php');
}
parent::__construct($parameters);
}
/**
* Returns list of step definition files.
*
* @see Behat\Behat\Context\ClosuredContextInterface::getStepDefinitionResources()
*
* @return array
*/
public function getStepDefinitionResources() {
// find and return all *.php files under features/steps folder
if (file_exists(__DIR__ . '/../steps')) {
$finder = new Finder();
return $finder->files()->name('*.php')->in(__DIR__ . '/../steps');
}
return array();
}
/**
* Returns list of hook definition files.
*
* @see Behat\Behat\Context\ClosuredContextInterface::getHookDefinitionResources()
*
* @return array
*/
public function getHookDefinitionResources() {
// return array of features/support/hooks.php if it exists
if (file_exists(__DIR__ . '/../support/hooks.php')) {
return array(__DIR__ . '/../support/hooks.php');
}
return array();
}
/**
* Returns list of XLIFF translation files.
*
* @see Behat\Behat\Context\TranslatedContextInterface::getTranslationResources()
*
* @return array
*/
public function getTranslationResources() {
// find and return all *.xliff files under features/steps/i18n folder
if (file_exists(__DIR__ . '/../steps/i18n')) {
$finder = new Finder();
return $finder->files()->name('*.xliff')->in(__DIR__ . '/../steps/i18n');
}
return array();
}
/**
* Calls previously saved on $world closure function.
*
* @param string $name function name
* @param array $args function args
*
* @return mixed
*/
public function __call($name, array $args) {
if (isset($this->$name) && is_callable($this->$name)) {
return call_user_func_array($this->$name, $args);
} else {
$trace = debug_backtrace();
trigger_error(
'Call to undefined method ' . get_class($this) . '::' . $name .
' in ' . $trace[0]['file'] .
' on line ' . $trace[0]['line'],
E_USER_ERROR
);
}
}
}
<?php
namespace MyProject\MyBundle\Features\Context;
use Behat\Behat\Context\ClosuredContextInterface as ClosuredContext,
Behat\Behat\Context\TranslatedContextInterface as TranslatedContext,
Behat\Behat\Context\BehatContext;
use Behat\Mink\Behat\Context\MinkContext;
use Symfony\Component\Finder\Finder;
// load features/support/bootstrap.php file if it exists
if (file_exists(__DIR__ . '/../support/bootstrap.php')) {
require_once __DIR__ . '/../support/bootstrap.php';
}
/**
* LS feature context with closure definitions.
*/
class ClosuredFeatureContext extends MinkContext implements ClosuredContext, TranslatedContext
{
/**
* Environment parameters.
*
* @var array
*/
public $parameters = array();
public function __construct($kernel) {
// don't need loading old env.php, it's empty
parent::__construct();
}
/**
* Returns list of step definition files.
*
* @see Behat\Behat\Context\ClosuredContextInterface::getStepDefinitionResources()
*
* @return array
*/
public function getStepDefinitionResources() {
// find and return all *.php files under features/steps folder
if (file_exists(__DIR__ . '/../steps')) {
$finder = new Finder();
return $finder->files()->name('*.php')->in(__DIR__ . '/../steps');
}
return array();
}
/**
* Returns list of hook definition files.
*
* @see Behat\Behat\Context\ClosuredContextInterface::getHookDefinitionResources()
*
* @return array
*/
public function getHookDefinitionResources() {
// return array of features/support/hooks.php if it exists
if (file_exists(__DIR__ . '/../support/hooks.php')) {
return array(__DIR__ . '/../support/hooks.php');
}
return array();
}
/**
* Returns list of XLIFF translation files.
*
* @see Behat\Behat\Context\TranslatedContextInterface::getTranslationResources()
*
* @return array
*/
public function getTranslationResources() {
// find and return all *.xliff files under features/steps/i18n folder
if (file_exists(__DIR__ . '/../steps/i18n')) {
$finder = new Finder();
return $finder->files()->name('*.xliff')->in(__DIR__ . '/../steps/i18n');
}
return array();
}
/**
* Calls previously saved on $world closure function.
*
* @param string $name function name
* @param array $args function args
*
* @return mixed
*/
public function __call($name, array $args) {
if (isset($this->$name) && is_callable($this->$name)) {
return call_user_func_array($this->$name, $args);
} else {
$trace = debug_backtrace();
trigger_error(
'Call to undefined method ' . get_class($this) . '::' . $name .
' in ' . $trace[0]['file'] .
' on line ' . $trace[0]['line'],
E_USER_ERROR
);
}
}
}
imports:
- { resource: config_dev.yml }
framework:
test: ~
session:
storage_id: session.storage.filesystem
web_profiler:
toolbar: false
intercept_redirects: false
behat_mink:
base_url: http://localhost/app_test.php/
#default_session: goutte
#goutte: ~
#sahi: ~
behat:
context:
class: MyProject\MyBundle\Features\Context\ClosuredFeatureContext
swiftmailer:
disable_delivery: true
With ClosuredFeatureContext_Original
===================================
[ErrorException]
Catchable Fatal Error: Argument 1 passed to MyProject\MyBundle\Features\Context\ClosuredFeatureContext::__construct() must be an array, object given, called in /var/www/reload/vendor/Behat/BehatBundle/Context/ContextDispatcher.php on line 50 and defined in /var/www/reload/src/MyProject/MyBundle/Features/Context/ClosuredFeatureContext.php line 35
With ClosuredFeatureContext_UglyHack
====================================
PHP Fatal error: Class 'Goutte\Client' not found in /var/www/reload/vendor/Behat/Mink/src/Behat/Mink/Behat/Context/MinkContext.php on line 639
Fatal error: Class 'Goutte\Client' not found in /var/www/reload/vendor/Behat/Mink/src/Behat/Mink/Behat/Context/MinkContext.php on line 639
jrubio@jrubio-ubuntu:/var/www/reload/vendor/Behat/Mink$ git submodule update --init --recursive
fatal: reference is not a tree: 63f57ab4e2a022277d690e57a6cdc77e018f99e7
Unable to checkout '63f57ab4e2a022277d690e57a6cdc77e018f99e7' in submodule path 'vendor/Goutte'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment