{"action":"opened","number":8,"pull_request":{"url":"https://api.github.com/repos/daylerees/scientist/pulls/8","id":58534416,"html_url":"https://github.com/daylerees/scientist/pull/8","diff_url":"https://github.com/daylerees/scientist/pull/8.diff","patch_url":"https://github.com/daylerees/scientist/pull/8.patch","issue_url":"https://api.github.com/repos/daylerees/scientist/issues/8","number":8,"state":"open","locked":false,"title":"Studies for class experiments","user":{"login":"jeremygiberson","id":487411,"avatar_url":"https://avatars.githubusercontent.com/u/487411?v=3","gravatar_id":"","url":"https://api.github.com/users/jeremygiberson","html_url":"https://github.com/jeremygiberson","followers_url":"https://api.github.com/users/jeremygiberson/followers","following_url":"https://api.github.com/users/jeremygiberson/following{/other_user}","gists_url":"https://api.github.com/users/jeremygiberson/gists{/gist_id}","starred_url":"https://api.github.com/users/jeremygiberson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeremygiberson/subscriptions","organizations_url":"https://api.github.com/users/jeremygiberson/orgs","repos_url":"https://api.github.com/users/jeremygiberson/repos","events_url":"https://api.github.com/users/jeremygiberson/events{/privacy}","received_events_url":"https://api.github.com/users/jeremygiberson/received_events","type":"User","site_admin":false},"body":"# Class Experiments\r\nThis is a feature addition that adds the abilities to run experiments on classes. \r\n\r\n## Features\r\n  * creates a proxy instance that can be used throughout your system\r\n  * proxy instance can implement as many interfaces as you need/want (including none) for when you have typehints/no-typehints\r\n  * control properties that are used but not implemented in trials are tracked\r\n  * control methods that are used but not implemented in trials are tracked\r\n\r\n## Use Case\r\nImagine you have a dependency in your system that you want to write a new implementation for. With class experiments you can create proxy around your dependency so that experiments can be run against trial implementations. \r\n\r\n\r\n\r\n### usage sample\r\nProvided you have a defined dependency, and a dependency factory:\r\n\r\n```php\r\ninterface UserRepository {\r\n    public function getUserComments($userId);\r\n    public function getUserArticles($userId);\r\n    public function getUserKarma($userId);\r\n}\r\n\r\n// your existing implementation\r\nclass PdoUserRepository implements UserRepository {\r\n    public function __construct(Pdo $db) { }\r\n    // ... method implementations\r\n} \r\n\r\n// your existing factory\r\nclass UserRepositoryFactory {\r\n    public function create($di) {\r\n        $db = $di['database'];\r\n        return new PdoUserRepository($db);\r\n    }\r\n}\r\n```\r\n\r\nYou also have a new user repository implementation:\r\n\r\n```php\r\nclass DoctrineUserRepository implements UserRepository {\r\n    public function __construct(EntityManager $em) { }\r\n    // ... method implementations\r\n}\r\n\r\nIn order to run an experiment in your application with the old implementation as control, and new implementation as a trial, you would update your factory like:\r\n\r\n\r\n```php\r\nclass UserRepositoryFactory {\r\n    public function create($di) {\r\n        $db = $di['database'];\r\n        $em = $di['entity_manager'];\r\n        $scientist = $di['scientist'];\r\n        $blind = $scientist->study('doctrine user repository implementation')\r\n            ->control(new PdoUserRepository($db))\r\n            ->trial(new DoctrineUserRepository($db))\r\n            ->blind(UserRepository::class); // blind will implement UserRepository\r\n\r\n           return $blind;\r\n    }\r\n}\r\n```\r\n\r\n## Internal Workings\r\nThe class experiment is implemented as a collection of experiments created to match each of the public methods and properties of the control instance. A proxy object is created that will map method calls and property access to the appropriate experiment. The proxy object can optionally implement a interface(s) so that it satisfies type hints.\r\n\r\nBesides some work under the hood, the feature is functionally equivalent to manually creating an experiment for each method of a class. Ie:\r\n\r\n```php\r\n$control = new Foo;\r\n$trial = new Bar;\r\n\r\n$experiment = $scientist->experiment('methodA')\r\n    ->control(function() use($control) { $args = func_get_args(); return call_user_func_array([$control, $args]); })\r\n    ->trial(function() use($trial) { $args = func_get_args(); return call_user_func_array([$trial, $args]); });\r\n\r\n$experiment->run(); \r\n```","created_at":"2016-02-07T00:13:33Z","updated_at":"2016-02-07T00:13:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/daylerees/scientist/pulls/8/commits","review_comments_url":"https://api.github.com/repos/daylerees/scientist/pulls/8/comments","review_comment_url":"https://api.github.com/repos/daylerees/scientist/pulls/comments{/number}","comments_url":"https://api.github.com/repos/daylerees/scientist/issues/8/comments","statuses_url":"https://api.github.com/repos/daylerees/scientist/statuses/5256c7fee3a7b18131aa0ba8ff48f4f53f686e96","head":{"label":"jeremygiberson:studies-for-class-experiments","ref":"studies-for-class-experiments","sha":"5256c7fee3a7b18131aa0ba8ff48f4f53f686e96","user":{"login":"jeremygiberson","id":487411,"avatar_url":"https://avatars.githubusercontent.com/u/487411?v=3","gravatar_id":"","url":"https://api.github.com/users/jeremygiberson","html_url":"https://github.com/jeremygiberson","followers_url":"https://api.github.com/users/jeremygiberson/followers","following_url":"https://api.github.com/users/jeremygiberson/following{/other_user}","gists_url":"https://api.github.com/users/jeremygiberson/gists{/gist_id}","starred_url":"https://api.github.com/users/jeremygiberson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeremygiberson/subscriptions","organizations_url":"https://api.github.com/users/jeremygiberson/orgs","repos_url":"https://api.github.com/users/jeremygiberson/repos","events_url":"https://api.github.com/users/jeremygiberson/events{/privacy}","received_events_url":"https://api.github.com/users/jeremygiberson/received_events","type":"User","site_admin":false},"repo":{"id":51216142,"name":"scientist","full_name":"jeremygiberson/scientist","owner":{"login":"jeremygiberson","id":487411,"avatar_url":"https://avatars.githubusercontent.com/u/487411?v=3","gravatar_id":"","url":"https://api.github.com/users/jeremygiberson","html_url":"https://github.com/jeremygiberson","followers_url":"https://api.github.com/users/jeremygiberson/followers","following_url":"https://api.github.com/users/jeremygiberson/following{/other_user}","gists_url":"https://api.github.com/users/jeremygiberson/gists{/gist_id}","starred_url":"https://api.github.com/users/jeremygiberson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeremygiberson/subscriptions","organizations_url":"https://api.github.com/users/jeremygiberson/orgs","repos_url":"https://api.github.com/users/jeremygiberson/repos","events_url":"https://api.github.com/users/jeremygiberson/events{/privacy}","received_events_url":"https://api.github.com/users/jeremygiberson/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jeremygiberson/scientist","description":"A PHP experimentation library inspired by Github's own Scientist.","fork":true,"url":"https://api.github.com/repos/jeremygiberson/scientist","forks_url":"https://api.github.com/repos/jeremygiberson/scientist/forks","keys_url":"https://api.github.com/repos/jeremygiberson/scientist/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jeremygiberson/scientist/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jeremygiberson/scientist/teams","hooks_url":"https://api.github.com/repos/jeremygiberson/scientist/hooks","issue_events_url":"https://api.github.com/repos/jeremygiberson/scientist/issues/events{/number}","events_url":"https://api.github.com/repos/jeremygiberson/scientist/events","assignees_url":"https://api.github.com/repos/jeremygiberson/scientist/assignees{/user}","branches_url":"https://api.github.com/repos/jeremygiberson/scientist/branches{/branch}","tags_url":"https://api.github.com/repos/jeremygiberson/scientist/tags","blobs_url":"https://api.github.com/repos/jeremygiberson/scientist/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jeremygiberson/scientist/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jeremygiberson/scientist/git/refs{/sha}","trees_url":"https://api.github.com/repos/jeremygiberson/scientist/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jeremygiberson/scientist/statuses/{sha}","languages_url":"https://api.github.com/repos/jeremygiberson/scientist/languages","stargazers_url":"https://api.github.com/repos/jeremygiberson/scientist/stargazers","contributors_url":"https://api.github.com/repos/jeremygiberson/scientist/contributors","subscribers_url":"https://api.github.com/repos/jeremygiberson/scientist/subscribers","subscription_url":"https://api.github.com/repos/jeremygiberson/scientist/subscription","commits_url":"https://api.github.com/repos/jeremygiberson/scientist/commits{/sha}","git_commits_url":"https://api.github.com/repos/jeremygiberson/scientist/git/commits{/sha}","comments_url":"https://api.github.com/repos/jeremygiberson/scientist/comments{/number}","issue_comment_url":"https://api.github.com/repos/jeremygiberson/scientist/issues/comments{/number}","contents_url":"https://api.github.com/repos/jeremygiberson/scientist/contents/{+path}","compare_url":"https://api.github.com/repos/jeremygiberson/scientist/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jeremygiberson/scientist/merges","archive_url":"https://api.github.com/repos/jeremygiberson/scientist/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jeremygiberson/scientist/downloads","issues_url":"https://api.github.com/repos/jeremygiberson/scientist/issues{/number}","pulls_url":"https://api.github.com/repos/jeremygiberson/scientist/pulls{/number}","milestones_url":"https://api.github.com/repos/jeremygiberson/scientist/milestones{/number}","notifications_url":"https://api.github.com/repos/jeremygiberson/scientist/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jeremygiberson/scientist/labels{/name}","releases_url":"https://api.github.com/repos/jeremygiberson/scientist/releases{/id}","deployments_url":"https://api.github.com/repos/jeremygiberson/scientist/deployments","created_at":"2016-02-06T18:46:20Z","updated_at":"2016-02-06T18:46:20Z","pushed_at":"2016-02-06T23:40:38Z","git_url":"git://github.com/jeremygiberson/scientist.git","ssh_url":"git@github.com:jeremygiberson/scientist.git","clone_url":"https://github.com/jeremygiberson/scientist.git","svn_url":"https://github.com/jeremygiberson/scientist","homepage":"https://scientist.readme.io","size":89,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"daylerees:master","ref":"master","sha":"9476f7ba1f5c11c5541dfdd9bc9ad50bbe4027a5","user":{"login":"daylerees","id":207870,"avatar_url":"https://avatars.githubusercontent.com/u/207870?v=3","gravatar_id":"","url":"https://api.github.com/users/daylerees","html_url":"https://github.com/daylerees","followers_url":"https://api.github.com/users/daylerees/followers","following_url":"https://api.github.com/users/daylerees/following{/other_user}","gists_url":"https://api.github.com/users/daylerees/gists{/gist_id}","starred_url":"https://api.github.com/users/daylerees/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daylerees/subscriptions","organizations_url":"https://api.github.com/users/daylerees/orgs","repos_url":"https://api.github.com/users/daylerees/repos","events_url":"https://api.github.com/users/daylerees/events{/privacy}","received_events_url":"https://api.github.com/users/daylerees/received_events","type":"User","site_admin":false},"repo":{"id":51095439,"name":"scientist","full_name":"daylerees/scientist","owner":{"login":"daylerees","id":207870,"avatar_url":"https://avatars.githubusercontent.com/u/207870?v=3","gravatar_id":"","url":"https://api.github.com/users/daylerees","html_url":"https://github.com/daylerees","followers_url":"https://api.github.com/users/daylerees/followers","following_url":"https://api.github.com/users/daylerees/following{/other_user}","gists_url":"https://api.github.com/users/daylerees/gists{/gist_id}","starred_url":"https://api.github.com/users/daylerees/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daylerees/subscriptions","organizations_url":"https://api.github.com/users/daylerees/orgs","repos_url":"https://api.github.com/users/daylerees/repos","events_url":"https://api.github.com/users/daylerees/events{/privacy}","received_events_url":"https://api.github.com/users/daylerees/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/daylerees/scientist","description":"A PHP experimentation library inspired by Github's own Scientist.","fork":false,"url":"https://api.github.com/repos/daylerees/scientist","forks_url":"https://api.github.com/repos/daylerees/scientist/forks","keys_url":"https://api.github.com/repos/daylerees/scientist/keys{/key_id}","collaborators_url":"https://api.github.com/repos/daylerees/scientist/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/daylerees/scientist/teams","hooks_url":"https://api.github.com/repos/daylerees/scientist/hooks","issue_events_url":"https://api.github.com/repos/daylerees/scientist/issues/events{/number}","events_url":"https://api.github.com/repos/daylerees/scientist/events","assignees_url":"https://api.github.com/repos/daylerees/scientist/assignees{/user}","branches_url":"https://api.github.com/repos/daylerees/scientist/branches{/branch}","tags_url":"https://api.github.com/repos/daylerees/scientist/tags","blobs_url":"https://api.github.com/repos/daylerees/scientist/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/daylerees/scientist/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/daylerees/scientist/git/refs{/sha}","trees_url":"https://api.github.com/repos/daylerees/scientist/git/trees{/sha}","statuses_url":"https://api.github.com/repos/daylerees/scientist/statuses/{sha}","languages_url":"https://api.github.com/repos/daylerees/scientist/languages","stargazers_url":"https://api.github.com/repos/daylerees/scientist/stargazers","contributors_url":"https://api.github.com/repos/daylerees/scientist/contributors","subscribers_url":"https://api.github.com/repos/daylerees/scientist/subscribers","subscription_url":"https://api.github.com/repos/daylerees/scientist/subscription","commits_url":"https://api.github.com/repos/daylerees/scientist/commits{/sha}","git_commits_url":"https://api.github.com/repos/daylerees/scientist/git/commits{/sha}","comments_url":"https://api.github.com/repos/daylerees/scientist/comments{/number}","issue_comment_url":"https://api.github.com/repos/daylerees/scientist/issues/comments{/number}","contents_url":"https://api.github.com/repos/daylerees/scientist/contents/{+path}","compare_url":"https://api.github.com/repos/daylerees/scientist/compare/{base}...{head}","merges_url":"https://api.github.com/repos/daylerees/scientist/merges","archive_url":"https://api.github.com/repos/daylerees/scientist/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/daylerees/scientist/downloads","issues_url":"https://api.github.com/repos/daylerees/scientist/issues{/number}","pulls_url":"https://api.github.com/repos/daylerees/scientist/pulls{/number}","milestones_url":"https://api.github.com/repos/daylerees/scientist/milestones{/number}","notifications_url":"https://api.github.com/repos/daylerees/scientist/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/daylerees/scientist/labels{/name}","releases_url":"https://api.github.com/repos/daylerees/scientist/releases{/id}","deployments_url":"https://api.github.com/repos/daylerees/scientist/deployments","created_at":"2016-02-04T18:16:37Z","updated_at":"2016-02-07T00:00:54Z","pushed_at":"2016-02-06T22:35:03Z","git_url":"git://github.com/daylerees/scientist.git","ssh_url":"git@github.com:daylerees/scientist.git","clone_url":"https://github.com/daylerees/scientist.git","svn_url":"https://github.com/daylerees/scientist","homepage":"https://scientist.readme.io","size":82,"stargazers_count":190,"watchers_count":190,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":3,"forks":5,"open_issues":3,"watchers":190,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/daylerees/scientist/pulls/8"},"html":{"href":"https://github.com/daylerees/scientist/pull/8"},"issue":{"href":"https://api.github.com/repos/daylerees/scientist/issues/8"},"comments":{"href":"https://api.github.com/repos/daylerees/scientist/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/daylerees/scientist/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/daylerees/scientist/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/daylerees/scientist/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/daylerees/scientist/statuses/5256c7fee3a7b18131aa0ba8ff48f4f53f686e96"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":5,"additions":930,"deletions":1,"changed_files":17}}