{"id":18773112,"url":"https://github.com/webfactory/doctrine-orm-test-infrastructure","last_synced_at":"2025-07-06T16:05:49.390Z","repository":{"id":20427212,"uuid":"23703777","full_name":"webfactory/doctrine-orm-test-infrastructure","owner":"webfactory","description":"Provides utils to create a test infrastructure for Doctrine ORM entities.","archived":false,"fork":false,"pushed_at":"2024-09-05T12:51:37.000Z","size":315,"stargazers_count":20,"open_issues_count":3,"forks_count":5,"subscribers_count":10,"default_branch":"2.x","last_synced_at":"2025-06-22T21:03:21.665Z","etag":null,"topics":["database","doctrine","doctrine-orm","php","phpunit","testing"],"latest_commit_sha":null,"homepage":"","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/webfactory.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-05T13:24:17.000Z","updated_at":"2024-09-05T12:49:22.000Z","dependencies_parsed_at":"2024-02-27T10:50:45.839Z","dependency_job_id":"204aa685-7792-4e38-af99-8df5749d73f9","html_url":"https://github.com/webfactory/doctrine-orm-test-infrastructure","commit_stats":{"total_commits":258,"total_committers":7,"mean_commits":"36.857142857142854","dds":0.1472868217054264,"last_synced_commit":"b5fb917f015a7547dc5e271f339fed2ba4b1c912"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/webfactory/doctrine-orm-test-infrastructure","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webfactory%2Fdoctrine-orm-test-infrastructure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webfactory%2Fdoctrine-orm-test-infrastructure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webfactory%2Fdoctrine-orm-test-infrastructure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webfactory%2Fdoctrine-orm-test-infrastructure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webfactory","download_url":"https://codeload.github.com/webfactory/doctrine-orm-test-infrastructure/tar.gz/refs/heads/2.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webfactory%2Fdoctrine-orm-test-infrastructure/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263932017,"owners_count":23531707,"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","doctrine","doctrine-orm","php","phpunit","testing"],"created_at":"2024-11-07T19:32:48.251Z","updated_at":"2025-07-06T16:05:49.369Z","avatar_url":"https://github.com/webfactory.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"doctrine-orm-test-infrastructure\n================================\n\n![Tests](https://github.com/webfactory/doctrine-orm-test-infrastructure/workflows/Tests/badge.svg)\n\nThis library provides some infrastructure for tests of Doctrine ORM entities, featuring:\n\n- configuration of a SQLite in memory database, compromising well between speed and a database environment being both\n  realistic and isolated\n- a mechanism for importing fixtures into your database that circumvents Doctrine's caching. This results in a more\n  realistic test environment when loading entities from a repository.\n\n[We](https://www.webfactory.de/) use it to test Doctrine repositories and entities in Symfony applications. It's a\nlightweight alternative to the\nheavyweight [functional tests suggested in the Symfony documentation](http://symfony.com/doc/current/cookbook/testing/doctrine.html)\n(we don't suggest you should skip those - we just want to open another path).\n\nIn non-application bundles, where functional tests are not possible,\nit is our only way to test repositories and entities.\n\nInstallation\n------------\n\nInstall via composer (see http://getcomposer.org/):\n\n    composer require --dev webfactory/doctrine-orm-test-infrastructure\n\nUsage\n-----\n\n```php\n\u003c?php\n\nuse Doctrine\\ORM\\EntityManagerInterface;\nuse Entity\\MyEntity;\nuse Entity\\MyEntityRepository;\nuse PHPUnit\\Framework\\TestCase;\nuse Webfactory\\Doctrine\\ORMTestInfrastructure\\ORMInfrastructure;\n\nclass MyEntityRepositoryTest extends TestCase\n{\n    private ORMInfrastructure $infrastructure;\n    private MyEntityRepository $repository;\n\n    protected function setUp(): void\n    {\n        /*\n           This will create an in-memory SQLite database with the necessary schema\n           for the MyEntity entity class and and everything reachable from it through\n           associations.\n        */\n        $this-\u003einfrastructure = ORMInfrastructure::createWithDependenciesFor(MyEntity::class);\n        $this-\u003erepository = $this-\u003einfrastructure-\u003egetRepository(MyEntity::class);\n    }\n\n    /**\n     * Example test: Asserts imported fixtures are retrieved with findAll().\n     */\n    public function testFindAllRetrievesFixtures(): void\n    {\n        $myEntityFixture = new MyEntity();\n\n        $this-\u003einfrastructure-\u003eimport($myEntityFixture);\n        $entitiesLoadedFromDatabase = $this-\u003erepository-\u003efindAll();\n\n        /* \n            import() will use a dedicated entity manager, so imported entities do not\n            end up in the identity map. But this also means loading entities from the\n            database will create _different object instances_.\n\n            So, this does not hold:\n        */\n        // self::assertContains($myEntityFixture, $entitiesLoadedFromDatabase);\n\n        // But you can do things like this (you probably want to extract that in a convenient assertion method):\n        self::assertCount(1, $entitiesLoadedFromDatabase);\n        $entityLoadedFromDatabase = $entitiesLoadedFromDatabase[0];\n        self::assertSame($myEntityFixture-\u003egetId(), $entityLoadedFromDatabase-\u003egetId());\n    }\n\n    /**\n     * Example test for retrieving Doctrine's entity manager.\n     */\n    public function testSomeFancyThingWithEntityManager(): void\n    {\n        $entityManager = $this-\u003einfrastructure-\u003egetEntityManager();\n        // ...\n    }\n}\n```\n\nMigrating to attribute-based mapping configuration (with version 1.x)\n---------------------------------------------------------------------\n\nIn versions 1.x of this library, the `ORMInfrastructure::createWithDependenciesFor()` and `ORMInfrastructure::createOnlyFor()` methods\nby default assume that the Doctrine ORM mapping is provided through annotations. Annotations-based configuration is no supported anymore in ORM 3.0.\n\nTo allow for a seamless transition towards attribute-based or other types of mapping, a mapping driver can be passed\nwhen creating instances of the `ORMInfrastructure`.\n\nIf you wish to switch to attribute-based mappings, pass a `new \\Doctrine\\ORM\\Mapping\\Driver\\AttributeDriver($paths)`,\nwhere `$paths` is an array of directory paths where your entity classes are stored.\n\nFor hybrid (annotations and attributes) mapping configurations, you can use `\\Doctrine\\Persistence\\Mapping\\Driver\\MappingDriverChain`.\nMultiple mapping drivers can be registered on the driver chain by providing namespace prefixes. For every namespace prefix,\nonly one mapping driver can be used.\n\nStarting in version 2.0.0, attributes-based mapping will be the default.\n\nTesting the library itself\n--------------------------\n\nAfter installing the dependencies managed via composer, just run\n\n    vendor/bin/phpunit\n\nfrom the library's root folder. This uses the shipped phpunit.xml.dist - feel free to create your own phpunit.xml if you\nneed local changes.\n\nHappy testing!\n\nKnown Issues\n------------\n\nPlease note that apart from any [open issues in this library](https://github.com/webfactory/doctrine-orm-test-infrastructure/issues), you\nmay stumble upon any Doctrine issues. Especially take care of\nit's [known sqlite issues](http://doctrine-dbal.readthedocs.org/en/latest/reference/known-vendor-issues.html#sqlite).\n\nCredits, Copyright and License\n------------------------------\n\nThis package was first written by webfactory GmbH (Bonn, Germany) and received [contributions\nfrom other people](https://github.com/webfactory/doctrine-orm-test-infrastructure/graphs/contributors) since then.\n\nwebfactory is a software development agency with a focus on PHP (mostly [Symfony](http://github.com/symfony/symfony)).\nIf you're a developer looking for new challenges, we'd like to hear from you!\n\n- \u003chttps://www.webfactory.de\u003e\n\nCopyright 2012 – 2024 webfactory GmbH, Bonn. Code released under [the MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebfactory%2Fdoctrine-orm-test-infrastructure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebfactory%2Fdoctrine-orm-test-infrastructure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebfactory%2Fdoctrine-orm-test-infrastructure/lists"}