Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 632a103

Browse files
Adjusted new entity dialog
1 parent a4dfdd4 commit 632a103

File tree

4 files changed

+159
-1
lines changed

4 files changed

+159
-1
lines changed

‎gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pluginVersion = 202520
55
pluginSinceBuild = 250.*
66
pluginUntilBuild = 258.*
77
platformType = PS
8-
platformVersion = 2025.1.3
8+
platformVersion = 2025.1.4.1
99
platformPlugins = com.intellij.lang.jsgraphql:251.26927.39,org.jetbrains.junie:251.204.104
1010
platformBundledPlugins = com.intellij.modules.json,com.jetbrains.php,JavaScript,com.intellij.copyright
1111
gradleVersion = 8.10.2

‎src/test/java/com/magento/idea/magento2plugin/BaseProjectTestCase.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.magento.idea.magento2plugin.indexes.IndexManager;
1313
import com.magento.idea.magento2plugin.magento.packages.File;
1414
import com.magento.idea.magento2plugin.project.Settings;
15+
import com.magento.idea.magento2plugin.util.PhpBundleMocker;
1516

1617
/**
1718
* Configure test environment with Magento 2 project.
@@ -28,6 +29,15 @@ public void setUp() throws Exception {
2829
super.setUp();
2930
copyMagento2ToTestProject();
3031
enablePluginAndReindex();
32+
33+
// Mock the PhpBundle to avoid issues with missing message keys
34+
try {
35+
PhpBundleMocker.mockPhpBundle();
36+
} catch (Exception e) {
37+
// Log the exception but continue with the test
38+
System.err.println("Failed to mock PhpBundle: " + e.getMessage());
39+
e.printStackTrace();
40+
}
3141
}
3242

3343
private void copyMagento2ToTestProject() {
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.util;
7+
8+
import java.io.IOException;
9+
import java.lang.reflect.Field;
10+
import java.lang.reflect.Method;
11+
import java.util.Locale;
12+
import java.util.Map;
13+
import java.util.ResourceBundle;
14+
import java.util.concurrent.ConcurrentHashMap;
15+
16+
/**
17+
* Utility class for mocking the PhpBundle in tests.
18+
*
19+
* This class provides methods to set up a mock for the PhpBundle,
20+
* which will return a fixed value for any key, avoiding the need for actual message keys in tests.
21+
*/
22+
public final class PhpBundleMocker {
23+
24+
private static final String PHP_BUNDLE_NAME = "messages.PhpBundle";
25+
private static final String DEFAULT_MOCK_VALUE = "mocked value";
26+
27+
private PhpBundleMocker() {
28+
// Private constructor to prevent instantiation
29+
}
30+
31+
/**
32+
* Set up a mock for the PhpBundle that returns a fixed value for any key.
33+
*
34+
* @param mockValue The value to return for any key
35+
* @throws Exception If an error occurs while setting up the mock
36+
*/
37+
public static void mockPhpBundle(final String mockValue) throws Exception {
38+
// Create a mock bundle
39+
final ResourceBundle mockBundle = new ResourceBundleMock(mockValue);
40+
41+
// Clear the ResourceBundle cache to ensure our mock is used
42+
clearResourceBundleCache();
43+
44+
// Install our custom ResourceBundle.Control that returns the mock bundle for PhpBundle
45+
ResourceBundle.getBundle(PHP_BUNDLE_NAME, new ResourceBundle.Control() {
46+
@Override
47+
public ResourceBundle newBundle(
48+
final String baseName,
49+
final Locale locale,
50+
final String format,
51+
final ClassLoader loader,
52+
final boolean reload
53+
) throws IllegalAccessException, InstantiationException, IOException {
54+
if (PHP_BUNDLE_NAME.equals(baseName)) {
55+
return mockBundle;
56+
}
57+
return super.newBundle(baseName, locale, format, loader, reload);
58+
}
59+
});
60+
}
61+
62+
/**
63+
* Set up a mock for the PhpBundle that returns "mocked value for [key]" for any key.
64+
*
65+
* @throws Exception If an error occurs while setting up the mock
66+
*/
67+
public static void mockPhpBundle() throws Exception {
68+
mockPhpBundle(DEFAULT_MOCK_VALUE);
69+
}
70+
71+
/**
72+
* Clear the ResourceBundle cache to ensure our mock is used.
73+
*
74+
* @throws Exception If an error occurs while clearing the cache
75+
*/
76+
private static void clearResourceBundleCache() throws Exception {
77+
try {
78+
// Get the cacheList field from ResourceBundle
79+
final Field cacheListField = ResourceBundle.class.getDeclaredField("cacheList");
80+
cacheListField.setAccessible(true);
81+
82+
// Get the cache map
83+
final Map<?, ?> cacheList = (Map<?, ?>) cacheListField.get(null);
84+
85+
// Clear the cache
86+
cacheList.clear();
87+
} catch (final NoSuchFieldException e) {
88+
// If cacheList field is not found, try the newer implementation (Java 9+)
89+
try {
90+
// Get the clearCache method
91+
final Method clearCacheMethod = ResourceBundle.class.getDeclaredMethod("clearCache");
92+
clearCacheMethod.setAccessible(true);
93+
94+
// Call the method to clear the cache
95+
clearCacheMethod.invoke(null);
96+
} catch (final NoSuchMethodException e2) {
97+
throw new Exception("Failed to clear ResourceBundle cache", e2);
98+
}
99+
}
100+
}
101+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.util;
7+
8+
import java.util.Collections;
9+
import java.util.Enumeration;
10+
import java.util.ResourceBundle;
11+
12+
/**
13+
* Mock implementation of ResourceBundle for testing.
14+
*
15+
* This class provides a dummy ResourceBundle that returns a fixed value for any key,
16+
* avoiding the need for actual message keys in tests.
17+
*/
18+
public class ResourceBundleMock extends ResourceBundle {
19+
20+
private final String defaultValue;
21+
22+
/**
23+
* Constructor with default value.
24+
*
25+
* @param defaultValue String value to return for any key
26+
*/
27+
public ResourceBundleMock(final String defaultValue) {
28+
this.defaultValue = defaultValue;
29+
}
30+
31+
/**
32+
* Default constructor that returns the key as the value.
33+
*/
34+
public ResourceBundleMock() {
35+
this.defaultValue = null;
36+
}
37+
38+
@Override
39+
protected Object handleGetObject(final String key) {
40+
return defaultValue != null ? defaultValue : "mocked value for " + key;
41+
}
42+
43+
@Override
44+
public Enumeration<String> getKeys() {
45+
return Collections.emptyEnumeration();
46+
}
47+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /