Skip to main content
added 1 characters in body
Source Link
k.m
  • 31.6k
  • 10
  • 64
  • 87

I just want to point out one thing. Let's forget about private fields for a moment and focus on what client of your class cares about. Your class exposes a contract, in this case - ability to alter and retrieve name (via getter and setter). Expected functionality is simple:

  • when I set name with setName to "Gerald", I expect to get "Gerald" when I call getName

That's all. Client won't (well, shouldn't!) care about internal implementation. Whether you used private field name, hashset or called web service via dynamically generated code - doesn't matter for client. The bug you are currently experiencing, from user point of view - is not a bug at all.

Whether PHPUnit allows you to test private variables - I don't know. But from unit-testing perspective, you shouldn't do that.

Edit (in response to comment):

I understand your concerns about possible exposure of internal state, however I don't think unit testing is the right tool to deal with that. You can come up with a lot of possible scenarios how something might do something else which wasn't planned. Unit tests are by no means cure for all and shouldn't be useused as such.

I just want to point out one thing. Let's forget about private fields for a moment and focus on what client of your class cares about. Your class exposes a contract, in this case - ability to alter and retrieve name (via getter and setter). Expected functionality is simple:

  • when I set name with setName to "Gerald", I expect to get "Gerald" when I call getName

That's all. Client won't (well, shouldn't!) care about internal implementation. Whether you used private field name, hashset or called web service via dynamically generated code - doesn't matter for client. The bug you are currently experiencing, from user point of view - is not a bug at all.

Whether PHPUnit allows you to test private variables - I don't know. But from unit-testing perspective, you shouldn't do that.

Edit (in response to comment):

I understand your concerns about possible exposure of internal state, however I don't think unit testing is the right tool to deal with that. You can come up with a lot of possible scenarios how something might do something else which wasn't planned. Unit tests are by no means cure for all and shouldn't be use as such.

I just want to point out one thing. Let's forget about private fields for a moment and focus on what client of your class cares about. Your class exposes a contract, in this case - ability to alter and retrieve name (via getter and setter). Expected functionality is simple:

  • when I set name with setName to "Gerald", I expect to get "Gerald" when I call getName

That's all. Client won't (well, shouldn't!) care about internal implementation. Whether you used private field name, hashset or called web service via dynamically generated code - doesn't matter for client. The bug you are currently experiencing, from user point of view - is not a bug at all.

Whether PHPUnit allows you to test private variables - I don't know. But from unit-testing perspective, you shouldn't do that.

Edit (in response to comment):

I understand your concerns about possible exposure of internal state, however I don't think unit testing is the right tool to deal with that. You can come up with a lot of possible scenarios how something might do something else which wasn't planned. Unit tests are by no means cure for all and shouldn't be used as such.

added 366 characters in body
Source Link
k.m
  • 31.6k
  • 10
  • 64
  • 87

I just want to point out one thing. Let's forget about private fields for a moment and focus on what client of your class cares about. Your class exposes a contract, in this case - ability to alter and retrieve name (via getter and setter). Expected functionality is simple:

  • when I set name with setName to "Gerald", I expect to get "Gerald" when I call getName

That's all. Client won't (well, shouldn't!) care about internal implementation. Whether you used private field name, hashset or called web service via dynamically generated code - doesn't matter for client. The bug you are currently experiencing, from user point of view - is not a bug at all.

Whether PHPUnit allows you to test private variables - I don't know. But from unit-testing perspective, you shouldn't do that.

Edit (in response to comment):

I understand your concerns about possible exposure of internal state, however I don't think unit testing is the right tool to deal with that. You can come up with a lot of possible scenarios how something might do something else which wasn't planned. Unit tests are by no means cure for all and shouldn't be use as such.

I just want to point out one thing. Let's forget about private fields for a moment and focus on what client of your class cares about. Your class exposes a contract, in this case - ability to alter and retrieve name (via getter and setter). Expected functionality is simple:

  • when I set name with setName to "Gerald", I expect to get "Gerald" when I call getName

That's all. Client won't (well, shouldn't!) care about internal implementation. Whether you used private field name, hashset or called web service via dynamically generated code - doesn't matter for client. The bug you are currently experiencing, from user point of view - is not a bug at all.

Whether PHPUnit allows you to test private variables - I don't know. But from unit-testing perspective, you shouldn't do that.

I just want to point out one thing. Let's forget about private fields for a moment and focus on what client of your class cares about. Your class exposes a contract, in this case - ability to alter and retrieve name (via getter and setter). Expected functionality is simple:

  • when I set name with setName to "Gerald", I expect to get "Gerald" when I call getName

That's all. Client won't (well, shouldn't!) care about internal implementation. Whether you used private field name, hashset or called web service via dynamically generated code - doesn't matter for client. The bug you are currently experiencing, from user point of view - is not a bug at all.

Whether PHPUnit allows you to test private variables - I don't know. But from unit-testing perspective, you shouldn't do that.

Edit (in response to comment):

I understand your concerns about possible exposure of internal state, however I don't think unit testing is the right tool to deal with that. You can come up with a lot of possible scenarios how something might do something else which wasn't planned. Unit tests are by no means cure for all and shouldn't be use as such.

Source Link
k.m
  • 31.6k
  • 10
  • 64
  • 87

I just want to point out one thing. Let's forget about private fields for a moment and focus on what client of your class cares about. Your class exposes a contract, in this case - ability to alter and retrieve name (via getter and setter). Expected functionality is simple:

  • when I set name with setName to "Gerald", I expect to get "Gerald" when I call getName

That's all. Client won't (well, shouldn't!) care about internal implementation. Whether you used private field name, hashset or called web service via dynamically generated code - doesn't matter for client. The bug you are currently experiencing, from user point of view - is not a bug at all.

Whether PHPUnit allows you to test private variables - I don't know. But from unit-testing perspective, you shouldn't do that.