{"id":807,"date":"2012-12-03T13:23:16","date_gmt":"2012-12-03T13:23:16","guid":{"rendered":"http:\/\/www.nathankowald.com\/blog\/?p=807"},"modified":"2016-11-13T16:58:50","modified_gmt":"2016-11-13T16:58:50","slug":"how-to-unit-test-private-methods-in-php","status":"publish","type":"post","link":"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/","title":{"rendered":"Unit test private methods in PHP"},"content":{"rendered":"<p><strong>Requires:<\/strong> PHP 5.3.2 or greater.<br \/>\nIf you&#8217;re not running 5.3.2+ you can test private methods indirectly by creating a public method, that calls your private method.<\/p>\n<div style=\"padding: 7px; background-color: #f3fceb; border: 2px solid #92DE7E; font-size:1.2em;\">\n<a href=\"#solution\">&darr; Jump to solution<\/a>\n<\/div>\n<h2>Problem<\/h2>\n<p>We have a class, <strong>StatFinder<\/strong> which contains a private method, <strong>getDomainFromEmail()<\/strong> that we want to test.<\/p>\n<pre class=\"prettyprint lang-php\">\r\n&lt;?php\r\nclass StatFinder\r\n{\r\n    \/\/ Get domain from email address\r\n    private function getDomainFromEmail($email='')\r\n    {\r\n        if ($email == '') return '';\r\n        $parts = explode('@', $email);\r\n        if ($parts === false || !isset($parts[1])) return '';\r\n\r\n        return $parts[1];\r\n    }\r\n}<\/pre>\n<p>We create a test to check that calling <strong>getEmailFromDomain(&#8216;iliketurtles@gmail.com&#8217;)<\/strong> returns the expected &#8216;<strong>gmail.com<\/strong>&#8216;. I&#8217;m using <a href=\"http:\/\/www.phpunit.de\">PHPUnit<\/a> to run the unit test.<\/p>\n<pre class=\"prettyprint lang-php\">\r\n&lt;?php\r\ninclude('..\/libraries\/StatFinder.php');\r\n\r\nclass StatFinderTest extends PHPUnit_Framework_TestCase\r\n{\r\n    public function testGetDomainFromEmail()\r\n    {\r\n        $sf = new StatFinder();\r\n        $email = 'iliketurtles@gmail.com';\r\n        $expected = 'gmail.com';\r\n        $this->assertEquals($expected, $sf->getDomainFromEmail($email));\r\n    }\r\n}<\/pre>\n<p>When run, the test fails because the method is private, so only accessible by the class that defined it.<\/p>\n<p><a href=\"http:\/\/www.nathankowald.com\/blog\/wp-content\/uploads\/2012\/12\/failed-test.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-854\" title=\"failed-test\" src=\"http:\/\/www.nathankowald.com\/blog\/wp-content\/uploads\/2012\/12\/failed-test-1024x171.png\" alt=\"\" width=\"614\" height=\"103\" srcset=\"https:\/\/www.nathankowald.com\/blog\/wp-content\/uploads\/2012\/12\/failed-test-1024x171.png 1024w, https:\/\/www.nathankowald.com\/blog\/wp-content\/uploads\/2012\/12\/failed-test-300x50.png 300w, https:\/\/www.nathankowald.com\/blog\/wp-content\/uploads\/2012\/12\/failed-test.png 1263w\" sizes=\"auto, (max-width: 614px) 100vw, 614px\" \/><\/a><br \/>\n<em>Failed unit test &ndash; (PHPUnit running in PhpStorm)<\/em><br \/>\n<a name=\"solution\"><\/a><\/p>\n<h2>Solution<\/h2>\n<p>You can test private and protected methods by using the ReflectionMethod class, part of the <a href=\"http:\/\/php.net\/manual\/en\/book.reflection.php\">Reflection API<\/a> that comes with PHP 5.<br \/>\nThe <a href=\"http:\/\/php.net\/manual\/en\/reflectionmethod.setaccessible.php\">setAccessible<\/a> method of the ReflectionMethod class is only available from PHP 5.3.2 up so you&#8217;ll have to be running at least this to use this.<\/p>\n<pre class=\"prettyprint lang-php\">\r\n&lt;?php\r\ninclude('..\/libraries\/StatFinder.php');\r\n\r\nclass StatFinderTest extends PHPUnit_Framework_TestCase\r\n{\r\n    public function testGetDomainFromEmail()\r\n    {\r\n        $method = new ReflectionMethod('StatFinder', 'getDomainFromEmail');\r\n        $method->setAccessible(true);\r\n\r\n        $email = 'iliketurtles@gmail.com';\r\n        $expected = 'gmail.com';\r\n        $this->assertEquals($expected, $method->invoke(new StatFinder, $email));\r\n    }\r\n}<\/pre>\n<h2>Explanation<\/h2>\n<pre class=\"prettyprint lang-php\">\r\n&lt;?php\r\n$method = new ReflectionMethod('StatFinder', 'getDomainFromEmail');<\/pre>\n<p>This creates an instance of the ReflectionMethod class.<br \/>\nThe first argument, <strong>StatFinder<\/strong> is the class that contains the private method to test.<br \/>\nThe second argument, <strong>getDomainFromEmail<\/strong> is the method to test.<\/p>\n<pre class=\"prettyprint lang-php\">\r\n&lt;?php\r\n$method->setAccessible(true);<\/pre>\n<p><strong>setAccessible(true)<\/strong> allows the private method, <strong>getDomainFromEmail<\/strong> to be called from inside the test.<\/p>\n<pre class=\"prettyprint lang-php\">\r\n&lt;?php\r\n$this->assertEquals($expected, $method->invoke(new StatFinder, $email));<\/pre>\n<p><strong>invoke()<\/strong> invokes the private method.<br \/>\nThe first argument, <strong>new StatFinder<\/strong> is the object to invoke the method on. For static methods, pass null.<br \/>\nThe second argument, <strong>$email<\/strong> is the argument to pass to the method. Zero or more arguments can be passed to the method this way.<\/p>\n<p>We run our updated test and it now works.<\/p>\n<p><a href=\"http:\/\/www.nathankowald.com\/blog\/wp-content\/uploads\/2012\/12\/successful-test.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.nathankowald.com\/blog\/wp-content\/uploads\/2012\/12\/successful-test.png\" alt=\"\" title=\"successful-test\" width=\"467\" height=\"207\" class=\"alignnone size-full wp-image-891\" srcset=\"https:\/\/www.nathankowald.com\/blog\/wp-content\/uploads\/2012\/12\/successful-test.png 467w, https:\/\/www.nathankowald.com\/blog\/wp-content\/uploads\/2012\/12\/successful-test-300x132.png 300w\" sizes=\"auto, (max-width: 467px) 100vw, 467px\" \/><\/a><br \/>\n<em>Successful test<\/em><\/p>\n<h2>Related<\/h2>\n<ul class=\"lovedarticles\">\n<li><a href=\"http:\/\/sebastian-bergmann.de\/archives\/881-Testing-Your-Privates.html\">Testing Your Privates &#8211; Sebastian Bergmann<\/a><\/li>\n<li><a href=\"http:\/\/www.phptherightway.com\/#testing\">PHP: The Right Way &#8211; Testing<\/a><\/li>\n<li><a href=\"http:\/\/programmer.97things.oreilly.com\/wiki\/index.php\/The_Three_Laws_of_Test-Driven_Development\">The Three Laws of Test-Driven Development<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/105007\/should-i-test-private-methods-or-only-public-ones\">Should I test private methods or only public ones? &#8211; Stack Overflow<\/a>\n<li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>You can test private and protected methods by using the ReflectionMethod class, part of the <a href=\"http:\/\/php.net\/manual\/en\/book.reflection.php\">Reflection API<\/a> that comes with PHP 5.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[20,7],"tags":[],"class_list":["post-807","post","type-post","status-publish","format-standard","hentry","category-unit-testing","category-web-development"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.9 - aioseo.com -->\n\t<meta name=\"description\" content=\"You can test private and protected methods by using the ReflectionMethod class, part of the Reflection API that comes with PHP 5.\" \/>\n\t<meta name=\"robots\" content=\"noarchive, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n\t<meta name=\"author\" content=\"Nathan Kowald\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.9\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Nathan&#039;s Blog | Web development and useful information\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Unit test private methods in PHP \u2014 Nathan&#039;s Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"You can test private and protected methods by using the ReflectionMethod class, part of the Reflection API that comes with PHP 5.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2012-12-03T13:23:16+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2016-11-13T16:58:50+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Unit test private methods in PHP \u2014 Nathan&#039;s Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"You can test private and protected methods by using the ReflectionMethod class, part of the Reflection API that comes with PHP 5.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2012\\\/12\\\/how-to-unit-test-private-methods-in-php\\\/#article\",\"name\":\"Unit test private methods in PHP \\u2014 Nathan's Blog\",\"headline\":\"Unit test private methods in PHP\",\"author\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/author\\\/ozymandias\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/#person\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"http:\\\/\\\/www.nathankowald.com\\\/blog\\\/wp-content\\\/uploads\\\/2012\\\/12\\\/failed-test-1024x171.png\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2012\\\/12\\\/how-to-unit-test-private-methods-in-php\\\/#articleImage\"},\"datePublished\":\"2012-12-03T13:23:16+10:30\",\"dateModified\":\"2016-11-13T16:58:50+10:30\",\"inLanguage\":\"en-US\",\"commentCount\":5,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2012\\\/12\\\/how-to-unit-test-private-methods-in-php\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2012\\\/12\\\/how-to-unit-test-private-methods-in-php\\\/#webpage\"},\"articleSection\":\"Unit Testing, Web Development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2012\\\/12\\\/how-to-unit-test-private-methods-in-php\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/category\\\/web-development\\\/#listItem\",\"name\":\"Web Development\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/category\\\/web-development\\\/#listItem\",\"position\":2,\"name\":\"Web Development\",\"item\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/category\\\/web-development\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/category\\\/web-development\\\/unit-testing\\\/#listItem\",\"name\":\"Unit Testing\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/category\\\/web-development\\\/unit-testing\\\/#listItem\",\"position\":3,\"name\":\"Unit Testing\",\"item\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/category\\\/web-development\\\/unit-testing\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2012\\\/12\\\/how-to-unit-test-private-methods-in-php\\\/#listItem\",\"name\":\"Unit test private methods in PHP\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/category\\\/web-development\\\/#listItem\",\"name\":\"Web Development\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2012\\\/12\\\/how-to-unit-test-private-methods-in-php\\\/#listItem\",\"position\":4,\"name\":\"Unit test private methods in PHP\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/category\\\/web-development\\\/unit-testing\\\/#listItem\",\"name\":\"Unit Testing\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/#person\",\"name\":\"Nathan Kowald\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2012\\\/12\\\/how-to-unit-test-private-methods-in-php\\\/#personImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/854acd146177108a75d95bc5fe67d244ccd1cd444eb62abe806923d3113f4319?s=96&d=mm&r=pg\",\"width\":96,\"height\":96,\"caption\":\"Nathan Kowald\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/author\\\/ozymandias\\\/#author\",\"url\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/author\\\/ozymandias\\\/\",\"name\":\"Nathan Kowald\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2012\\\/12\\\/how-to-unit-test-private-methods-in-php\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/854acd146177108a75d95bc5fe67d244ccd1cd444eb62abe806923d3113f4319?s=96&d=mm&r=pg\",\"width\":96,\"height\":96,\"caption\":\"Nathan Kowald\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2012\\\/12\\\/how-to-unit-test-private-methods-in-php\\\/#webpage\",\"url\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2012\\\/12\\\/how-to-unit-test-private-methods-in-php\\\/\",\"name\":\"Unit test private methods in PHP \\u2014 Nathan's Blog\",\"description\":\"You can test private and protected methods by using the ReflectionMethod class, part of the Reflection API that comes with PHP 5.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/2012\\\/12\\\/how-to-unit-test-private-methods-in-php\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/author\\\/ozymandias\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/author\\\/ozymandias\\\/#author\"},\"datePublished\":\"2012-12-03T13:23:16+10:30\",\"dateModified\":\"2016-11-13T16:58:50+10:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/\",\"name\":\"Nathan's Blog\",\"description\":\"Web development and useful information\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.nathankowald.com\\\/blog\\\/#person\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Unit test private methods in PHP \u2014 Nathan's Blog","description":"You can test private and protected methods by using the ReflectionMethod class, part of the Reflection API that comes with PHP 5.","canonical_url":"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/","robots":"noarchive, max-snippet:-1, max-image-preview:large, max-video-preview:-1","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/#article","name":"Unit test private methods in PHP \u2014 Nathan's Blog","headline":"Unit test private methods in PHP","author":{"@id":"https:\/\/www.nathankowald.com\/blog\/author\/ozymandias\/#author"},"publisher":{"@id":"https:\/\/www.nathankowald.com\/blog\/#person"},"image":{"@type":"ImageObject","url":"http:\/\/www.nathankowald.com\/blog\/wp-content\/uploads\/2012\/12\/failed-test-1024x171.png","@id":"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/#articleImage"},"datePublished":"2012-12-03T13:23:16+10:30","dateModified":"2016-11-13T16:58:50+10:30","inLanguage":"en-US","commentCount":5,"mainEntityOfPage":{"@id":"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/#webpage"},"isPartOf":{"@id":"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/#webpage"},"articleSection":"Unit Testing, Web Development"},{"@type":"BreadcrumbList","@id":"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.nathankowald.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/#listItem","name":"Web Development"}},{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/#listItem","position":2,"name":"Web Development","item":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/unit-testing\/#listItem","name":"Unit Testing"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/unit-testing\/#listItem","position":3,"name":"Unit Testing","item":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/unit-testing\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/#listItem","name":"Unit test private methods in PHP"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/#listItem","name":"Web Development"}},{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/#listItem","position":4,"name":"Unit test private methods in PHP","previousItem":{"@type":"ListItem","@id":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/unit-testing\/#listItem","name":"Unit Testing"}}]},{"@type":"Person","@id":"https:\/\/www.nathankowald.com\/blog\/#person","name":"Nathan Kowald","image":{"@type":"ImageObject","@id":"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/#personImage","url":"https:\/\/secure.gravatar.com\/avatar\/854acd146177108a75d95bc5fe67d244ccd1cd444eb62abe806923d3113f4319?s=96&d=mm&r=pg","width":96,"height":96,"caption":"Nathan Kowald"}},{"@type":"Person","@id":"https:\/\/www.nathankowald.com\/blog\/author\/ozymandias\/#author","url":"https:\/\/www.nathankowald.com\/blog\/author\/ozymandias\/","name":"Nathan Kowald","image":{"@type":"ImageObject","@id":"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/854acd146177108a75d95bc5fe67d244ccd1cd444eb62abe806923d3113f4319?s=96&d=mm&r=pg","width":96,"height":96,"caption":"Nathan Kowald"}},{"@type":"WebPage","@id":"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/#webpage","url":"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/","name":"Unit test private methods in PHP \u2014 Nathan's Blog","description":"You can test private and protected methods by using the ReflectionMethod class, part of the Reflection API that comes with PHP 5.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.nathankowald.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/#breadcrumblist"},"author":{"@id":"https:\/\/www.nathankowald.com\/blog\/author\/ozymandias\/#author"},"creator":{"@id":"https:\/\/www.nathankowald.com\/blog\/author\/ozymandias\/#author"},"datePublished":"2012-12-03T13:23:16+10:30","dateModified":"2016-11-13T16:58:50+10:30"},{"@type":"WebSite","@id":"https:\/\/www.nathankowald.com\/blog\/#website","url":"https:\/\/www.nathankowald.com\/blog\/","name":"Nathan's Blog","description":"Web development and useful information","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.nathankowald.com\/blog\/#person"}}]},"og:locale":"en_US","og:site_name":"Nathan's Blog | Web development and useful information","og:type":"article","og:title":"Unit test private methods in PHP \u2014 Nathan's Blog","og:description":"You can test private and protected methods by using the ReflectionMethod class, part of the Reflection API that comes with PHP 5.","og:url":"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/","article:published_time":"2012-12-03T13:23:16+00:00","article:modified_time":"2016-11-13T16:58:50+00:00","twitter:card":"summary","twitter:title":"Unit test private methods in PHP \u2014 Nathan's Blog","twitter:description":"You can test private and protected methods by using the ReflectionMethod class, part of the Reflection API that comes with PHP 5."},"aioseo_meta_data":{"post_id":"807","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2020-12-20 21:50:51","updated":"2025-09-13 06:09:41","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.nathankowald.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/\" title=\"Web Development\">Web Development<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/unit-testing\/\" title=\"Unit Testing\">Unit Testing<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tUnit test private methods in PHP\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.nathankowald.com\/blog"},{"label":"Web Development","link":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/"},{"label":"Unit Testing","link":"https:\/\/www.nathankowald.com\/blog\/category\/web-development\/unit-testing\/"},{"label":"Unit test private methods in PHP","link":"https:\/\/www.nathankowald.com\/blog\/2012\/12\/how-to-unit-test-private-methods-in-php\/"}],"_links":{"self":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts\/807","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/comments?post=807"}],"version-history":[{"count":116,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts\/807\/revisions"}],"predecessor-version":[{"id":1770,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts\/807\/revisions\/1770"}],"wp:attachment":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/media?parent=807"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/categories?post=807"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/tags?post=807"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}