Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InterceptorSubstitutionTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class InterceptorSubstitutionTest extends \PHPUnit\Framework\TestCase
11 {
13  {
14  $inputConfig = [
15  'data' => []
16  ];
17  $modifier = new InterceptorSubstitution();
18  $this->assertSame($inputConfig, $modifier->modify($inputConfig));
19  }
20 
21  public function testModifyArguments()
22  {
23  $modifier = new InterceptorSubstitution();
24  $this->assertEquals($this->getOutputConfig(), $modifier->modify($this->getInputConfig()));
25  }
26 
27  public function testModifyPreferences()
28  {
29  $inputConfig = [
30  'arguments' => [
31  'ClassReplaced' => [],
32  'ClassReplacement' => [],
33  'ClassReplaced\Interceptor' => [],
34  'ClassReplacement\Interceptor' => []
35  ],
36  'preferences' => [
37  'ClassReplaced' => 'ClassReplacement'
38  ],
39  'instanceTypes' => []
40  ];
41 
42  $outputConfig = [
43  'arguments' => [
44  'ClassReplaced\Interceptor' => [],
45  'ClassReplacement\Interceptor' => []
46  ],
47  'preferences' => [
48  'ClassReplaced' => 'ClassReplacement\Interceptor',
49  'ClassReplacement' => 'ClassReplacement\Interceptor'
50  ],
51  'instanceTypes' => []
52  ];
53 
54  $modifier = new InterceptorSubstitution();
55  $this->assertEquals($outputConfig, $modifier->modify($inputConfig));
56  }
57 
63  private function getInputConfig()
64  {
65  return [
66  'arguments' => [
67  'Class' => [
68  'argument_type' => ['_i_' => 'Class\Dependency'],
69  'argument_not_shared' => ['_ins_' => 'Class\Dependency'],
70  'array_configured' => [
71  'argument_type' => ['_i_' => 'Class\Dependency'],
72  'argument_not_shared' => ['_ins_' => 'Class\Dependency'],
73  'array' => [
74  'argument_type' => ['_i_' => 'Class\Dependency'],
75  'argument_not_shared' => ['_ins_' => 'Class\DependencyIntercepted'],
76  ]
77  ]
78  ],
79  'virtualType' => [
80  'argument_type' => ['_i_' => 'Class\DependencyIntercepted'],
81  'argument_not_shared' => ['_ins_' => 'Class\Dependency'],
82  'array_configured' => ['banana']
83  ],
84  'Class\Interceptor' => [
85  'argument_type' => ['_i_' => 'Class\Dependency'],
86  'argument_not_shared' => ['_ins_' => 'Class\Dependency'],
87  'array_configured' => []
88  ],
89 
90  'Class\DependencyIntercepted\Interceptor' => [],
91  'Class\DependencyIntercepted' => []
92  ],
93  'preferences' => [
94  'ClassInterface' => 'Class',
95  ],
96  'instanceTypes' => [
97  'virtualType' => 'Class'
98  ]
99  ];
100  }
101 
107  private function getOutputConfig()
108  {
109  return [
110  'arguments' => [
111  'Class\Interceptor' => [
112  'argument_type' => ['_i_' => 'Class\Dependency'],
113  'argument_not_shared' => ['_ins_' => 'Class\Dependency'],
114  'array_configured' => [
115  'argument_type' => ['_i_' => 'Class\Dependency'],
116  'argument_not_shared' => ['_ins_' => 'Class\Dependency'],
117  'array' => [
118  'argument_type' => ['_i_' => 'Class\Dependency'],
119  'argument_not_shared' => ['_ins_' => 'Class\DependencyIntercepted'],
120  ]
121  ]
122  ],
123  'virtualType' => [
124  'argument_type' => ['_i_' => 'Class\DependencyIntercepted'],
125  'argument_not_shared' => ['_ins_' => 'Class\Dependency'],
126  'array_configured' => ['banana']
127  ],
128  'Class\DependencyIntercepted\Interceptor' => []
129  ],
130  'preferences' => [
131  'ClassInterface' => 'Class\Interceptor',
132  'Class' => 'Class\Interceptor',
133  'Class\DependencyIntercepted' => 'Class\DependencyIntercepted\Interceptor'
134  ],
135  'instanceTypes' => [
136  'virtualType' => 'Class\Interceptor',
137  ]
138  ];
139  }
140 }