{"action":"created","issue":{"url":"https://api.github.com/repos/phpspec/prophecy/issues/197","labels_url":"https://api.github.com/repos/phpspec/prophecy/issues/197/labels{/name}","comments_url":"https://api.github.com/repos/phpspec/prophecy/issues/197/comments","events_url":"https://api.github.com/repos/phpspec/prophecy/issues/197/events","html_url":"https://github.com/phpspec/prophecy/issues/197","id":92393249,"number":197,"title":"[RFC] Support for mock for final class","user":{"login":"Nek-","id":972456,"avatar_url":"https://avatars.githubusercontent.com/u/972456?v=3","gravatar_id":"","url":"https://api.github.com/users/Nek-","html_url":"https://github.com/Nek-","followers_url":"https://api.github.com/users/Nek-/followers","following_url":"https://api.github.com/users/Nek-/following{/other_user}","gists_url":"https://api.github.com/users/Nek-/gists{/gist_id}","starred_url":"https://api.github.com/users/Nek-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nek-/subscriptions","organizations_url":"https://api.github.com/users/Nek-/orgs","repos_url":"https://api.github.com/users/Nek-/repos","events_url":"https://api.github.com/users/Nek-/events{/privacy}","received_events_url":"https://api.github.com/users/Nek-/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-01T14:02:58Z","updated_at":"2015-07-01T14:13:49Z","closed_at":null,"body":"Hello,\r\n\r\nI think code should not be change for tests. But currently, to work with prophecy and/or phpspec, that's what people do. (i.e. https://github.com/doctrine/doctrine2/pull/1215)\r\n\r\nI think it's time to change that and supports mock for final classes.\r\n\r\nWhat do you think about that ?"},"comment":{"url":"https://api.github.com/repos/phpspec/prophecy/issues/comments/117690561","html_url":"https://github.com/phpspec/prophecy/issues/197#issuecomment-117690561","issue_url":"https://api.github.com/repos/phpspec/prophecy/issues/197","id":117690561,"user":{"login":"stof","id":439401,"avatar_url":"https://avatars.githubusercontent.com/u/439401?v=3","gravatar_id":"","url":"https://api.github.com/users/stof","html_url":"https://github.com/stof","followers_url":"https://api.github.com/users/stof/followers","following_url":"https://api.github.com/users/stof/following{/other_user}","gists_url":"https://api.github.com/users/stof/gists{/gist_id}","starred_url":"https://api.github.com/users/stof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stof/subscriptions","organizations_url":"https://api.github.com/users/stof/orgs","repos_url":"https://api.github.com/users/stof/repos","events_url":"https://api.github.com/users/stof/events{/privacy}","received_events_url":"https://api.github.com/users/stof/received_events","type":"User","site_admin":false},"created_at":"2015-07-01T14:13:49Z","updated_at":"2015-07-01T14:13:49Z","body":"How would you mock final classes ? The generated mock class currently extends the mocked class so that it passes typehints, and so it is not possible for final classes.\r\n\r\nAFAICT, mocking final classes would involved defining a mock definition of the class and running all the code for this mock in a PHP process where the original class is never loaded. But this makes things much more complex, because it involves many assumption about the code using the mocking library, and would make the library incompatible with PHPUnit or PhpSpec (meaning we won't do it as the primary goal of creating Prophecy was to fulfill the PhpSpec needs) as they run several tests in the same PHP process.\r\nAnd it also makes the job of PhpSpec much harder, because it would have to stop using Reflection to get info about the class (as this requires loading the class) and to stop using autoloading to find the class declaration (which would be a huge pain to configure Prophecy as you would have to configure a separate class locator).\r\nThus, it would also mean than internal classes (i.e. classes defined in C extensions) would not be mockable with such implementation, as well as any class loaded by the test runtime (as they would be loaded in the process)."}}