{"id":15159610,"url":"https://github.com/facile-it/paraunit-testcase","last_synced_at":"2026-01-10T03:41:55.252Z","repository":{"id":35733273,"uuid":"40011932","full_name":"facile-it/paraunit-testcase","owner":"facile-it","description":"TestCase and client to test Symfony applications with Doctrine database isolation","archived":true,"fork":false,"pushed_at":"2017-09-22T10:33:08.000Z","size":70,"stargazers_count":6,"open_issues_count":4,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-26T17:13:07.394Z","etag":null,"topics":["database","test-symfony","testcase","transaction"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/facile-it.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG-0.x.md","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":"2015-07-31T15:31:18.000Z","updated_at":"2024-03-17T21:24:19.000Z","dependencies_parsed_at":"2022-08-18T01:05:36.756Z","dependency_job_id":null,"html_url":"https://github.com/facile-it/paraunit-testcase","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facile-it%2Fparaunit-testcase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facile-it%2Fparaunit-testcase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facile-it%2Fparaunit-testcase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facile-it%2Fparaunit-testcase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/facile-it","download_url":"https://codeload.github.com/facile-it/paraunit-testcase/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234724889,"owners_count":18877279,"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":["database","test-symfony","testcase","transaction"],"created_at":"2024-09-26T21:40:47.861Z","updated_at":"2025-09-30T10:30:33.157Z","avatar_url":"https://github.com/facile-it.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# paraunit-testcase\n\n**WARNING**: this package is now **abandoned**; we suggest [dama/doctrine-test-bundle](https://github.com/dmaicher/doctrine-test-bundle) as a replacement instead.\n\n[![Stable release][Last stable image]][Packagist link]\n[![Unstable release][Last unstable image]][Packagist link]\n\n[![Scrutinizer][Master scrutinizer image]][Master scrutinizer link]\n\nTestCase and HTTP client to test Symfony2/3 applications with Doctrine database isolation:\n\n * no more manual database cleanup after each test, it's already done!\n * no more garbage left over in your test database\n * mess all you want with your fixtures\n * (a bit) faster functional tests\n\n## Requirements\nThis package is meant to be used for functional testing inside Symfony2/3+Doctrine applications. It works only with \ntransactional databases, so Entity Manager only, sorry!\n\nIf you need to test controllers that requires authentication, it's best to set the security to HTTP-basic in your test \nenvironment, to speed up the test and avoid re-testing the login functionality of your app; if this isn't viable for you, \nsee **Advanced usage**.\n\nIt's suggested in combination with [facile-it/paraunit](https://github.com/facile-it/paraunit), for even more faster \ntesting!\n\n## Installation\nTo use this package, use composer:\n\n * from CLI: `composer require --dev facile-it/paraunit-testcase`\n * or, directly in your `composer.json`:\n\n``` \n{\n    \"require-dev\": {\n        \"facile-it/paraunit-testcase\": \"~0.4\"\n    }\n}\n```\n\n## Usage\nThis package provides a test case class, `ParaunitFunctionalTestCase`: to achieve **per-test-method transactional \nisolation**, extend you functional test classes from it.\n\nWith this, anything that your test writes on the DB:\n\n * is normally readable everywhere inside your test method\n * is \"forgotten\" at the end of the test method: the first-level transaction is always rolled back\n * is faster to write (it doesn't really reach the DB)\n * your app will behave normally: it can open and close more transactions, and it will fail as normal when flushing \n incorrect/incomplete data\n\n### Testing a controller\nThe TestCase provides some utility methods for testing controller's actions:\n\n * `getUnauthorizedClient()`: extended Symfony HTTP client, for controller testing (it can read inside the transaction,\n  even between multiple requests)\n * `getAuthorizedClient($user, $password)`: same as before, but with HTTP basic authentication\n * `getEM()`: Doctrine's Entity Manager (transactional)\n * `refreshEntity(\u0026$entity, $entityManagerName = null)`: shortcut for refreshing an entity, re-fetching all the data \n from the database; really useful if you need to run some assertion on an entity and you want to be sure to read the\n data as persisted/rollbacked on the database.\n\n### Testing a Console ContainerAwareCommand\nWe also provide an easy way to test in parallel easily console `ContainerAwareCommand`. To do it use the the \n`ParaunitFunctionalTestCase::runContainerAwareCommandTester()` method, like this:\n```\nclass YourCommandTest extends ParaunitFunctionalTestCase\n{\n    public function testYourCommand()\n    {\n        $output = $this-\u003erunContainerAwareCommandTester(\n            new YourCommand(), \n            [\n                'argument' =\u003e 'argumentValue',\n                '--option' =\u003e 0,\n            ]\n        );\n        \n        $this-\u003eassertContains('Execution completed', $output);\n    }\n}\n```\n\nIf you want to split the instantiation and the execution (i.e. if you need to interact with the container first), you \ncan use the `createContainerAwareCommandTester()` method to get a `ContainerAwareCommandTester` class like this:\n\n```\nclass YourCommandTest extends ParaunitFunctionalTestCase\n{\n    public function testYourCommand()\n    {\n        $commandTester = $this-\u003ecreateContainerAwareCommandTester(new YourCommand());\n        $container = $commandTester-\u003egetCommandContainer();\n        // do what you want to the container!\n        \n        $commandTester-\u003eexecute(\n            [\n                'argument' =\u003e 'argumentValue',\n                '--option' =\u003e 0,\n            ]\n        );\n        \n        $this-\u003eassertEquals(0, $commandTester-\u003egetStatusCode());\n        $this-\u003eassertContains('Execution completed', $commandTester-\u003egetDisplay());\n    }\n}\n```\nNote: the `ContainerAwareCommandTester` class which the method returns extends Symfony's `CommandTester` class, so you\ncan use it in the same way (see the assertions); the only difference is that it provides the same level of transactional\nisolation as our test case or client.\n\n##Advanced usage\nIt's possible to extend `ParaunitFunctionalTestCase` more before using it as your base test case:\n\n * extend and use the `prepareAuthorizedClient(...)` hook method to add additional authentication and preparation to the \n client, if needed\n * do NOT EVER FORGET to call the parent methods first if you override the `setUp()` and `tearDown()` methods\n\n[Last stable image]: https://poser.pugx.org/facile-it/paraunit-testcase/version.svg\n[Last unstable image]: https://poser.pugx.org/facile-it/paraunit-testcase/v/unstable.svg\n[Master scrutinizer image]: https://scrutinizer-ci.com/g/facile-it/paraunit/badges/quality-score.png?b=master\n\n[Packagist link]: https://packagist.org/packages/facile-it/paraunit-testcase\n[Master scrutinizer link]: https://scrutinizer-ci.com/g/facile-it/paraunit/?branch=master\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffacile-it%2Fparaunit-testcase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffacile-it%2Fparaunit-testcase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffacile-it%2Fparaunit-testcase/lists"}