-
-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathSymfonyConsoleRunAnythingProviderTest.kt
More file actions
131 lines (100 loc) · 4.6 KB
/
SymfonyConsoleRunAnythingProviderTest.kt
File metadata and controls
131 lines (100 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package fr.adrienbrault.idea.symfony2plugin.tests.runAnything
import com.intellij.ide.actions.runAnything.items.RunAnythingItemBase
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.impl.SimpleDataContext
import com.intellij.testFramework.DumbModeTestUtils
import fr.adrienbrault.idea.symfony2plugin.runAnything.SymfonyConsoleRunAnythingProvider
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase
import fr.adrienbrault.idea.symfony2plugin.util.dict.SymfonyCommand
/**
* @see SymfonyConsoleRunAnythingProvider
*/
class SymfonyConsoleRunAnythingProviderTest : SymfonyLightCodeInsightFixtureTestCase() {
private val provider = SymfonyConsoleRunAnythingProvider()
override fun setUp() {
super.setUp()
myFixture.copyFileToProject("classes.php")
myFixture.addFileToProject(
"src/Command/CacheClearCommand.php",
"""
<?php
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
#[AsCommand(name: 'cache:clear')]
class CacheClearCommand extends Command {}
""".trimIndent()
)
myFixture.addFileToProject(
"src/Command/AppCreateUserCommand.php",
"""
<?php
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
#[AsCommand(name: 'app:create-user')]
class AppCreateUserCommand extends Command {}
""".trimIndent()
)
}
override fun getTestDataPath() =
"src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/dic/command/fixtures"
// --- getValues ---
fun testGetValuesReturnsMatchingCommandsByPrefix() {
val values = provider.getValues(createDataContext(), "cache")
assertTrue(values.isNotEmpty())
assertTrue(values.any { it.name == "cache:clear" })
}
fun testGetValuesEmptyPatternReturnsAllCommands() {
val values = provider.getValues(createDataContext(), "")
assertTrue(values.size >= 2)
}
fun testGetValuesNonMatchingPatternReturnsEmpty() {
val values = provider.getValues(createDataContext(), "nonexistent:xyz:command")
assertTrue(values.isEmpty())
}
fun testGetValuesCaseInsensitiveMatch() {
val values = provider.getValues(createDataContext(), "CACHE")
assertTrue(values.any { it.name == "cache:clear" })
}
fun testGetValuesInvalidatesOnPhpModification() {
val before = provider.getValues(createDataContext(), "app:after-cache").map { it.name }
assertFalse("app:after-cache should not exist before adding the PHP file", "app:after-cache" in before)
myFixture.addFileToProject(
"src/Command/AfterCacheCommand.php",
"""
<?php
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
#[AsCommand(name: 'app:after-cache')]
class AfterCacheCommand extends Command {}
""".trimIndent()
)
val after = provider.getValues(createDataContext(), "app:after-cache").map { it.name }
assertTrue("app:after-cache should be collected after the PHP modification", "app:after-cache" in after)
}
fun testGetValuesReturnsEmptyInDumbMode() {
DumbModeTestUtils.runInDumbModeSynchronously(project) {
val values = provider.getValues(createDataContext(), "cache")
assertTrue(values.isEmpty())
}
}
// --- getMainListItem ---
fun testGetMainListItemDescriptionIsShortClassName() {
val cmd = SymfonyCommand("cache:clear", "\\App\\Command\\CacheClearCommand")
val item = provider.getMainListItem(createDataContext(), cmd) as RunAnythingItemBase
assertEquals("CacheClearCommand", item.description)
}
fun testGetMainListItemDescriptionForRootClass() {
val cmd = SymfonyCommand("list", "\\ListCommand")
val item = provider.getMainListItem(createDataContext(), cmd) as RunAnythingItemBase
assertEquals("ListCommand", item.description)
}
fun testGetMainListItemCommand() {
val cmd = SymfonyCommand("cache:clear", "\\App\\Command\\CacheClearCommand")
val item = provider.getMainListItem(createDataContext(), cmd) as RunAnythingItemBase
assertEquals("cache:clear", item.command)
}
// --- helpers ---
private fun createDataContext() = SimpleDataContext.builder()
.add(CommonDataKeys.PROJECT, project)
.build()
}