I agree with "yegor256" when testing the contract. However, there are times when we have arguments that are optional for using previously declared values, but if they are not set, then we throw exceptions. Below is a small version of your code (a simple example, not good or ready for production).
class Foo { ... public function bar($arg = NULL) { if(is_null($arg) // Use internal setting, or ... { if( ! $this->GetDefault($arg)) // Use Internal argument { throw new InvalidArgumentException(); } } else { return $arg; } } } ... class FooTest extends PHPUnit_Framework_TestCase { /** * @expectedException InvalidArgumentException */ public function testBar() { $dummy = Foo::bar(); } public function testBarWithArg() { $this->assertEquals(1, Foo:bar(1)); } }
source share