{"id":42616439,"url":"https://github.com/konsulting/exposer","last_synced_at":"2026-01-29T03:57:03.127Z","repository":{"id":57008427,"uuid":"122269194","full_name":"konsulting/exposer","owner":"konsulting","description":"Access non-public methods and properties on classes.","archived":false,"fork":false,"pushed_at":"2018-07-30T14:21:23.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-11-20T09:16:02.064Z","etag":null,"topics":["php","reflection","testing","unit-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/konsulting.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-20T23:21:15.000Z","updated_at":"2018-02-21T23:45:10.000Z","dependencies_parsed_at":"2022-08-21T14:31:14.601Z","dependency_job_id":null,"html_url":"https://github.com/konsulting/exposer","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/konsulting/exposer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konsulting%2Fexposer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konsulting%2Fexposer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konsulting%2Fexposer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konsulting%2Fexposer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/konsulting","download_url":"https://codeload.github.com/konsulting/exposer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konsulting%2Fexposer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28862138,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T22:56:21.783Z","status":"online","status_checked_at":"2026-01-29T02:00:06.714Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["php","reflection","testing","unit-testing"],"created_at":"2026-01-29T03:57:01.836Z","updated_at":"2026-01-29T03:57:03.121Z","avatar_url":"https://github.com/konsulting.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Exposer\n\nAlthough for the most part only public methods of classes are unit tested, it's sometimes necessary or helpful to have access to protected or private methods and properties.\nExposer provides a convenient way to do this whilst keeping your tests clear and concise.\n\n## Installation\nInstall via Composer:\n```\n $ composer require konsulting/exposer\n```\n\n## Usage\nConsider the following class:\n```php\nclass ClassUnderTest\n{\n    protected $secret = 'My secret';\n    \n    protected static $anotherSecret = 'My static secret';\n    \n    protected function add($number1, $number2)\n    {\n        return $number1 + $number2;\n    }\n    \n    protected static function multiply($number1, $number2)\n    {\n        return $number1 * $number2;\n    }\n}\n```\n\nThere are multiple ways to test the protected methods and properties on this class.\n\n### Base Exposer\nThe most direct way is with the `BaseExposer` class. \nThe subject must be passed into each method, and may be either an instance or the (string) class name.\n\n```php\nuse Konsulting\\Exposer\\BaseExposer;\n\n// With an instance\nBaseExposer::hasMethod(new ClassUnderTest, 'add');                          // true\nBaseExposer::invokeMethod(new ClassUnderTest, 'add', [1, 1]);               // 2\nBaseExposer::getProperty(new ClassUnderTest, 'secret');                     // 'My secret'\n\n// Static context\nBaseExposer::hasMethod(ClassUnderTest::class, 'multiply');                  // true\nBaseExposer::invokeMethod(ClassUnderTest::class, 'multiply', [2,2]);        // 4\nBaseExposer::getProperty(ClassUnderTest::class, 'anotherSecret');           // 'My static secret'\n```\n\n### Exposer\nThe `Exposer` class allows the use of a class's inaccessible methods and properties as if they were public.\n\n```php\nuse Konsulting\\Exposer\\Exposer;\n\n$exposer = Exposer::make(new ClassUnderTest);\n\n$exposer-\u003eadd(1, 1);                                // 2\n$exposer-\u003emultiply(2, 2);                           // 4\n$exposer-\u003esecret;                                   // 'My secret'\n$exposer-\u003eanotherSecret;                            // 'My static secret'\n\n// These non-magic methods are also available\n$exposer-\u003einvokeMethod('add', [1, 1]);               // 2\n$exposer-\u003egetProperty('secret');                     // 'My secret'\n```\n\nExposer can also access class's static methods and properties without the need to provide an instance.\n\n```php\nuse Konsulting\\Exposer\\Exposer;\n\n$exposer = Exposer::make(ClassUnderTest::class);\n\n$exposer-\u003emultiply(2, 2);                           // 4\n$exposer-\u003eanotherSecret;                            // 'My static secret'\n\n$exposer-\u003einvokeMethod('multiply', [2, 2]);         // 4\n$exposer-\u003egetProperty('anotherSecret');             // 'My static secret'\n```\n\n**Note:** Static methods and properties are available from an instance context, but of course non-static methods and properties are not available from a static context.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkonsulting%2Fexposer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkonsulting%2Fexposer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkonsulting%2Fexposer/lists"}