{"id":19961200,"url":"https://github.com/formapro/phpunitextensions","last_synced_at":"2026-05-13T04:33:40.681Z","repository":{"id":66342998,"uuid":"7815969","full_name":"formapro/PhpunitExtensions","owner":"formapro","description":"Some useful extensions for phpunit. ","archived":false,"fork":false,"pushed_at":"2013-02-02T19:57:29.000Z","size":168,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-12T07:44:00.478Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/formapro.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":"2013-01-25T07:51:14.000Z","updated_at":"2015-11-06T17:00:16.000Z","dependencies_parsed_at":"2023-02-20T02:25:15.317Z","dependency_job_id":null,"html_url":"https://github.com/formapro/PhpunitExtensions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formapro%2FPhpunitExtensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formapro%2FPhpunitExtensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formapro%2FPhpunitExtensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formapro%2FPhpunitExtensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/formapro","download_url":"https://codeload.github.com/formapro/PhpunitExtensions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241391599,"owners_count":19955553,"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-13T02:06:40.008Z","updated_at":"2026-05-13T04:33:40.643Z","avatar_url":"https://github.com/formapro.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"PhpunitExtensions\n=================\n\nWrite attribute extension\n-------------------------\n\nIt is simple extension which allows to access protected properties. It is like readAttribute shipped with phpunit.\n\n```php\n\u003c?php\n\nclass Foo\n{\n    protected $id;\n    \n    public function getId()\n    {\n        return $this-\u003eid;\n    }\n}\n\nclass FooTest extends PHPUnit_Framework_TestCase\n{\n    use \\Fp\\PhpunitExtension\\WriteAttributeTrait;\n\n    public function testReturnExpectedId()\n    {\n        $foo = new Foo;\n        $this-\u003ewriteAttribute($foo, 'id', 10);\n\n        $this-\u003eassertEquals(10, $foo-\u003egetId());\n        \n        //or\n        \n        $this-\u003ewriteIdAttribute($foo, 20);\n        \n        $this-\u003eassertEquals(20, $foo-\u003egetId());\n    }\n}\n```\n\nStub extension\n--------------\n\n```php\n\u003c?php\n\nclass Foo\n{\n    public function __construct($anArgument) {}\n\n    public function bar() {}\n    \n    public function baz($a) {}\n}\n\nclass FooTest extends PHPUnit_Framework_TestCase\n{\n    use \\Fp\\PhpunitExtension\\StubTrait;\n\n    public function testFoo()\n    {\n        $fooStub = $this-\u003egetStub('Foo', array(\n            'bar' =\u003e 'barResult',\n            'baz' =\u003e $this-\u003ereturnValueMap(array(\n                array('theArg', 'bazResult')\n            ))\n        ));\n\n        $this-\u003eassertEquals('barResult', $fooStub-\u003ebar());\n        $this-\u003eassertEquals('bazResult', $fooStub-\u003ebaz('theArg'));\n    }\n}\n```\n\nAs you can see the constructor is **overwritten**. \nYou can define returned values or pass instance of `PHPUnit_Framework_MockObject_Stub`.\nThere is an [issue](https://github.com/sebastianbergmann/phpunit/issues/550) at phpunit.\n\nFumocker extension\n------------------\n\nThis extension could be used to mock function. For that you have to install [fp\\fumocker](https://github.com/formapro/Fumocker) lib first.\n\n```php\n\u003c?php\n\nclass FooTest extends PHPUnit_Framework_TestCase\n{\n    use \\Fp\\PhpunitExtension\\SetUpTrait;\n    use \\Fp\\PhpunitExtension\\Fumocker\\FumockerTrait;\n\n    public function setUp()\n    {\n        $this-\u003esetUpExtensions();\n    }\n    \n    public function tearDown()\n    {\n        $this-\u003etearDownExtensions();\n    }\n\n    public function testFoo()\n    {\n        $expectedEmailTo = 'admin@example.com';\n        \n        /**\n         * @var $mock \\PHPUnit_Framework_MockObject_MockObject\n         */\n        $mock = $this-\u003egetFunctionMock('Namespace/Where/Tested/Class/Is', 'mail');\n        $mock\n            -\u003eexpects($this-\u003eonce())\n            -\u003emethod('mail')\n            -\u003ewith($expectedEmailTo)\n        ;\n\n        //test your Namespace/Where/Tested/Class/Is/Foo class\n    }\n}","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformapro%2Fphpunitextensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fformapro%2Fphpunitextensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformapro%2Fphpunitextensions/lists"}