Skip to content

Commit 1e25d95

Browse files
committed
chore: phpstan errors
1 parent 9c9ca72 commit 1e25d95

3 files changed

Lines changed: 94 additions & 0 deletions

File tree

tests/Unit/DependencyInjection/IbexaAutomaticMigrationsExtensionTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,23 @@
3535
$registeredPath = key($paths);
3636
expect(str_contains($registeredPath, 'Resources/views'))->toBeTrue();
3737
});
38+
39+
it('load sets ibexa_automatic_migrations parameters', function () {
40+
$container = new ContainerBuilder();
41+
$ext = new IbexaAutomaticMigrationsExtension();
42+
43+
$ext->load([[]], $container);
44+
45+
expect($container->hasParameter('ibexa_automatic_migrations.enabled'))->toBeTrue();
46+
expect($container->hasParameter('ibexa_automatic_migrations.types'))->toBeTrue();
47+
});
48+
49+
it('load registers settings service in the container', function () {
50+
$container = new ContainerBuilder();
51+
$ext = new IbexaAutomaticMigrationsExtension();
52+
53+
$ext->load([[]], $container);
54+
55+
expect($container->hasDefinition('ibexa_automatic_migrations.settings_service'))->toBeTrue();
56+
});
3857
});

tests/Unit/EventSubscriber/MigrationsMenuSubscriberTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,31 @@
5757

5858
$subscriber->onMainMenuConfigure($event);
5959
});
60+
61+
it('onMainMenuConfigure adds menu item when permission is granted', function () {
62+
$permissionResolver = $this->createStub(PermissionResolver::class);
63+
$permissionResolver->method('hasAccess')->willReturn(true);
64+
65+
$addChildCallCount = 0;
66+
$childMenu = $this->createMock(ItemInterface::class);
67+
$childMenu->method('addChild')->willReturnCallback(function () use (&$addChildCallCount, &$childMenu) {
68+
$addChildCallCount++;
69+
return $childMenu;
70+
});
71+
72+
$menuFactory = $this->createStub(MenuItemFactory::class);
73+
$menuFactory->method('createItem')->willReturn($this->createStub(ItemInterface::class));
74+
75+
$subscriber = new MigrationsMenuSubscriber($menuFactory, $permissionResolver);
76+
77+
$menu = $this->createStub(ItemInterface::class);
78+
$menu->method('getChild')->willReturn($childMenu);
79+
80+
$factory = $this->createStub(\Knp\Menu\FactoryInterface::class);
81+
$event = new ConfigureMenuEvent($factory, $menu, []);
82+
83+
$subscriber->onMainMenuConfigure($event);
84+
85+
expect($addChildCallCount)->toBe(1);
86+
});
6087
});

tests/Unit/HelperTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,52 @@
294294
expect(substr_count($content, 'match_tolerate_misses:'))->toBe(1);
295295
expect($content)->toContain(' match_tolerate_misses: true');
296296
});
297+
298+
it('returns true when file cannot be read', function () {
299+
set_error_handler(fn () => true, E_WARNING);
300+
try {
301+
$result = Helper::fixKaliopMigrationYaml('/nonexistent_test_path_xyz/file.yml', new NullLogger());
302+
expect($result)->toBeTrue();
303+
} finally {
304+
restore_error_handler();
305+
}
306+
});
307+
308+
it('inserts field-settings at correct position when block ends with blank line and has no validator-configuration', function () {
309+
// The block collector includes trailing empty lines; the while loop on line 134
310+
// must back up past the trailing blank before splicing field-settings in.
311+
$yaml = "-\n type: content_type\n mode: create\n attributes:\n -\n identifier: title\n type: ibexa_string\n\n -\n identifier: body\n type: ibexa_richtext\n";
312+
file_put_contents($this->tmpFile, $yaml);
313+
314+
$result = Helper::fixKaliopMigrationYaml($this->tmpFile, new NullLogger());
315+
$content = file_get_contents($this->tmpFile);
316+
317+
expect($result)->toBeTrue();
318+
expect($content)->toContain(' field-settings: { }');
319+
});
320+
321+
it('inserts validator-configuration at correct position when ibexa_boolean block ends with blank line', function () {
322+
// Block has field-settings but no validator-configuration, and ends with a blank line;
323+
// the while loop on line 143 must back up past the trailing blank.
324+
$yaml = "-\n type: content_type\n mode: create\n attributes:\n -\n identifier: active\n type: ibexa_boolean\n field-settings: { }\n\n -\n identifier: body\n type: ibexa_richtext\n";
325+
file_put_contents($this->tmpFile, $yaml);
326+
327+
$result = Helper::fixKaliopMigrationYaml($this->tmpFile, new NullLogger());
328+
$content = file_get_contents($this->tmpFile);
329+
330+
expect($result)->toBeTrue();
331+
expect($content)->toContain(' validator-configuration: { }');
332+
});
333+
334+
it('inserts match_tolerate_misses before sibling key that follows match block', function () {
335+
// A non-8-space-indented key immediately after match: triggers the elseif branch (lines 205-207).
336+
$yaml = "-\n type: content_type\n mode: delete\n match:\n content_type_identifier: some_type\n";
337+
file_put_contents($this->tmpFile, $yaml);
338+
339+
$result = Helper::fixKaliopMigrationYaml($this->tmpFile, new NullLogger());
340+
$content = file_get_contents($this->tmpFile);
341+
342+
expect($result)->toBeTrue();
343+
expect($content)->toContain(' match_tolerate_misses: true');
344+
});
297345
});

0 commit comments

Comments
 (0)