Switch back to dynamic getter methods because static methods cannot been mocked in tests

This commit is contained in:
Art4 2025-01-03 10:12:09 +00:00
parent 73a55e4700
commit 82470738e4
6 changed files with 39 additions and 11 deletions

View file

@ -10,12 +10,18 @@ declare(strict_types=1);
namespace Friendica\Test\Unit\Addon;
use Friendica\Addon\AddonBootstrap;
use Friendica\Addon\DependencyProvider;
use Friendica\Addon\Event\AddonStartEvent;
use Friendica\Service\Addon\Addon;
use Friendica\Service\Addon\AddonProxy;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
/**
* Helper interface to combine AddonBootstrap and DependencyProvider.
*/
interface CombinedAddonBootstrapDependencyProvider extends AddonBootstrap, DependencyProvider {}
class AddonProxyTest extends TestCase
{
public function testCreateWithAddonBootstrap(): void
@ -27,6 +33,26 @@ class AddonProxyTest extends TestCase
$this->assertInstanceOf(Addon::class, $addon);
}
public function testGetRequiredDependenciesCallsBootstrap(): void
{
$bootstrap = $this->createMock(AddonBootstrap::class);
$bootstrap->expects($this->once())->method('getRequiredDependencies')->willReturn([]);
$addon = new AddonProxy($bootstrap);
$addon->getRequiredDependencies();
}
public function testGetProvidedDependencyRulesCallsBootstrap(): void
{
$bootstrap = $this->createMock(CombinedAddonBootstrapDependencyProvider::class);
$bootstrap->expects($this->once())->method('provideDependencyRules')->willReturn([]);
$addon = new AddonProxy($bootstrap);
$addon->getProvidedDependencyRules();
}
public function testInitAddonCallsBootstrap(): void
{
$bootstrap = $this->createMock(AddonBootstrap::class);