PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

PHPUnit 3.5: Less $this Required

Note: This article was originally published at Planet PHP on 16 August 2010.
Planet PHP

Over the years, I have gotten quite a few "complaints" from PHPUnit users that they do not like typing $this- as often as they have to:


classAStackTestAextendsAPHPUnit_Framework_TestCase
{
AAAApublicAfunctionAtestPushAndPop()
AAAA{
AAAAAAAA$stackA=Aarray();
AAAAAAAA$this-assertEquals(0,Acount($stack));
A
AAAAAAAAarray_push($stack,A'foo');
AAAAAAAA$this-assertEquals('foo',A$stack[count($stack)-1]);
AAAAAAAA$this-assertEquals(1,Acount($stack));
A
AAAAAAAA$this-assertEquals('foo',Aarray_pop($stack));
AAAAAAAA$this-assertEquals(0,Acount($stack));
AAAA}
}
?

As of PHPUnit 3.5, they can write test code that requires less $this- statements:


require_onceA'PHPUnit/Framework/Assert/Functions.php';
A
classA

Truncated by Planet PHP, read more at the original (another 3943 bytes)