ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
CollectionBuilderTest.php
Go to the documentation of this file.
1 <?php
2 
20 
32 
37 class CollectionBuilderTest extends TestCase
38 {
39  public const DUMMY_RCID = 'dummy-rcid';
48  private ResourceBuilder|MockObject $resource_builder;
50 
51  protected function setUp(): void
52  {
53  $this->collection_builder = new CollectionBuilder(
54  $this->collection_repo = $this->createMock(CollectionRepository::class),
55  new Subject(),
56  new DummyIDGenerator(self::DUMMY_RCID)
57  );
58  $this->collections = new Collections(
59  $this->resource_builder = $this->createMock(ResourceBuilder::class),
60  $this->collection_builder,
61  $this->createMock(RepositoryPreloader::class),
62  new Subject()
63  );
64  }
65 
66  public function testGetCollectionTwice(): void
67  {
68  $rcid = new ResourceCollectionIdentification(self::DUMMY_RCID);
69 
70  $this->collection_repo->expects($this->once())
71  ->method('existing')
72  ->with($rcid)
73  ->willReturn(
74  new ResourceCollection($rcid, -1, '')
75  );
76 
77  $this->collection_repo->expects($this->once())
78  ->method('getResourceIdStrings')
79  ->with($rcid)
80  ->willReturn(
81  $this->arrayAsGenerator([
82  'rid1',
83  'rid2',
84  'rid3'
85  ])
86  );
87 
88  $consecutive = [
89  new ResourceIdentification('rid1'),
90  new ResourceIdentification('rid2'),
91  new ResourceIdentification('rid3'),
92  new ResourceIdentification('rid1'),
93  new ResourceIdentification('rid2'),
94  new ResourceIdentification('rid3'),
95  ];
96  $this->resource_builder
97  ->expects($this->exactly(6))
98  ->method('has')
99  ->willReturnCallback(
100  function ($rid) use (&$consecutive): true {
101  $this->assertEquals(array_shift($consecutive), $rid);
102  return true;
103  }
104  );
105 
106  $collection = $this->collections->get($rcid, null);
107 
108  $this->assertInstanceOf(ResourceCollection::class, $collection);
109  $this->assertNotInstanceOf(MockObject::class, $collection);
110 
111  $this->assertEquals(3, $collection->count());
112 
113  $collection = $this->collections->get($rcid, null);
114 
115  $this->assertEquals(3, $collection->count());
116  }
117 
118  protected function arrayAsGenerator(array $array): \Generator
119  {
120  foreach ($array as $item) {
121  yield $item;
122  }
123  }
124 
125 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...