{"id":21616065,"url":"https://github.com/ecomdev/phpspec-magento-di-adapter","last_synced_at":"2025-07-13T08:06:02.402Z","repository":{"id":56974730,"uuid":"59466993","full_name":"EcomDev/phpspec-magento-di-adapter","owner":"EcomDev","description":"This small PHPSpec extension allows you to test Magento 2.0 modules much more easier by utilizing generators of Magento\\Framework\\ObjectManager.","archived":false,"fork":false,"pushed_at":"2016-09-15T10:19:22.000Z","size":54,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T05:03:52.990Z","etag":null,"topics":["magento2","phpspec","phpspec-extension"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"osl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EcomDev.png","metadata":{"files":{"readme":"README.md","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":"2016-05-23T08:49:13.000Z","updated_at":"2019-05-27T08:26:51.000Z","dependencies_parsed_at":"2022-08-21T07:40:31.313Z","dependency_job_id":null,"html_url":"https://github.com/EcomDev/phpspec-magento-di-adapter","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EcomDev%2Fphpspec-magento-di-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EcomDev%2Fphpspec-magento-di-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EcomDev%2Fphpspec-magento-di-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EcomDev%2Fphpspec-magento-di-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EcomDev","download_url":"https://codeload.github.com/EcomDev/phpspec-magento-di-adapter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248358821,"owners_count":21090440,"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":["magento2","phpspec","phpspec-extension"],"created_at":"2024-11-24T22:13:38.286Z","updated_at":"2025-04-11T07:30:29.162Z","avatar_url":"https://github.com/EcomDev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHPSpec Magento 2.0 DI Adapter [![Build Status](https://travis-ci.org/EcomDev/phpspec-magento-di-adapter.svg?branch=develop)](https://travis-ci.org/EcomDev/phpspec-magento-di-adapter?branch=develop)  [![Coverage Status](https://coveralls.io/repos/github/EcomDev/phpspec-magento-di-adapter/badge.svg?branch=develop)](https://coveralls.io/github/EcomDev/phpspec-magento-di-adapter?branch=develop)\n\nThis small PHPSpec extension allows you to test Magento 2.0 modules much more easier by utilizing generators of `Magento\\Framework\\ObjectManager`.\n\n## Why?\nReasons why not to use `ObjectManager` in PHPSpec examples:\n\n1. It is heavy and requires stubbing full file system in order to run a simple spec example.\n2. Depending on ObjectManager is a bad idea, as you don't want to test some-else DI overrides.\n3. Simple modules that do not require database do not need fully functional object manager\n4. Adapting your business logic to another framework will require from you only to materialize generated classes, instead of depending on the whole ObjectManager library.\n\n## Supported Generators\n\n* Factory\n* Repository\n* Converter\n* Persistor\n* Mapper\n* SearchResults\n\n## Installation\n\n1. Install via composer\n\n    ```bash\n    composer require --dev ecomdev/phpspec-magento-di-adapter\n    ```\n\n2. Add to your phpspec.yml\n\n    ```yaml\n    extensions:\n       - EcomDev\\PHPSpec\\MagentoDiAdapter\\Extension\n    ```\n\n## Usage\n\nMake sure that when you write examples to specify fully qualified class name for auto-generated class. \n\n```php\n\u003c?php\n\nnamespace spec\\Acme\\CustomMagentoModule\\Model;\n\nuse Magento\\Catalog\\Model\\Product;\nuse PhpSpec\\ObjectBehavior;\nuse Prophecy\\Argument;\n\nclass ProductManagerSpec extends ObjectBehavior\n{\n    private $productFactory; \n    \n    function let(ProductFactory $factory) {\n        $this-\u003eproductFactory = $factory;    \n        $this-\u003ebeConstructedWith($factory);\n    }\n    \n    function it_creates_items_via_product_factory(Product $product)\n    {\n        $this-\u003eproductFactory-\u003ecreate()-\u003ewillReturn($product)-\u003eshouldBeCalled();\n        $this-\u003esomeCreationLogic();\n    }\n}\n```\n\nThis approach will not get you a desired result, as PHP by default looks for undefined classes within the same namespace.\nSo instead of `Magento\\Catalog\\Model\\ProductFactory` it will generate a class `spec\\Acme\\CustomMagentoModule\\Model\\ProductFactory`, that is definitely not a desired behavior.\n\nIn order to fix that make sure to specify fully qualified name in method signature or via `use` operator in the file header.\n\n```php\n\u003c?php\n\nnamespace spec\\Acme\\CustomMagentoModule\\Model;\n\nuse Magento\\Catalog\\Model\\Product;\nuse Magento\\Catalog\\Model\\ProductFactory; // This class will be automatically generated\nuse PhpSpec\\ObjectBehavior;\nuse Prophecy\\Argument;\n\nclass ProductManagerSpec extends ObjectBehavior\n{\n    private $productFactory; \n    \n    function let(ProductFactory $factory) {\n        $this-\u003eproductFactory = $factory;    \n        $this-\u003ebeConstructedWith($factory);\n    }\n    \n    function it_creates_items_via_product_factory(Product $product)\n    {\n        $this-\u003eproductFactory-\u003ecreate()-\u003ewillReturn($product)-\u003eshouldBeCalled();\n        $this-\u003esomeCreationLogic();\n    }\n}\n```\n\n## Contribution\nMake a pull request based on develop branch\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomdev%2Fphpspec-magento-di-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fecomdev%2Fphpspec-magento-di-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomdev%2Fphpspec-magento-di-adapter/lists"}