Skip to content

Commit b5d959e

Browse files
committed
Added test coverage
1 parent 3522311 commit b5d959e

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Foo\Bar\Model\Data;
4+
5+
use Foo\Bar\Api\Data\SampleInterface;
6+
use Magento\Framework\DataObject;
7+
8+
class Sample extends DataObject implements SampleInterface
9+
{
10+
/**
11+
* @inheritDoc
12+
*/
13+
public function getSampleProperty()
14+
{
15+
return $this->getData(self::SAMPLE_PROPERTY);
16+
}
17+
18+
/**
19+
* @inheritDoc
20+
*/
21+
public function setSampleProperty($sampleProperty)
22+
{
23+
return $this->setData(self::SAMPLE_PROPERTY, $sampleProperty);
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Foo\Bar\Api\Data;
4+
5+
interface SampleInterface
6+
{
7+
/**
8+
* String constants for property names
9+
*/
10+
const SAMPLE_PROPERTY = "sample_property";
11+
12+
/**
13+
* @return string
14+
*/
15+
public function getSampleProperty();
16+
17+
/**
18+
* @param string $sampleProperty
19+
* @return $this
20+
*/
21+
public function setSampleProperty($sampleProperty);
22+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.generator;
7+
8+
import com.intellij.openapi.project.Project;
9+
import com.intellij.psi.PsiFile;
10+
import com.magento.idea.magento2plugin.actions.generation.NewDataModelAction;
11+
import com.magento.idea.magento2plugin.actions.generation.data.DataModelData;
12+
13+
public class DataModelGeneratorTest extends BaseGeneratorTestCase {
14+
/**
15+
* Tests for generation of a Magento 2 Data Model.
16+
*/
17+
public void testGenerateDataModel() {
18+
final Project project = myFixture.getProject();
19+
final DataModelData modelData = new DataModelData(
20+
"Foo\\Bar\\Model\\Data",
21+
"Sample",
22+
"Foo_Bar",
23+
"Foo\\Bar\\Model\\Data\\Sample",
24+
"Foo\\Bar\\Api\\Data\\SampleInterface",
25+
"SAMPLE_PROPERTY;sample_property;string;SampleProperty;sampleProperty"
26+
);
27+
final DataModelGenerator generator = new DataModelGenerator(
28+
project, modelData
29+
);
30+
final PsiFile modelFile = generator.generate(NewDataModelAction.ACTION_NAME);
31+
final PsiFile expectedFile
32+
= myFixture.configureByFile(this.getFixturePath("Sample.php"));
33+
34+
assertGeneratedFileIsCorrect(
35+
expectedFile,
36+
"src/app/code/Foo/Bar/Model/Data",
37+
modelFile
38+
);
39+
}
40+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.generator;
7+
8+
import com.intellij.openapi.project.Project;
9+
import com.intellij.psi.PsiFile;
10+
import com.magento.idea.magento2plugin.actions.generation.NewDataModelAction;
11+
import com.magento.idea.magento2plugin.actions.generation.data.DataModelInterfaceData;
12+
13+
public class DataModelInterfaceGeneratorTest extends BaseGeneratorTestCase {
14+
/**
15+
* Tests for generation of a Magento 2 Data Model Interface.
16+
*/
17+
public void testGenerateDataModelInterface() {
18+
final Project project = myFixture.getProject();
19+
final DataModelInterfaceData interfaceData = new DataModelInterfaceData(
20+
"Foo\\Bar\\Api\\Data",
21+
"SampleInterface",
22+
"Foo_Bar",
23+
"Foo\\Bar\\Api\\Data\\SampleInterface",
24+
"SAMPLE_PROPERTY;sample_property;string;SampleProperty;sampleProperty"
25+
);
26+
final DataModelInterfaceGenerator generator = new DataModelInterfaceGenerator(
27+
project, interfaceData
28+
);
29+
final PsiFile interfaceFile = generator.generate(NewDataModelAction.ACTION_NAME);
30+
final PsiFile expectedFile
31+
= myFixture.configureByFile(this.getFixturePath("SampleInterface.php"));
32+
33+
assertGeneratedFileIsCorrect(
34+
expectedFile,
35+
"src/app/code/Foo/Bar/Api/Data",
36+
interfaceFile
37+
);
38+
}
39+
}

0 commit comments

Comments
 (0)