PHPUnit Annotations

Other
An annotation is a special form of syntactic metadata that can be added to the source code of some programming languages. While PHP has no dedicated language feature for annotating source code, the usage of tags such as @annotation arguments in documentation block has been established in the PHP community to annotate source code.
With PHPUnit annotations you can write PHPUnit tests in a simle and unconventional way.
For example:
@test
    /**
     *@test
     */
    public function checkPoints()
    {
        $this->assertEquals(0, $this->getPoints());
    }
@test it tells to PHPUnit that function checkPoints is a test and is an alternative to prefixing your test method.

@assert
    /**
     * @assert (0, 0) == 0
     */
    public function add($a, $b)
    {
        return $a + $b;
    }
For function bellow PHPUnit automatically generates a test function such as:
    /**
     * Generated from @assert (0, 0) == 0.
     */
    public function testAdd() {
        $o = new Calculator;
        $this->assertEquals(0, $o->add(0, 0));
    }
Complete list supported by PHPUnit 3.6 is:
@assert
@author
@backupGlobals
@backupStaticAttributes
@codeCoverageIgnore*
@covers
@dataProvider
@depends
@expectedException
@expectedExceptionCode
@expectedExceptionMessage
@group
@outputBuffering
@runTestsInSeparateProcesses
@runInSeparateProcess
@test
@testdox
@ticket
Add comment
 
 
 

Comments