<?php
use Laminas\Stdlib\ArrayUtils;
use PHPUnit\Framework\TestCase;
/**
* This class replaces the original ArrayUtils
*/
class StaticStub
{
public static function merge(array $array1, array $array2)
{
return [];
}
}
/**
* The class to test
*/
class Foo
{
public function mergeAndFoo($array1, $array2)
{
$merged = ArrayUtils::merge($array1, $array2);
$merged[] = 'foo';
return $merged;
}
}
class StaticTest extends TestCase
{
public function testMergeAndFoo() : void
{
// ArrayUtils is "replaced" by StaticStub
// This works only with classes from an autoloader
class_alias('StaticStub', 'Laminas\Stdlib\ArrayUtils');
$array1 = ['bar', 'baz'];
$array2 = [100, 200];
$foo = new Foo();
$actual = $foo->mergeAndFoo($array1, $array2);
$this->assertEquals(['foo'], $actual);
}
}