Codeception Gherkin, defining the step implementation path - php

I’m new to php and codeception and I wanted to use Gherkin with Codeception, and I’ve already setup the bare minimum to make feature files run in Codeception. I now find myself trying to make a scalable structure and make use of the PageObject framework. I created a Steps Folder and I wanted my step implementations kept in that folder. By default running codecept run some.feature loads the class defined in the acceptance.suite.yml file.
Motivation: I want to be able keep my step implementations into it’s own separate folder
Given I have an acceptance.suite.yml file configuration of:
gherkin:
contexts:
default:
- AcceptanceTester
modules:
enabled:
- WebDriver:
url: https://www.google.com/
browser: chrome
- \Helper\Acceptance
And I have a codeception.yml file configuration of:
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed
And I have my Steps folder under _support:
How do I change the configuration to allow my step implementation to be
called from the Steps folder?

In the gherkin: section of the suite configuration, you need to list your steps classes organised under default:, role: and/or tag: sections. There are example configurations in the official documentation: Gherkin options.
Below is an example from a recent project (using Codeception 2.5.6):
file structure
/app/common
├── codeception.yml
├── tests
│   ├── acceptance.suite.yml
│ ├── _bootstrap.php
│ ├── _data
│ │ └── user.php
│ ├── _support
│ │ ├── AcceptanceTester.php
│ │ ├── Step
│ │ │ └── Acceptance
│ │ │ └── CuratorSteps.php
The layout above for the step class is the default one when generating step object using codecept generate:stepobject command like so:
$ /app/vendor/bin/codecept -c /app/common generate:stepobject acceptance CuratorSteps
acceptance.suite.yml:
# acceptance.suite.yml
namespace: common\tests
suite_namespace: common\tests\acceptance
bootstrap: false
actor: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: http://example.com/
gherkin:
contexts:
default:
- common\tests\AcceptanceTester
role:
curator:
- common\tests\Step\Acceptance\CuratorSteps
The documentation doesn't mention it, but I notice I have to list the full namespace of the step classes, otherwise I'll get "Step definition for ... not found in contexts" errors when running the tests and the gherkin:steps codecept command won't return the step definitions.
output
$ /app/vendor/bin/codecept -vvv -c /app/common gherkin:steps acceptance
Steps from role:curator context:
+--------------------------------------------------------------------+------------------------------------------------------------------------------------------+
| Step | Implementation |
+--------------------------------------------------------------------+------------------------------------------------------------------------------------------+
| I sign in as an admin | common\tests\Step\Acceptance\CuratorSteps::iSignInAsAnAdmin |
| I should see a :arg1 button | common\tests\Step\Acceptance\CuratorSteps::iShouldSeeAButton |
+--------------------------------------------------------------------+------------------------------------------------------------------------------------------+
Steps from default context:
+-------------------------------------+---------------------------------------------------------+
| Step | Implementation |
+-------------------------------------+---------------------------------------------------------+
| I take a screenshot with name :arg1 | common\tests\AcceptanceTester::itakeAScreenshotWithName |
+-------------------------------------+---------------------------------------------------------+

Related

How to override errors templates for Symfony

I want to override the error templates in Symfony 3. I've started by creating a TwigBundle folder withe the personalised twig.
app/
└─ Resources/
└─ TwigBundle/
└─ Exception/
├─ error404.html.twig
├─ error403.html.twig
├─ error.html.twig
Then I checked the routing_dev file which contains this lines :
_errors:
resource: "#TwigBundle/Resources/config/routing/errors.xml"
prefix: /_error
Symfony still displays the default error templates. I want to know if I should verify something else.
PS : I have already checked this documentation : How to Customize Error Pages
EDIT :
The overriden files should reside in a subfolder named views. The correct file tree would look like this:
app/
└─ Resources/
└─ TwigBundle/
└─ views/
└─ Exception/
├─ error404.html.twig
├─ error403.html.twig
├─ error.html.twig
Clear your cache afterwards.
Be aware that those overriden error templates do NOT show up in the dev environment.
If you want to test the templates in your dev environment you must ensure you have imported the following in routing_dev.yml:
_errors:
resource: "#TwigBundle/Resources/config/routing/errors.xml"
prefix: /_error
Now you can access /_error/<error-code>.html (i.e. localhost:8000/_error/404.html with the integrated webserver)

php-fpm : disabling a php extension for a specific pool

I have configured a new FPM pool (config file www.conf in pool.d), now let's say I want to disable mysql support for that specific pool ? Or maybe there is a way not to load that extension for that pool ?
I'm using debian 9 and here is how the file structure looks like this:
/etc/php/7.0/fpm$ tree
.
├── conf.d
│ ├── 10-mysqlnd.ini -> /etc/php/7.0/mods-available/mysqlnd.ini
│ ├── 10-opcache.ini -> /etc/php/7.0/mods-available/opcache.ini
│ ├── 10-pdo.ini -> /etc/php/7.0/mods-available/pdo.ini
│ ├── 20-calendar.ini -> /etc/php/7.0/mods-available/calendar.ini
│ ├── 20-ctype.ini -> /etc/php/7.0/mods-available/ctype.ini.ini
(...)
├── php-fpm.conf
├── php.ini
└── pool.d
├── forgewww.conf
└── www.conf
extension=thing.so can be found in files conf.d/<extension>.ini. Problem is all those extensions once configured seem common to all pools...
I've also tried to disable mysql extensions globally with phpdismod then append a line in www.conf with:
php_admin_value[extension] = mysqli.so
Which doesn't seems to work (the above doesn't enable mysqli for that pool)
You can't load different extension per-pool, the extensions are defined in an .ini file, loaded by master process. php-fpm master process forks into children, meaning that they share what's been loaded by the master process. You can't have a child load a different set of extensions after forking, or unload them. It probably is possible to develop a solution, but there's really no need for that seeing that you can solve your problem via different approach.
In order to achieve what you're after, simply set up entirely different php-fpm process on a different port / unix socket and load extensions you require, set up your pools and you're done. It's actually a lot less work than it sounds, it probably won't take you more than a few minutes.

How to call Controller from another folder via url Symfony 2?

I have this folder structure (symfony 2 application):
src
|-- Application
| |-- UserBundle
| | |-- Admin
| | |-- Api
| | |-- SomeController.php
| | |-- Controller
| | |-- DefaultController.php
| | |-- DependencyInjection
| | |-- Entity
| | |-- Resources
| | |-- Tests
I want to call some controller from Api folder. How i can do this?
UPD.
I use symfony routing to provide the controller:
application_homepage:
path: /hello/{name}
defaults: { _controller: ApplicationUserBundle:Default:index }
application_some:
path: /api/{slug}
defaults: { _controller: ApplicationUserBundle:../Api/Some:index }
I want to load controller from Api folder
If the namespace of your controller is : Application\UserBundle\Api,
that the className is SomeController and the action is indexAction
You can use this syntax in your routing file :
application_some:
path: /api/{slug}
defaults: { _controller: Application\UserBundle\Api\SomeController::indexAction }
This solution will work too:
application_some:
resource: "#ApplicationUserBundle/Api"
type: annotation
or:
application_some:
resource: "#ApplicationUserBundle/Api/SomeController.php"
type: annotation
see http://symfony.com/doc/current/book/routing.html#including-external-routing-resources
If both controller sit within the same namespace, you could simply do
$controller = new ControllerInApiFolder();
$conotroller->someFunction();
if they do not, then you need to include the controller via use-statement.
use Namespace\My\Controller\Sits\In\ControllerInApiFolder;
If you are trying to access the controller not from another controller, but from a template, an url or a testcase, you should refer to the symfony2 documentation.
Symfony2 Doc
From the edited question above I take it you want to call the controller via the url.
In your browser you can simply type in
path/to/my/web/api/something
or
path/to/my/web/app_dev.php/api/something
where "path/to/my/web" referes to the path of the web folder within your project
EDIT: I think now I am getting the problem...
Symfony2 routing always defaults to the /Controller folder to look for the controller (which is quite nice).
I am not quite sure you should add another folder to this. Instead, the documentation suggests having multiple folders inside the /Controller folder.
If you take a look at the folder structure displayed here: Symfony2 Controller, you will notice that there is an API folder within the /Controller folder.
<your-project>/
├─ ...
└─ src/
└─ AppBundle/
├─ ...
└─ Controller/
├─ DefaultController.php
├─ ...
├─ Api/
│ ├─ ...
│ └─ ...
└─ Backend/
├─ ...
└─ ...

Symfony 2 FOSUserBundle: Override form without defining service

I' m trying to set up FOSUserBundle for my new application, so I want to override the default FOSUser form. As stated in the FOSUser documentation, I have to define my new form as a service before set up the app/config.yml appropriately. My question is why can't I just set up config.yml like this:
fos_user:
db_driver: orm
firewall_name: admin_area
user_class: abc\abcBundle\Entity\User
registration:
form:
type: abc\abcBundle\Form\Type\UserType
In my last application, I used FOSUserBundle along with PUGXMUltiUserBundle and then my (perfectly working) configuration for PUGXM was:
users:
agents:
entity:
class: abc\NikBundle\Entity\agents
registration:
form:
type: abc\NikBundle\Form\Type\UserType
name: agent_user_registration_form
template: abcNikBundle:ManageUsers:newUser.html.twig
so I supposed this can also be done with FOSUserBundle. Is it impossible and if yes why?
FOSUserBundle allows you to override it's controllers as described in the doc below
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_controllers.md
This doc actually shows you how to override registration controller and from there it's simply injecting your custom form for validation as in any normal controller.
You can also override the templates by finding the original FOSUserBundle templates under "{ROOT_DIR}/vendor/friendsofsymfony/user-bundle/Resources/views" and copying them into "{ROOT_DIR}/app/Resources/FOSUserBundle/views".
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_templates.md
It should look like this
Resources
└── FOSUserBundle
└── views
├── ChangePassword
│ ├── changePassword.html.twig
│ └── changePassword_content.html.twig
├── Registration
│ ├── confirmed.html.twig
│ ├── register.html.twig
│ └── register_fail.html.twig
├── Resetting
│ ├── checkEmail.html.twig
│ ├── email.txt.twig
│ ├── passwordAlreadyRequested.html.twig
│ ├── request.html.twig
│ ├── request_content.html.twig
│ ├── reset.html.twig
│ └── reset_content.html.twig
├── Security
│ └── login.html.twig
└── layout.html.twig

app.yaml apparently not redirecting correctly

I've been trying to set up a basic Wordpress site with Google App Engine's new PHP SDK, following these instructions.
From what I understand, app.yaml is where the process kicks off and should work similar to .htaccess (re routing).
Google instruct you to drop your wordpress files into a wordpress folder, so your directory structure looks like this:
.
├── app.yaml
├── cron.yaml
├── php.ini
└── wordpress
├── index.php
├── license.txt
├── readme.html
└── (etc)
So their template app.yaml should work, including the following lines:
- url: /wp-cron.php
script: wordpress/wp-cron.php
login: admin
- url: /xmlrpc.php
script: wordpress/xmlrpc.php
- url: /(.+)?/?
script: wordpress/index.php
But localhost:8080 gives me my app folder's directory structure, instead of the anticipated wordpress/index.php. I tried this as well:
- url: /.*
script: wordpress/index.php
Any ideas?
Note: I verified that wordpress/index.php exists, by the way.
GAE's dev_appserver will never list the directory structure. Sounds like you might be hitting some other web server running on your localhost?

Categories