{"id":20827716,"url":"https://github.com/peridot-php/peridot-prophecy-plugin","last_synced_at":"2025-07-09T17:35:06.728Z","repository":{"id":22850311,"uuid":"26197706","full_name":"peridot-php/peridot-prophecy-plugin","owner":"peridot-php","description":"Add prophecy to your peridot tests and auto inject mocks","archived":false,"fork":false,"pushed_at":"2017-10-30T16:24:51.000Z","size":160,"stargazers_count":4,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T09:20:41.240Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://peridot-php.github.io/","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/peridot-php.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":"2014-11-05T01:46:34.000Z","updated_at":"2016-07-31T00:07:23.000Z","dependencies_parsed_at":"2022-08-23T21:00:27.067Z","dependency_job_id":null,"html_url":"https://github.com/peridot-php/peridot-prophecy-plugin","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peridot-php%2Fperidot-prophecy-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peridot-php%2Fperidot-prophecy-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peridot-php%2Fperidot-prophecy-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peridot-php%2Fperidot-prophecy-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peridot-php","download_url":"https://codeload.github.com/peridot-php/peridot-prophecy-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252714868,"owners_count":21792763,"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":[],"created_at":"2024-11-17T23:12:50.861Z","updated_at":"2025-05-07T21:05:22.831Z","avatar_url":"https://github.com/peridot-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Peridot Prophecy Plugin\n=======================\n\n[![Build Status](https://travis-ci.org/peridot-php/peridot-prophecy-plugin.png)](https://travis-ci.org/peridot-php/peridot-prophecy-plugin) [![HHVM Status](http://hhvm.h4cc.de/badge/peridot-php/peridot-prophecy-plugin.svg)](http://hhvm.h4cc.de/package/peridot-php/peridot-prophecy-plugin)\n\nUse Peridot with the amazing mocking framework [Prophecy](https://github.com/phpspec/prophecy)\n\n##Usage\n\nWe recommend installing this plugin to your project via composer:\n\n```\n$ composer require --dev peridot-php/peridot-prophecy-plugin:~1.0\n```\n\nYou can register the plugin via your [peridot.php](http://peridot-php.github.io/#plugins) file.\n\n```php\n\u003c?php\nuse Evenement\\EventEmitterInterface;\nuse Peridot\\Plugin\\Prophecy\\ProphecyPlugin;\n\nreturn function(EventEmitterInterface $emitter) {\n    $plugin = new ProphecyPlugin($emitter);\n};\n```\n\nRegistering this plugin will add a `ProphecyScope` as a child scope to all of your tests. This will allow you\nto get a prophet object in all of your tests.\n\n```php\n\u003c?php\ndescribe('Bird', function() {\n    it('should fly', function() {\n        $mock = $this-\u003egetProphet()-\u003eprophesize('Bird');\n        //do stuff with the mock\n    });\n});\n```\n\n###Automatic injection of mock\n\nIf a test suite's description is an existing class, the prophecy plugin will automatically inject a `$subject` instance\nvariable into your tests that is a mock of the class.\n\n```php\ndescribe('Vendor\\Namespace\\Klass', function() {\n    it('should have a subject', function() {\n        $instance = $this-\u003esubject-\u003ereveal();\n        assert($instance instanceof Klass, 'should be instance of Klass');\n    });\n});\n```\n\n###Using the scope on a test by test basis\n\nLike any other peridot [scope](http://peridot-php.github.io/#scopes), you can mix the `ProphecyScope` provided by this plugin\non a test by test, or suite by suite basis.\n\n```php\n\u003c?php\nuse Peridot\\Plugin\\Prophecy\\ProphecyScope;\n\ndescribe('Bird', function() {\n    //here we manually mixin the http kernel scope\n    $scope = new ProphecyScope();\n    $this-\u003eperidotAddChildScope($scope);\n\n    it('should fly', function() {\n        $mock = $this-\u003egetProphet()-\u003eprophesize('Bird');\n        //do stuff with the mock\n    });\n});\n```\n\n##Example specs\n\nTo test examples that are using the plugin, run the following:\n\n```\n$ vendor/bin/peridot example/bird.spec.php\n```\n\n##Running plugin tests\n\n```\n$ vendor/bin/peridot specs/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperidot-php%2Fperidot-prophecy-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperidot-php%2Fperidot-prophecy-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperidot-php%2Fperidot-prophecy-plugin/lists"}