<?php
use PHPUnit\Framework\TestCase;
class SplTest extends TestCase
{
public function testSplError() : void
{
// the following mock creation triggers an error
$spl = $this->getMockBuilder(SplFileInfo::CLASS)
->disableOriginalConstructor()
->getMock();
// this test doesn't work
$spl->expects($this->once())
->method('getFileName')
->will($this->returnValue('Foo.php'));
$this->assertEquals('Foo.php', $spl->getFileName());
}
public function testSplWorks() : void
{
// Constructor gets a parameter for this mock
$spl = $this->getMockBuilder(SplFileInfo::CLASS)
->setConstructorArgs([__DIR__])
->getMock();
$spl->expects($this->once())
->method('getFileName')
->will($this->returnValue('Foo.php'));
$this->assertEquals('Foo.php', $spl->getFileName());
}
}