File tree Expand file tree Collapse file tree 4 files changed +82
-4
lines changed
src/com/magento/idea/magento2plugin/actions/generation/generator
testData/actions/generation/generator/CronjobClassGenerator/generateFile
tests/com/magento/idea/magento2plugin/actions/generation/generator Expand file tree Collapse file tree 4 files changed +82
-4
lines changed Original file line number Diff line number Diff line change 8
8
import com .intellij .psi .PsiDirectory ;
9
9
import com .intellij .psi .PsiFile ;
10
10
import com .jetbrains .php .lang .psi .PhpFile ;
11
- import com .jetbrains .php .lang .psi .elements .PhpClass ;
12
11
import com .magento .idea .magento2plugin .actions .generation .data .CronjobClassData ;
13
12
import com .magento .idea .magento2plugin .actions .generation .generator .util .DirectoryGenerator ;
14
13
import com .magento .idea .magento2plugin .actions .generation .generator .util .FileFromTemplateGenerator ;
15
14
import com .magento .idea .magento2plugin .bundles .ValidatorBundle ;
16
15
import com .magento .idea .magento2plugin .indexes .ModuleIndex ;
17
16
import com .magento .idea .magento2plugin .magento .files .CronjobTemplate ;
18
- import com .magento .idea .magento2plugin .util .GetPhpClassByFQN ;
19
17
import org .jetbrains .annotations .NotNull ;
20
-
21
- import javax .swing .*;
22
18
import java .io .File ;
23
19
import java .util .Properties ;
24
20
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+
4
+ namespace Foo \Bar \Cron ;
5
+
6
+
7
+ class CleanTableCronjob
8
+ {
9
+ /**
10
+ * Cronjob Description
11
+ *
12
+ * @return void
13
+ */
14
+ public function execute (): void
15
+ {
16
+ // todo: implement cronjob logic here
17
+ }
18
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright © Magento, Inc. All rights reserved.
3
+ * See COPYING.txt for license details.
4
+ */
5
+ package com .magento .idea .magento2plugin .actions .generation .generator ;
6
+
7
+ import com .intellij .psi .PsiFile ;
8
+ import com .jetbrains .php .lang .psi .PhpFile ;
9
+ import com .magento .idea .magento2plugin .BaseProjectTestCase ;
10
+ import java .io .File ;
11
+
12
+ abstract public class BaseGeneratorTestCase extends BaseProjectTestCase {
13
+ private static final String testDataFolderPath = "testData" + File .separator + "actions" + File .separator ;
14
+ private static final String fixturesFolderPath = "generation" + File .separator + "generator" + File .separator ;
15
+
16
+ @ Override
17
+ protected void setUp () throws Exception {
18
+ super .setUp ();
19
+ myFixture .setTestDataPath (testDataFolderPath );
20
+ }
21
+
22
+ protected String getFixturePath (String fileName ) {
23
+ return prepareFixturePath (fileName , fixturesFolderPath );
24
+ }
25
+
26
+ protected void assertGeneratedFileIsCorrect (
27
+ PsiFile expectedFile ,
28
+ String expectedDirectory ,
29
+ PsiFile resultFile ) {
30
+
31
+ assertEquals (expectedDirectory , resultFile .getContainingDirectory ().getVirtualFile ().getPresentableUrl ());
32
+ assertEquals (expectedFile .getText (), resultFile .getText ());
33
+ assertEquals (expectedFile .getName (), resultFile .getName ());
34
+ }
35
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright © Magento, Inc. All rights reserved.
3
+ * See COPYING.txt for license details.
4
+ */
5
+ package com .magento .idea .magento2plugin .actions .generation .generator ;
6
+
7
+ import com .intellij .openapi .project .Project ;
8
+ import com .intellij .psi .PsiFile ;
9
+ import com .magento .idea .magento2plugin .actions .generation .data .CronjobClassData ;
10
+
11
+ public class CronjobClassGeneratorTest extends BaseGeneratorTestCase {
12
+
13
+ public void testGenerateFile () {
14
+ String filePath = this .getFixturePath ("CleanTableCronjob.php" );
15
+ PsiFile expectedFile = myFixture .configureByFile (filePath );
16
+
17
+ Project project = myFixture .getProject ();
18
+ CronjobClassData cronjobClassData = new CronjobClassData (
19
+ "CleanTableCronjob" ,
20
+ "Cron" ,
21
+ "Foo\\ Bar\\ Cron" ,
22
+ "Foo_Bar"
23
+ );
24
+ CronjobClassGenerator cronjobClassGenerator = new CronjobClassGenerator (project , cronjobClassData );
25
+ PsiFile cronJobFile = cronjobClassGenerator .generate ("test" );
26
+
27
+ assertGeneratedFileIsCorrect (expectedFile , "/src/app/code/Foo/Bar/Cron" , cronJobFile );
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments