Answers.Body: <p>I think submitting a PR to make this variable protected would be perfectly reasonable.</p>
  
  <p>Alternatively, there is a way to <a href="http://php.net/manual/en/reflectionproperty.setaccessible.php" rel="nofollow noreferrer">access private properties in PHP</a> for the sake of unit testing via <a href="http://php.net/manual/en/book.reflection.php" rel="nofollow noreferrer">Reflection</a>. It's slightly cludgy but it does work.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-01T08:18:50.963Z
Answers.Text: mmm - hard to know which to prefer of those 2 methods - wasn't aware of reflection technique - it seems like a reasonable approach for unit testing where you're allowed to do naughty things with mocks?
Answers.UserDisplayName: ErichBSchulz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-01T15:59:12.473Z
Answers.Text: Yea but in this case I think making the variable protected really wouldn't hurt anything. Go ahead and submit the PR and save the Reflection in your back pocket, you'll probably find a use for it later.
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-02T02:12:25.170Z
Answers.Text: cool thanks for the advice! PR: [here](https://github.com/civicrm/civicrm-core/pull/9605)
Answers.UserDisplayName: ErichBSchulz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-01T03:44:35.703Z
Answers.LastActivityDate: 2017-01-01T03:44:35.703Z
Answers.UserDisplayName: Coleman
Body: <p>I'm looking at a class in CRM_Utils_Cache <a href="https://github.com/civicrm/civicrm-core/blob/fa938177202b0ef376e00b6cbe8be3814ef1cd28/CRM/Utils/Cache/ArrayCache.php#L42" rel="nofollow noreferrer">here specificly</a> and it looks exactly like what I need to write some unit tests against my extension.</p>
  
  <p>The issue is that the <code>$cache</code> array is <code>private</code> rather than <code>protected</code>...</p>
  
  <p>This means I can't extend this class into a test mock that allows my unit tests to manipulate and observe the cache state.</p>
  
  <p>For this reason I'm wonder if there is a downside to changing this (and maybe other) properties to <code>protected</code>?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-12-28T13:19:04.790Z
Comments.Text: I see there is a get() and set() public function to store and retrieve values in `_cache`.  Are you not able to use them ?
Comments.UserDisplayName: jitendra - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-12-28T22:18:54.487Z
Comments.Text: Not to count the cache entries or inspect without knowing what the key is @jitendrapurohit
Comments.UserDisplayName: ErichBSchulz
Tags: <unit-testing><coding-standards>
Title: private or protected class properties
ThreadText: # private or protected class properties
  
  (Asked by: username_0 on 2016-12-28)
  
  I'm looking at a class in CRM\_Utils\_Cache [here specificly](https://github.com/civicrm/civicrm-core/blob/fa938177202b0ef376e00b6cbe8be3814ef1cd28/CRM/Utils/Cache/ArrayCache.php#L42) and it looks exactly like what I need to write some unit tests against my extension.
  
  The issue is that the `$cache` array is `private` rather than `protected`...
  
  This means I can't extend this class into a test mock that allows my unit tests to manipulate and observe the cache state.
  
  For this reason I'm wonder if there is a downside to changing this (and maybe other) properties to `protected`?
  
  **Tags:** unit-testing, coding-standards
  
  > **Comments:**
  > **username_1**: I see there is a get() and set() public function to store and retrieve values in `_cache`.  Are you not able to use them ?  
  > **username_0**: Not to count the cache entries or inspect without knowing what the key is @jitendrapurohit  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2017-01-01. Score: 3 | Accepted answer
  
  I think submitting a PR to make this variable protected would be perfectly reasonable.
  
  Alternatively, there is a way to [access private properties in PHP](http://php.net/manual/en/reflectionproperty.setaccessible.php) for the sake of unit testing via [Reflection](http://php.net/manual/en/book.reflection.php). It's slightly cludgy but it does work.
  
  > **Comments:**
  > **username_0**: mmm - hard to know which to prefer of those 2 methods - wasn't aware of reflection technique - it seems like a reasonable approach for unit testing where you're allowed to do naughty things with mocks?  
  > **username_2**: Yea but in this case I think making the variable protected really wouldn't hurt anything. Go ahead and submit the PR and save the Reflection in your back pocket, you'll probably find a use for it later.  
  > **username_0**: cool thanks for the advice! PR: [here](https://github.com/civicrm/civicrm-core/pull/9605)  
  
  ---
  
  