21 'shortDescription' =>
'Interface short description.',
22 'longDescription' =>
"Interface long\ndescription.",
24 'tag1' => [
'name' =>
'tag1',
'description' =>
'data1'],
25 'tag2' => [
'name' =>
'tag2',
'description' =>
'data2'],
36 'name' =>
'testMethod1',
39 [
'name' =>
'data',
'type' =>
'array',
'defaultValue' => [],
'passedByReference' =>
true],
42 'shortDescription' =>
'Method short description',
44 [
'name' =>
'param',
'description' =>
'array $data'],
45 [
'name' =>
'return',
'description' =>
'TestThree'],
50 'name' =>
'testMethod2',
52 [
'name' =>
'data',
'defaultValue' =>
'test_default'],
53 [
'name' =>
'flag',
'defaultValue' =>
true],
56 'shortDescription' =>
'Method short description',
57 'longDescription' =>
"Method long\ndescription",
59 [
'name' =>
'param',
'description' =>
'string $data'],
60 [
'name' =>
'param',
'description' =>
'bool $flag'],
64 'testMethod3' => [
'name' =>
'testMethod3'],
69 $this->interfaceGenerator = new \Magento\Framework\Code\Generator\InterfaceGenerator();
75 public function testGenerate($additionalMethodsData, $expectedException, $expectedExceptionMessage)
77 if ($expectedException) {
78 $this->expectException($expectedException);
79 $this->expectExceptionMessage($expectedExceptionMessage);
81 $methodsData = array_merge_recursive($this->methodsData, $additionalMethodsData);
82 $this->interfaceGenerator->setClassDocBlock($this->interfaceDocBlock)
84 ->setName(
'SevenInterface')
85 ->setNamespaceName(\
Magento\SomeModule\Model::class)
86 ->addUse(\
Magento\SomeModule\Model\Two\Test::class,
'TestTwo')
87 ->addUse(\
Magento\SomeModule\Model\Three\Test::class,
'TestThree')
88 ->setExtendedClass(\
Magento\Framework\Code\
Generator\CodeGeneratorInterface::class);
89 $generatedInterface = $this->interfaceGenerator->generate();
91 __DIR__ .
'/../_files/app/code/Magento/SomeModule/Model/SevenInterface.php' 94 $this->assertStringEndsWith(
97 "Interface was generated incorrectly." 103 $expectedContent =
'Expected generated content.';
104 $this->interfaceGenerator->setSourceDirty(
false)->setSourceContent($expectedContent);
105 $generatedContent = $this->interfaceGenerator->generate();
106 $this->assertEquals($expectedContent, $generatedContent,
"Generated content is invalid.");
111 $expectedContent =
'';
112 $this->interfaceGenerator->setSourceDirty(
false);
113 $generatedContent = $this->interfaceGenerator->generate();
114 $this->assertEquals($expectedContent, $generatedContent,
"Generated content is invalid.");
124 'additionalMethodsData' => [],
125 'expectedException' =>
'',
126 'expectedExceptionMessage' =>
'' 128 '"final" usage exception' => [
129 'additionalMethodsData' => [
'testMethod1' => [
'final' =>
true]],
130 'expectedException' =>
'\LogicException',
131 'expectedExceptionMessage' =>
"Interface method cannot be marked as 'final'. Method name: 'testMethod1'" 133 'Non public interface method exception' => [
134 'additionalMethodsData' => [
'testMethod2' => [
'visibility' =>
'protected']],
135 'expectedException' =>
'\LogicException',
136 'expectedExceptionMessage' =>
137 "Interface method visibility can only be 'public'. Method name: 'testMethod2'" 139 '"abstract" usage exception' => [
140 'additionalMethodsData' => [
'testMethod1' => [
'abstract' =>
true]],
141 'expectedException' =>
'\LogicException',
142 'expectedExceptionMessage' =>
143 "'abstract' modifier cannot be used for interface method. Method name: 'testMethod1'" defined('TESTS_BP')||define('TESTS_BP' __DIR__
testGenerate($additionalMethodsData, $expectedException, $expectedExceptionMessage)
testGeneratePredefinedContentNotSet()
testGeneratePredefinedContent()