ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
LazyProvideTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use PHPUnit\Framework\TestCase;
26use PHPUnit\Framework\Attributes\DataProvider;
27
28require_once __DIR__ . '/ContainerMock.php';
29
30class LazyProvideTest extends TestCase
31{
32 use ContainerMock;
33
34 public function testConstruct(): void
35 {
36 $this->assertInstanceOf(LazyProvide::class, new LazyProvide($this->fail(...)));
37 }
38
39 #[DataProvider('methods')]
40 public function testMethods(string $method, $return = []): void
41 {
42 $called = false;
43 $provide = $this->mockTree(Provide::class, [$method => $return]);
44
45 $create = function () use (&$called, $provide) {
46 $called = true;
47 return $provide;
48 };
49
50 $instance = new LazyProvide($create);
51 $this->assertFalse($called);
52 $this->assertSame($provide->$method(), $instance->$method());
53 $this->assertTrue($called);
54 }
55
56 public static function methods(): array
57 {
58 return [
59 ['withdrawal'],
60 ['publicPage'],
61 ['document'],
62 ['history'],
63 ['allowEditing'],
64 ['publicApi'],
65 ['id', ''],
66 ];
67 }
68}
testMethods(string $method, $return=[])