ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
LazyProvideTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 
28 require_once __DIR__ . '/ContainerMock.php';
29 
30 class 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=[])