{"id":19003475,"url":"https://github.com/acseo/behatgeneratorbundle","last_synced_at":"2026-04-22T21:35:56.841Z","repository":{"id":56940200,"uuid":"61631306","full_name":"acseo/BehatGeneratorBundle","owner":"acseo","description":"This bundle allows you to generate automatic tests with Behat","archived":false,"fork":false,"pushed_at":"2020-08-07T14:16:25.000Z","size":37,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-02-21T13:44:27.645Z","etag":null,"topics":["behat","bundle","php","symfony","symfony-bundle"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/acseo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-21T12:14:35.000Z","updated_at":"2022-10-28T05:03:28.000Z","dependencies_parsed_at":"2022-08-21T01:40:23.527Z","dependency_job_id":null,"html_url":"https://github.com/acseo/BehatGeneratorBundle","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/acseo/BehatGeneratorBundle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acseo%2FBehatGeneratorBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acseo%2FBehatGeneratorBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acseo%2FBehatGeneratorBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acseo%2FBehatGeneratorBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/acseo","download_url":"https://codeload.github.com/acseo/BehatGeneratorBundle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acseo%2FBehatGeneratorBundle/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261031327,"owners_count":23100014,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["behat","bundle","php","symfony","symfony-bundle"],"created_at":"2024-11-08T18:19:14.139Z","updated_at":"2026-04-22T21:35:56.767Z","avatar_url":"https://github.com/acseo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ACSEO Behat Generator Bundle\n\n## Introduction\n\nThis Bundle allows you to generate *.feature* file for each route of your project.\n\n\n## Installation\n\n### Behat\n\nYou don't need behat to generate the tests, but to run them.\nTo add behat in your project, you can follow the procedure here : http://docs.behat.org/en/v3.0/cookbooks/1.symfony2_integration.html\n\n```\n$ composer require --dev behat/behat\n$ composer require --dev behat/mink-extension\n$ composer require --dev behat/mink-zombie-driver\n```\n\nThen your ```behat.yml``` file should look like :\n\n```\n# behat.yml\ndefault:\n    extensions:\n        Behat\\MinkExtension:\n            base_url: \"http://localhost:8000/\"\n            sessions:\n                default:\n                    zombie: ~\n                javascript:\n                    zombie: ~\n    suites:\n        default:\n            contexts:\n                - FeatureContext: { container: \"@service_container\" }\n```\n\nYou will need to define a FeatureContext class :\n\n```\n\u003c?php\n// features/bootstrap/FeatureContext.php\n\nuse Behat\\MinkExtension\\Context\\MinkContext;\n\n/**\n * Defines application features from the specific context.\n */\nclass FeatureContext extends MinkContext\n{\n    /**\n     * Initializes context.\n     *\n     * Every scenario gets its own context instance.\n     * You can also pass arbitrary arguments to the\n     * context constructor through behat.yml.\n     */\n    public function __construct($container)\n    {\n         $this-\u003econtainer = $container;\n    }\n\n    /**\n     * Some forms do not have a Submit button just pass the ID\n     *\n     * @When I Submit the form with id :arg1\n     */\n    public function iSubmitTheFormWithId($arg1)\n    {\n        // https://jsfiddle.net/v3rv47hL/\n        $jsTemplate = \u003c\u003c\u003cEOT\n        \"var forms = document.getElementsByTagName('form');var search = '%s';var x = null;if (forms.length == 1) {x = forms[0];} else { for (var i = 0; i \u003c forms.length; i++) { if (forms[i].getAttribute('class') == search || forms[i].getAttribute('id') == search || forms[i].getAttribute('name') == search) { x = forms[i]; break; } } } if (x != null) x.submit();\"\nEOT;\n        $js = sprintf($jsTemplate, $arg1);\n\n        $node = $this-\u003egetSession()-\u003egetPage()-\u003efind('named', array('id', $arg1));\n        if($node) {\n            $this-\u003egetSession()-\u003eexecuteScript($js);\n        } else {\n            throw new Exception('No form with id : '.$arg1.' found on this page');\n        }\n    }\n\n}\n```\n\n### Zombie\n\nWe will use Zombie.js as browser emulator. Why ? Because it allows us to check the status code after a JS test.\n\nThe installation documentation can be found here : http://mink.behat.org/en/latest/drivers/zombie.html :\n\n* Install node.js by following instructions from the official site: http://nodejs.org/.\n* Install npm (node package manager) by following the instructions from http://npmjs.org/.\n* Install zombie.js with npm:\n\n```\n$ npm install -g zombie\n```\n\n### BehatGeneratorBundle\n\nInclude the bundle in your project :\n\n```\n$ composer require acseo/behat-generator-bundle\n```\n\nEnable the bundle in AppKernel.php\n\n```\n// app/AppKernel.php\n// ...\npublic function registerBundles()\n{\n    $bundles = array(\n        // ...\n        new ACSEO\\Bundle\\BehatGeneratorBundle\\ACSEOBehatGeneratorBundle(),\n        // ...\n    );\n```\n\nThat's it ! now the command ```php app/console acseo:automatic-test``` is ready.\n\n## Usage\n\nYou can use the command ```app/console acseo:automatic-test``` in order to generate feature files.\n\nIf you do so, there is a lot of chances that the command will detect protected routes that *require to login*.\nIt will prompt you multiple information that will be used, such as the login url, username and password, etc.\n\nIf you want to avoid prompt, you can call the command with the usefull information :\n\n```\n$ app/console acseo:automatic-test --access \"main uri /login\" --access \"main loginField username \" --access \"main passwordField password\" --access \"main submitField Login\" --access \"main login test@test.com\" --access \"main password test\"\n\n```\n\n## Customization.\n\nTBD.\n\n\n## How does it works ?\n\n* Step One : Get all the routes and filter them, in order to only keep routes that accept GET and doesn't have any parameters\n* Step Two : Generate a simple test : get the URL and check if a 200 code is returned.\n* Step Thee : Use a custom event to generate the view, check if it contains a FormView parameter in it. If so, generate a simple test : submit the form that may be in the view and check if a 200 code is returned.\n\n## API auto generated tests\n\nWhen using an api, it's often not needed to make custom tests. Knowing that everything works in regular conditions is enough. In that case, you can use the Acseo auto generated tests for api. It will create a behat feature test in folder features/automatic/api/ for each api resource in your project. That is to say, a test to create a resource, get it, get all, edit one, delete one (some steps could be missing if you did not opened the action in your api). All of these tests will be run in a temporary SQL Lite database, so your real database won't be compromised. Obviously, if a resource does not have a route for the creation of a new item, no test can be written (console will warn you then), and it's up to you to create tests on your own.\n\nFor now, it is only available for api using NelmioApiDoc, that we use to get all elements needed to write tests (route, methods, parameters to send).\n\nYou also need these dependencies, add them in your ``composer.json`` if it's not already the case:\n\n```\n    - \"behat/mink-extension\": \"~2.0\"\n    - \"behat/mink-browserkit-driver\": \"~1.1\"\n    - \"behatch/contexts\": \"dev-master\"\n    - \"fzaninotto/faker\": \"~1.6.0\"\n```\n\nAnd add in ``behat.yml`` our specific features:\n\n```\ndefault:\n  ...\n  suites:\n    default:\n      contexts:\n        - ACSEO\\Bundle\\BehatGeneratorBundle\\Context\\ApiContext: { container: \"@service_container\" }\n        - ACSEO\\Bundle\\BehatGeneratorBundle\\Context\\ExtendedMinkContext\n        - ACSEO\\Bundle\\BehatGeneratorBundle\\Context\\ParallelContext: { container: \"@service_container\"\n```\n\nTo generate these tests, just run this command in your terminal:\napp/console acseo:automatic-api-test\n\nYou will see all generated features appear.\n\nThen, if everything all right:\n\n```\n$ bin/behat\n```\n\nIf you need authentication, please add to your ``config_test.yml``\n\n```\n# app/config/config_test.yml\nparameters:\n    ACSEOBehatGeneratorBundle:\n        entity_manager: doctrine.orm.entity_manager # Put your own entity manager\n        authentication:\n            user:\n                class: \\AcmeBundle\\Entity\\User      # Put your own class for user\n                attributes:                         # Enter value to fill out on user creation\n                    username: user\n                    email: user@test.com\n                    plainPassword: test\n                    enabled: true\n            route:                                  # Define the route\n                url: /login_check\n                parameters:                         # And parameters to send\n                    _username: user.username\n                    _password: user.plainPassword\n\n```\n\n## License\n\nThis bundle is under the MIT license. See the complete license in the bundle:\n\n```\nResources/meta/LICENSE\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facseo%2Fbehatgeneratorbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facseo%2Fbehatgeneratorbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facseo%2Fbehatgeneratorbundle/lists"}