Last active
August 29, 2015 14:14
-
-
Save farconada/3ca2fa6e7748eac0a4e9 to your computer and use it in GitHub Desktop.
Behat bug?
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
default: | |
suites: | |
default: | |
contexts: | |
- FeatureContext | |
- behatch:rest | |
- behatch:browser | |
extensions: | |
Behat\Symfony2Extension: | |
kernel: | |
env: test | |
debug: true | |
Behat\MinkExtension: | |
base_url: ~ | |
default_session: my_session | |
sessions: | |
my_session: | |
symfony2: ~ | |
VIPSoft\DoctrineDataFixturesExtension\Extension: | |
lifetime: scenario | |
autoload: true | |
directories: ~ | |
fixtures: ~ | |
Sanpi\Behatch\Extension: ~ |
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
"behat/behat": "*", | |
"sensio/generator-bundle": "~2.3", | |
"phpspec/phpspec": "~2.0@dev", | |
"behat/symfony2-extension": "dev-master", | |
"behatch/contexts": "dev-master", | |
"behat/mink": "1.*@stable", | |
"behat/mink-extension": "*", | |
"behat/mink-browserkit-driver": "*", | |
"behat/mink-goutte-driver": "*", | |
"behat/mink-sahi-driver": "*", |
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
imports: | |
- { resource: config_dev.yml } | |
framework: | |
test: ~ | |
session: | |
storage_id: session.storage.native | |
handler_id: session.handler.native_file | |
profiler: | |
collect: false | |
web_profiler: | |
toolbar: false | |
intercept_redirects: false | |
swiftmailer: | |
disable_delivery: true | |
doctrine: | |
dbal: | |
driver: "pdo_sqlite" | |
path: "%kernel.cache_dir%/test.db" | |
charset: UTF8 | |
liip_functional_test: | |
cache_sqlite_db: true |
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
Cannot change the ID of an active session (500 Internal Server Error) |
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
Scenario: Puedo borrar un objeto Tag por su ID | |
Given I count the "Tag" objects | |
And I select one "Tag" ID | |
When I POST to "/admin/tag/delete" with: | |
|name | type | value | | |
|tag_id | string | {Tag-selected} | | |
|_token | csrf | | | |
Then print last response | |
Then the response status code should be 200 | |
And I have 1 "less" "Tag" objects |
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
class FeatureContext extends MinkContext implements Context, SnippetAcceptingContext, KernelAwareContext { | |
..... | |
/** | |
* @When I POST to :url a form :form_name with: | |
*/ | |
public function iPostToAFormWith($url, $form_name, TableNode $parametersTable) | |
{ | |
$driver = $this->getSession()->getDriver(); | |
if (!$driver instanceof BrowserKitDriver) { | |
throw new \Exception('This step is only supported by the BrowserKitDriver'); | |
} | |
$params = array(); | |
$files = array(); | |
$client = $driver->getClient(); | |
foreach ($parametersTable as $row) { | |
switch ($row['type']) { | |
case "string": | |
$text = $this->replaceIdsInString($row['value']); | |
$params[$form_name][$row['name']] = $text; | |
break; | |
case "boolean": | |
$params[$form_name][$row['name']] = $row['value']; | |
break; | |
case "file": | |
$fileUpload = new UploadedFile($row['value'], 'the_file_name'); | |
$files[$form_name][$row['name']] = $fileUpload; | |
break; | |
case "csrf": | |
$token = $client->getContainer()->get('form.csrf_provider')->generateCsrfToken($form_name); | |
$params[$form_name][$row['name']] = $token; | |
break; | |
} | |
} | |
$client->request('POST', $url, $params, $files); | |
} | |
.... |
This comes from Symfony, not behat: https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/AbstractProxy.php#L123
Do you have any custom listeners that require session?
Background:
Given I am authenticated as "admin"
/**
* @given I am authenticated as :username
*/
public function iAmAuthenticatedAs($username)
{
$driver = $this->getSession()->getDriver();
if (!$driver instanceof BrowserKitDriver) {
throw new \Exception('This step is only supported by the BrowserKitDriver');
}
$client = $driver->getClient();
$client->getCookieJar()->set(new Cookie(session_name(), true));
$session = $this->client->getContainer()->get('session');
$user = $this->kernel->getContainer()->get('fos_user.user_manager')->findUserByUsername($username);
$providerKey = $this->kernel->getContainer()->getParameter('fos_user.firewall_name');
$token = new UsernamePasswordToken($user, null, $providerKey, $user->getRoles());
$session->set('_security_'.$providerKey, serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$this->client->getCookieJar()->set($cookie);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If csrf token is set then error is raised