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 11<?php
2+ declare (strict_types=1 );
23
34namespace Foo \Bar \Model \Data ;
45
@@ -10,16 +11,17 @@ class Sample extends DataObject implements SampleInterface
1011 /**
1112 * @inheritDoc
1213 */
13- public function getSampleProperty ()
14+ public function getSampleProperty (): ? string
1415 {
15- return $ this ->getData (self ::SAMPLE_PROPERTY );
16+ return $ this ->getData (self ::SAMPLE_PROPERTY ) === null ? null
17+ : (string )$ this ->getData (self ::SAMPLE_PROPERTY );
1618 }
1719
1820 /**
1921 * @inheritDoc
2022 */
21- public function setSampleProperty ($ sampleProperty )
23+ public function setSampleProperty (? string $ sampleProperty ): void
2224 {
23- return $ this ->setData (self ::SAMPLE_PROPERTY , $ sampleProperty );
25+ $ this ->setData (self ::SAMPLE_PROPERTY , $ sampleProperty );
2426 }
2527}
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 11<?php
2+ declare (strict_types=1 );
23
34namespace Foo \Bar \Api \Data ;
45
@@ -10,13 +11,18 @@ interface SampleInterface
1011 const SAMPLE_PROPERTY = "sample_property " ;
1112
1213 /**
13- * @return string
14+ * Getter for SampleProperty.
15+ *
16+ * @return string|null
1417 */
15- public function getSampleProperty ();
18+ public function getSampleProperty (): ? string ;
1619
1720 /**
18- * @param string $sampleProperty
19- * @return $this
21+ * Setter for SampleProperty.
22+ *
23+ * @param string|null $sampleProperty
24+ *
25+ * @return void
2026 */
21- public function setSampleProperty ($ sampleProperty );
27+ public function setSampleProperty (? string $ sampleProperty ): void ;
2228}
Original file line number Diff line number Diff line change @@ -22,7 +22,36 @@ public void testGenerateDataModel() {
2222 "Foo_Bar" ,
2323 "Foo\\ Bar\\ Model\\ Data\\ Sample" ,
2424 "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
2655 );
2756 final DataModelGenerator generator = new DataModelGenerator (
2857 project , modelData
You can’t perform that action at this time.
0 commit comments