{"id":41781032,"url":"https://github.com/imatic/testing","last_synced_at":"2026-01-25T04:02:20.327Z","repository":{"id":54189457,"uuid":"113308367","full_name":"imatic/testing","owner":"imatic","description":"Library to make testing of Symfony bundles easier","archived":false,"fork":false,"pushed_at":"2023-03-27T14:02:41.000Z","size":363,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-09-18T07:23:47.640Z","etag":null,"topics":["symfony","testing"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imatic.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-06T11:35:12.000Z","updated_at":"2022-11-10T11:46:56.000Z","dependencies_parsed_at":"2023-02-17T16:45:57.109Z","dependency_job_id":null,"html_url":"https://github.com/imatic/testing","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/imatic/testing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imatic%2Ftesting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imatic%2Ftesting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imatic%2Ftesting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imatic%2Ftesting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imatic","download_url":"https://codeload.github.com/imatic/testing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imatic%2Ftesting/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28742983,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T02:46:29.005Z","status":"ssl_error","status_checked_at":"2026-01-25T02:44:29.968Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["symfony","testing"],"created_at":"2026-01-25T04:02:19.626Z","updated_at":"2026-01-25T04:02:20.322Z","avatar_url":"https://github.com/imatic.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":".. image:: https://secure.travis-ci.org/imatic/testing.png?branch=master\n   :alt: Build Status\n   :target: http://travis-ci.org/imatic/testing\n|\n.. image:: https://img.shields.io/badge/License-MIT-yellow.svg\n   :alt: License: MIT\n   :target: LICENSE\n\nTesting\n=======\nThis library makes it easy to setup tests including testing project for reusable bundles. It will create all required files so that you can start writing your tests and visualise components of your bundle without necessity of including it into some application (as this library creates such application in testing namespace of your bundle).\n\nContent\n=======\n* `Initialize testing project`_\n* `PHPUnit`_\n* `Usage`_\n* `Checking your testing project in browser`_\n* `Writing tests working with database`_\n* `Testing project configuration`_\n\nInitialize testing project\n==========================\n\n* Add `phpunit.xml.dist \u003chttps://phpunit.de/manual/current/en/appendixes.configuration.html\u003e`_ to your repository to configure `phpunit \u003chttps://phpunit.de/\u003e`__\n* Set KERNEL_DIR server variable so that phpunit finds symfony kernel (example value nees to be modified based on bundle name)\n\n.. sourcecode:: xml\n\n   \u003c!-- phpunit.xml.dist --\u003e\n   \u003cphpunit\u003e\n       \u003cphp\u003e\n           \u003cserver name=\"KERNEL_DIR\" value=\"Imatic\\Bundle\\TestsTemplateBundle\\Tests\\Fixtures\\TestProject\\TestKernel\"/\u003e\n       \u003c/php\u003e\n   \u003c/phpunit\u003e\n\n* Add imatic-testing into your dev dependencies\n\n.. sourcecode:: bash\n\n   $ composer require --dev 'imatic/testing'\n\n* Create required files in your `bundle \u003cbundle_\u003e`_\n\n.. sourcecode:: bash\n\n    $ ./vendor/bin/testingbundle-init\n\n\n* Command above should create directory structure similar to\n\n.. sourcecode:: text\n\n    Tests\n        Fixtures\n            TestProject\n                config\n                    config.yml\n                    routing.yml\n                XYZBundle (same name as tested bundle)\n                    AppXYZBundle.php\n                web\n                    app.php\n                console\n                TestKernel.php\n                WebTestCase.php\n        Functional\n        Integration\n        Unit\n        bootstrap.php\n\n* Directory structure above is created based on template in `TestsTemplate \u003cResources/skeleton/TestsTemplate\u003e`_ directory\n\nPHPUnit\n=======\n\nAdditional constraints\n----------------------\nAll additinal constraints usable in `symfony functional tests \u003csymfony functional tests_\u003e`_ are included in our ``WebTestCase`` automatically. If you have your own ``WebTestCase`` implementation, you can use our trait `WebTestCaseExtension \u003cTest/WebTestCaseExtension.php\u003e`_ to include our additional constraints in your ``WebTestCase``.\n\nResponseHasCode\n^^^^^^^^^^^^^^^\nThis constraint can be used to assert status codes in `symfony functional tests \u003chttps://symfony.com/doc/current/testing.html#functional-tests\u003e`_. Usage:\n\n.. sourcecode:: php\n\n   \u003c?php\n\n   use Imatic\\Testing\\Test\\WebTestCase;\n\n   class ExampleTestCase extends WebTestCase\n   {\n       public function testHomepageReturnsOk()\n       {\n           $client = static::createClient();\n           $client-\u003erequest('GET', '/');\n\n           $this-\u003eassertResponseHasCode(200, $client-\u003egetResponse());\n       }\n   }\n\n* advantage in comparison with asserting 200 with ``$client-\u003egetResponse()-\u003egetStatusCode()`` is that the special assert gives you information about what went wrong instead of giving you just wrong code of the response (e.g. 500)\n\nUsage\n=====\nNow if you have all configured, you can start writing tests or check your testing project in browser. In order to check your testing project in browser.\n\nChecking your testing project in browser\n----------------------------------------\n\n* go to the testing project root and run web server\n\nUsing PHP's bult-in web server\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. sourcecode:: bash\n\n   $ cd Tests/Fixtures/TestProject/\n   $ ./console server:run --docroot=web\n\n* now open your browser at url reported by the last command (probably \"http://127.0.0.1:8000/app.php\")\n* you will see exception now probably because you didn't configure any routes for your project yet\n* you can find more details on the command in `symfony documentation \u003chttps://symfony.com/doc/current/setup/built_in_web_server.html\u003e`__\n\nUsing other web servers\n^^^^^^^^^^^^^^^^^^^^^^^\n\n* see `symfony documentation \u003chttps://symfony.com/doc/current/setup/web_server_configuration.html\u003e`__ on how to configure each\n\nUsing symfony console\n---------------------\n\n* as you may or may not notice when we talked about testing project directory structure, you have also available symfony console - so that you can run all commands that your bundle or bundles your testing project uses provide\n* see `symfony documentation \u003chttps://symfony.com/doc/current/components/console/usage.html\u003e`__ on how to work with console command (note that in our case, the executable running console is called ``console`` and is placed in root of the testing project\n\n\nWriting tests working with database\n===================================\n\n* if you use our ``WebTestCase`` as parent of your tests, then each test will run in transaction so all your modifications to db are lost (so you have db in state before the test run)\n* see commented test below on how it works\n\n.. sourcecode:: php\n\n    \u003c?php\n\n    namespace Imatic\\Bundle\\DataBundle\\Tests\\Integration\\Data\\Command;\n\n    use Doctrine\\ORM\\EntityManager;\n    use Doctrine\\ORM\\EntityRepository;\n    use Imatic\\Bundle\\DataBundle\\Data\\Command\\Command;\n    use Imatic\\Bundle\\DataBundle\\Data\\Command\\CommandExecutor;\n    use Imatic\\Bundle\\DataBundle\\Tests\\Fixtures\\TestProject\\ImaticDataBundle\\Entity\\User;\n    use Imatic\\Bundle\\DataBundle\\Tests\\Fixtures\\TestProject\\WebTestCase;\n\n    // this is our test class wich extends ``WebTestCase`` which ensures\n    // that each test runs in the same environment (has predictable db state)\n    class CommandExecutorTest extends WebTestCase\n    {\n        public function testGivenCommandShouldBeSuccessfullyExecuted()\n        {\n            /* @var $user User */\n            $user = $this-\u003egetUserRepository()-\u003efindOneByName('Adam');\n\n            // here we make sure that the user is not activated\n            // so that we can test activating functionality\n            $this-\u003eassertTrue($user-\u003eisActivated());\n\n            $command = new Command('user.deactivate', ['id' =\u003e $user-\u003egetId()]);\n            // here we execute command which activates the user\n            // and stores the information into database\n            $result = $this-\u003egetCommandExecutor()-\u003eexecute($command);\n            $this-\u003eassertTrue($result-\u003eisSuccessful());\n\n            // here we check that user was activated\n            $this-\u003eassertFalse($user-\u003eisActivated());\n\n            // after this test finishes, user is deactivated because the transaction\n            // is rollbacked\n        }\n\n        /**\n         * @return EntityRepository\n         */\n        public function getUserRepository()\n        {\n            return $this-\u003egetEntityManager()-\u003egetRepository('AppImaticDataBundle:User');\n        }\n\n        /**\n         * @return EntityManager\n         */\n        public function getEntityManager()\n        {\n            return $this-\u003econtainer-\u003eget('doctrine.orm.entity_manager');\n        }\n\n        /**\n         * @return CommandExecutor\n         */\n        private function getCommandExecutor()\n        {\n            return $this-\u003econtainer-\u003eget('imatic_data.command_executor');\n        }\n    }\n\n* note that because of doctrine connection wrapper we use - you can write `symfony funcional tests \u003chttps://symfony.com/doc/current/testing.html#functional-tests\u003e`__ and after each test, transaction will still be rollbacked (which is not possible without using the wrapper\n    * you can see this connection wrapper in our `config template \u003cTestsTemplate/Fixtures/TestProject/config/config.ym\u003e`__\n\n.. sourcecode:: yaml\n\n    doctrine:\n        dbal:\n            connections:\n                default:\n                    wrapper_class: \"Imatic\\\\Testing\\\\Doctrine\\\\DBAL\\\\PersistedConnection\"\n\n* if you want to load any fixtures, you need to require `DoctrineFixturesBundle \u003chttps://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html\u003e`_\n  and specify any fixture. Our ``WebTestCase`` load fixtures automatically when ``DoctrineFixturesBundle`` is enabled.\n\n* before running tests database and fixtures is reloaded, if you want to disable this behavior, change env variable ``TESTING_DATA_INIT`` in your test configuration\n\n.. sourcecode:: xml\n\n   \u003c!-- phpunit.xml.dist --\u003e\n   \u003cphpunit\u003e\n       \u003cphp\u003e\n           \u003cenv name=\"TESTING_DATA_INIT\" value=\"0\" /\u003e\n       \u003c/php\u003e\n   \u003c/phpunit\u003e\n\n\nTesting project configuration\n=============================\n\n* if you need to make changes to the configuration, just edit generated config file which you can find in ``config/config.yml`` (relative to the testing project roor)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimatic%2Ftesting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimatic%2Ftesting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimatic%2Ftesting/lists"}