Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing reflection in PHPUnit
    text
    copied!<p>I'm testing a private method of a class used in Symfony2 project with PHPUnit. I'm using the private methods testing strategy (through reflection) described by many developers such as <a href="http://aaronsaray.com/blog/2011/08/16/testing-protected-and-private-attributes-and-methods-using-phpunit/" rel="nofollow">http://aaronsaray.com/blog/2011/08/16/testing-protected-and-private-attributes-and-methods-using-phpunit/</a></p> <p>But unfortunately, I got the following error:</p> <blockquote> <p>There was 1 error: 1) My\CalendarBundle\Tests\Calendar\CalendarTest::testCalculateDaysPreviousMonth ReflectionException: Class Calendar does not exist /Library/WebServer/Documents/calendar/src/My/CalendarBundle/Tests/Calendar/CalendarTest.php:47</p> </blockquote> <pre><code>&lt;?php namespace My\CalendarBundle\Tests\Calendar; use My\CalendarBundle\Calendar\Calendar; class CalendarTest { //this method works fine public function testGetNextYear() { $this-&gt;calendar = new Calendar('12', '2012', $this-&gt;get('translator')); $result = $this-&gt;calendar-&gt;getNextYear(); $this-&gt;assertEquals(2013, $result); } public function testCalculateDaysPreviousMonth() { $reflectionCalendar = new \ReflectionClass('Calendar'); //this is the line $method = $reflectionCalendar-&gt;getMethod('calculateDaysPreviousMonth'); $method-&gt;setAccessible(true); $this-&gt;assertEquals(5, $method-&gt;invokeArgs($this-&gt;calendar, array())); } } </code></pre> <p>Why?</p> <p>Thank you in advance</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload