I'm using Symfony 2(latest version) framework and I want to use behat.
I've already inited the Features folder inside my bundle with Context/FeatureConext.php and /xxx.feature
My behat.yml is located in app/config folder of Symfony 2
and is looking like this :
default:
paths:
features : %behat.paths.base%/../src/xxx/myBundle/features
bootstrap: %behat.paths.features%/bootstrap
context:
class: FeatureContext
formatter:
name: progress
extensions:
Behat\Symfony2Extension\Extension:
mink_driver: true
kernel:
env: test
debug: true
Behat\MinkExtension\Extension:
base_url: 'localhost/web/app_dev.php'
default_session: symfony2
suites:
test_suite:
type: symfony_bundle
bundle: 'xxxMyBundleBundle'
How do I exactly specify the path to my feature folder ?
Thanks you.
Thank you Pierre for your answer.
Indeed, behat.yml should be in the root folder but I have read that there is a way to put it in the app/config folder.
Anyway, putting it in the root folder does the trick.
Related
I want to create a lot of Behat features with simulating different configurations (from yaml,xml,php files).
Official extension for support Symfony 4 - Symfony2Extension have support for configuring a different environment like:
default:
# ...
extensions:
Behat\Symfony2Extension:
kernel:
class: App\Kernel
bootstrap: config/bootstrap.php
env: custom_env
But, this extension is loaded before any suites or context. I should initial Kernel for each separate context with different config files via env.
Like:
default:
suites:
default:
contexts:
params:
env: custom_env
- FeatureContext:
or
default:
suites:
default:
contexts:
- FeatureContext:
env: custom_env
And I'll load Kernel manually inside Context.
Any idea here?
I guess you could define different profiles for each env:
default:
# ...
extensions:
Behat\Symfony2Extension:
kernel:
class: App\Kernel
bootstrap: config/bootstrap.php
php_profile:
# ...
extensions:
Behat\Symfony2Extension:
kernel:
env: prod
yaml_profile:
# ...
extensions:
Behat\Symfony2Extension:
kernel:
env: dev
I'm trying to update a Symfony 3.4 application to Symfony 4. On my current applications I always share a local AdminBundle folder inside src. I know Symfony 4 recommends to be "bundle-less" now. But this AdminBundle is the base for most of my projects, and sometimes I make some updates to it that can be deployed to all my projects just pushing to the repository.
I tried to move by AdminBundle inside src but obviously that's not working. Could anyone detail the recipe or configuration needed to make this Bundle work under Symfony 4 in a generic way?
If this is not possible what's the best way to create a reusable code in symfony 4?
I'm currently using a similiar approach:
I've got a "CoreBundle" for shared Services, Entites, Subscribers etc under "src".
In order to make this usable i had to edit the following:
config/maker.yaml -> to use make:entity and create under CoreBundle
maker:
root_namespace: 'App\CoreBundle'
config/packages/doctrine.yaml modify -> to get the Entities from CoreBundle
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/CoreBundle/Entity'
prefix: 'App\CoreBundle\Entity'
alias: App
config/services.yaml add -> to import all SymfonyLike Classes
###> CoreBundle ###
App\CoreBundle\:
resource: '../src/CoreBundle/*'
exclude: '../src/CoreBundle/{DependencyInjection,Entity,Model,Migrations,Tests}'
App\CoreBundle\Controller\:
resource: '../src/CoreBundle/Controller'
tags: ['controller.service_arguments']
###< CoreBundle ###
config/* add -> where i wanted to import a separate config file
imports:
- { resource: '../../src/CoreBundle/Resources/config/*.yaml' }
Im having behat.yml which looks like
machine:
suites:
machine:
contexts:
- MachineContext:
location:
suites:
location:
contexts:
- LocationContext:
And when I run behat -c behat.yml --profile machine it run all my scenarios correct, but when I run behat -c behat.yml --profile location it run scenarios rom location.feature and adds scenariose form machine.feature and tells me that Im missing then
You can inspire from this example. Adjust it for your needs.
default:
extensions:
Behat\MinkExtension:
sessions:
default:
symfony2: ~
Behat\Symfony2Extension:
kernel:
env: test
debug: true
machine:
extensions:
Behat\MinkExtension:
base_url: 'http://machine.domain.com/app_test.php/'
suites:
default:
contexts:
- Path/To/Your/Context/Machine1Context:
- 'constructor parameter if you have any'
- 'and another one'
- 'Path/To/Your/Context/Machine2Context'
type: symfony_bundle
bundle: Whatever1YourBundle
location:
extensions:
Behat\MinkExtension:
base_url: 'http://location.domain.com/app_test.php/'
suites:
default:
contexts:
- 'Path/To/Your/Context/LocationContext'
type: symfony_bundle
bundle: Whatever2YourBundle
Or you can just use suites version like here: Installing behat3 with composer.json
I found out that I needed to add paths in my profile configuration, now my behat.yml looks like
machine:
suites:
machine:
paths:
- %paths.base%/features/machine.feature
contexts:
- MachineContext:
location:
suites:
location:
paths:
- %paths.base%/features/location.feature
contexts:
- LocationContext:
works for me by adding following command :
behat -c behat.yml --profile machine --suite=machine
behat -c behat.yml --profile machine --suite=location
I am trying to configure Behat3 to use SensionLabs PageObject Extension, but looks like it won't find it. I have the extension added to composer.json file and installed in vendor folder when I look into it.
Here is my behat.yml file
default:
suites:
default:
path:
features: features/site
contexts:
- SiteContext
system:
path:
features: features/system
contexts:
- SystemContext
extensions:
SensioLabs\Behat\PageOBjectExtension:
namespaces:
page: [Page]
MageTest\MagentoExtension\Extensions: ~
Behat\MinkExtension:
base_url: "http://somewebsite.local/"
selenium2:
wd_host: http://127.0.0.1:4444
browser: firefox
I think to have to have figured it out myself, I was using incorrect extension path it should have been
SensioLabs\Behat\PageObjectExtension\ServiceContainer\PageObjectExtension
I have a PHP project with Codeception on which several developers are working. Everyone have their own environment and different URL to their copy of the project. But in Codeception Functional/Acceptance yml config file we have to set up URL for acceptance and functional tests.
How could we have different URL to project and have main part of configs in repository?
Thank you in advance.
One way to solve this is to look at the $_SERVER['HOSTNAME'] value and select the appropriate url from that. I've currently got this in my tests/acceptance/_bootstrap.php
switch($_SERVER['HOSTNAME'])
{
case 'dev1':
$base_url = 'http://www.example.com.dev1';
break;
default:
$base_url = 'http://www.example.com';
break;
}
define("BASE_URL",$base_url);
You can then make use of this constant in a test
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure that the a user can log in');
$I->amOnUrl(BASE_URL . "/home");
I have same problem. I asked same question here. I used --environment option to get this working.
here is the example configuration:
class_name: FunctionalTester
modules:
enabled:
# add framework module here
- Yii1
- \Helper\Functional
- PhpBrowser
- Db
config:
Yii1:
appPath: '/Volumes/disk0s4/www/new-proj/trunk/test.php'
url: 'https://my.proj.local/test.php'
PhpBrowser:
url: 'https://my.proj.didin/'
Db:
dsn: 'mysql:host=127.0.0.1;dbname=test-proj-new'
user: 'root'
password: 'root'
env:
my_env:
modules:
enabled:
- Yii1
- \Helper\Functional
config:
Yii1:
appPath: 'path to index.php of my environment'
url: 'http://my.local/test.php'
production_env:
modules:
enabled:
- Yii1
- \Helper\Functional
config:
Yii1:
appPath: 'path to index.php of production environment'
url: 'http://my.local.com/test.php'
I know that config contains duplicated-lines and should be able to be simplified, I've tried to simplify by removing duplicate line at global modules, but seems doesn't work to me.
So I let the config as you see above and I have created Issue for it, but still wondering if someone get this overriding working.
I hope this helps to anyone.