Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php unit test

//Example Testing array operations with PHPUnit¶
<?php declare(strict_types=1);
use PHPUnitFrameworkTestCase;

final class StackTest extends TestCase
{
    public function testPushAndPop(): void
    {
        $stack = [];
        $this->assertSame(0, count($stack));

        array_push($stack, 'foo');
        $this->assertSame('foo', $stack[count($stack)-1]);
        $this->assertSame(1, count($stack));

        $this->assertSame('foo', array_pop($stack));
        $this->assertSame(0, count($stack));
    }
}
 
PREVIOUS NEXT
Tagged: #php #unit #test
ADD COMMENT
Topic
Name
9+2 =