File tree Expand file tree Collapse file tree 4 files changed +84
-10
lines changed
testData/actions/generation/generator
generateDataModelWithoutInterface
DataModelInterfaceGenerator/generateDataModelInterface
tests/com/magento/idea/magento2plugin/actions/generation/generator Expand file tree Collapse file tree 4 files changed +84
-10
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
+ declare (strict_types=1 );
2
3
3
4
namespace Foo \Bar \Model \Data ;
4
5
@@ -10,16 +11,17 @@ class Sample extends DataObject implements SampleInterface
10
11
/**
11
12
* @inheritDoc
12
13
*/
13
- public function getSampleProperty ()
14
+ public function getSampleProperty (): ? string
14
15
{
15
- return $ this ->getData (self ::SAMPLE_PROPERTY );
16
+ return $ this ->getData (self ::SAMPLE_PROPERTY ) === null ? null
17
+ : (string )$ this ->getData (self ::SAMPLE_PROPERTY );
16
18
}
17
19
18
20
/**
19
21
* @inheritDoc
20
22
*/
21
- public function setSampleProperty ($ sampleProperty )
23
+ public function setSampleProperty (? string $ sampleProperty ): void
22
24
{
23
- return $ this ->setData (self ::SAMPLE_PROPERTY , $ sampleProperty );
25
+ $ this ->setData (self ::SAMPLE_PROPERTY , $ sampleProperty );
24
26
}
25
27
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+ declare (strict_types=1 );
3
+
4
+ namespace Foo \Bar \Model \Data ;
5
+
6
+ use Magento \Framework \DataObject ;
7
+
8
+ class Sample extends DataObject
9
+ {
10
+ /**
11
+ * String constants for property names
12
+ */
13
+ const SAMPLE_PROPERTY = "sample_property " ;
14
+
15
+ /**
16
+ * Getter for SampleProperty.
17
+ *
18
+ * @return string|null
19
+ */
20
+ public function getSampleProperty (): ?string
21
+ {
22
+ return $ this ->getData (self ::SAMPLE_PROPERTY ) === null ? null
23
+ : (string )$ this ->getData (self ::SAMPLE_PROPERTY );
24
+ }
25
+
26
+ /**
27
+ * Setter for SampleProperty.
28
+ *
29
+ * @param string|null $sampleProperty
30
+ *
31
+ * @return void
32
+ */
33
+ public function setSampleProperty (?string $ sampleProperty ): void
34
+ {
35
+ $ this ->setData (self ::SAMPLE_PROPERTY , $ sampleProperty );
36
+ }
37
+ }
Original file line number Diff line number Diff line change 1
1
<?php
2
+ declare (strict_types=1 );
2
3
3
4
namespace Foo \Bar \Api \Data ;
4
5
@@ -10,13 +11,18 @@ interface SampleInterface
10
11
const SAMPLE_PROPERTY = "sample_property " ;
11
12
12
13
/**
13
- * @return string
14
+ * Getter for SampleProperty.
15
+ *
16
+ * @return string|null
14
17
*/
15
- public function getSampleProperty ();
18
+ public function getSampleProperty (): ? string ;
16
19
17
20
/**
18
- * @param string $sampleProperty
19
- * @return $this
21
+ * Setter for SampleProperty.
22
+ *
23
+ * @param string|null $sampleProperty
24
+ *
25
+ * @return void
20
26
*/
21
- public function setSampleProperty ($ sampleProperty );
27
+ public function setSampleProperty (? string $ sampleProperty ): void ;
22
28
}
Original file line number Diff line number Diff line change @@ -22,7 +22,36 @@ public void testGenerateDataModel() {
22
22
"Foo_Bar" ,
23
23
"Foo\\ Bar\\ Model\\ Data\\ Sample" ,
24
24
"Foo\\ Bar\\ Api\\ Data\\ SampleInterface" ,
25
- "SAMPLE_PROPERTY;sample_property;string;SampleProperty;sampleProperty"
25
+ "SAMPLE_PROPERTY;sample_property;string;SampleProperty;sampleProperty" ,
26
+ true
27
+ );
28
+ final DataModelGenerator generator = new DataModelGenerator (
29
+ project , modelData
30
+ );
31
+ final PsiFile modelFile = generator .generate (NewDataModelAction .ACTION_NAME );
32
+ final PsiFile expectedFile
33
+ = myFixture .configureByFile (this .getFixturePath ("Sample.php" ));
34
+
35
+ assertGeneratedFileIsCorrect (
36
+ expectedFile ,
37
+ "src/app/code/Foo/Bar/Model/Data" ,
38
+ modelFile
39
+ );
40
+ }
41
+
42
+ /**
43
+ * Tests for generation of a Magento 2 Data Model without interface.
44
+ */
45
+ public void testGenerateDataModelWithoutInterface () {
46
+ final Project project = myFixture .getProject ();
47
+ final DataModelData modelData = new DataModelData (
48
+ "Foo\\ Bar\\ Model\\ Data" ,
49
+ "Sample" ,
50
+ "Foo_Bar" ,
51
+ "Foo\\ Bar\\ Model\\ Data\\ Sample" ,
52
+ "Foo\\ Bar\\ Api\\ Data\\ SampleInterface" ,
53
+ "SAMPLE_PROPERTY;sample_property;string;SampleProperty;sampleProperty" ,
54
+ false
26
55
);
27
56
final DataModelGenerator generator = new DataModelGenerator (
28
57
project , modelData
You can’t perform that action at this time.
0 commit comments