10
10
namespace Magento \Test \Integrity \Magento \Payment ;
11
11
12
12
use Magento \Framework \App \State ;
13
+ use Magento \TestFramework \Helper \Bootstrap ;
13
14
14
15
class MethodsTest extends \PHPUnit_Framework_TestCase
15
16
{
@@ -22,11 +23,12 @@ class MethodsTest extends \PHPUnit_Framework_TestCase
22
23
*/
23
24
public function testPaymentMethod ($ code , $ methodClass )
24
25
{
26
+ Bootstrap::getObjectManager ()->configure ($ this ->getTestConfiguration ());
25
27
/** @var $blockFactory \Magento\Framework\View\Element\BlockFactory */
26
- $ blockFactory = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->get (
28
+ $ blockFactory = Bootstrap::getObjectManager ()->get (
27
29
'Magento\Framework\View\Element\BlockFactory '
28
30
);
29
- $ storeId = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->get (
31
+ $ storeId = Bootstrap::getObjectManager ()->get (
30
32
'Magento\Store\Model\StoreManagerInterface '
31
33
)->getStore ()->getId ();
32
34
/** @var $model \Magento\Payment\Model\MethodInterface */
@@ -36,7 +38,7 @@ public function testPaymentMethod($code, $methodClass)
36
38
*/
37
39
$ this ->fail ("Model of ' {$ code }' payment method is not found. " );
38
40
}
39
- $ model = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->create ($ methodClass );
41
+ $ model = Bootstrap::getObjectManager ()->create ($ methodClass );
40
42
if ($ code == \Magento \Payment \Model \Method \Substitution::CODE ) {
41
43
$ paymentInfo = $ this ->getMockBuilder (
42
44
'Magento\Payment\Model\Info '
@@ -52,7 +54,7 @@ public function testPaymentMethod($code, $methodClass)
52
54
);
53
55
$ model ->setInfoInstance ($ paymentInfo );
54
56
}
55
- \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->get ('Magento\Framework\App\State ' )
57
+ Bootstrap::getObjectManager ()->get ('Magento\Framework\App\State ' )
56
58
->setMode (State::MODE_DEVELOPER );
57
59
$ this ->assertNotEmpty ($ model ->getTitle ());
58
60
foreach ([$ model ->getFormBlockType (), $ model ->getInfoBlockType ()] as $ blockClass ) {
@@ -63,20 +65,20 @@ public function testPaymentMethod($code, $methodClass)
63
65
$ this ->assertFileExists ((string )$ block ->getTemplateFile (), $ message );
64
66
if ($ model ->canUseInternal ()) {
65
67
try {
66
- \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->get (
68
+ Bootstrap::getObjectManager ()->get (
67
69
'Magento\Store\Model\StoreManagerInterface '
68
70
)->getStore ()->setId (
69
71
\Magento \Store \Model \Store::DEFAULT_STORE_ID
70
72
);
71
73
$ block ->setArea ('adminhtml ' );
72
74
$ this ->assertFileExists ((string )$ block ->getTemplateFile (), $ message );
73
- \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->get (
75
+ Bootstrap::getObjectManager ()->get (
74
76
'Magento\Store\Model\StoreManagerInterface '
75
77
)->getStore ()->setId (
76
78
$ storeId
77
79
);
78
80
} catch (\Exception $ e ) {
79
- \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->get (
81
+ Bootstrap::getObjectManager ()->get (
80
82
'Magento\Store\Model\StoreManagerInterface '
81
83
)->getStore ()->setId (
82
84
$ storeId
@@ -85,7 +87,7 @@ public function testPaymentMethod($code, $methodClass)
85
87
}
86
88
}
87
89
}
88
- \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->get ('Magento\Framework\App\State ' )
90
+ Bootstrap::getObjectManager ()->get ('Magento\Framework\App\State ' )
89
91
->setMode (State::MODE_DEFAULT );
90
92
}
91
93
@@ -95,11 +97,47 @@ public function testPaymentMethod($code, $methodClass)
95
97
public function paymentMethodDataProvider ()
96
98
{
97
99
/** @var $helper \Magento\Payment\Helper\Data */
98
- $ helper = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->get ('Magento\Payment\Helper\Data ' );
100
+ $ helper = Bootstrap::getObjectManager ()->get ('Magento\Payment\Helper\Data ' );
99
101
$ result = [];
100
102
foreach ($ helper ->getPaymentMethods () as $ code => $ method ) {
101
103
$ result [] = [$ code , $ method ['model ' ]];
102
104
}
103
105
return $ result ;
104
106
}
107
+
108
+ /**
109
+ * @param string $path
110
+ * @return \RegexIterator
111
+ */
112
+ private function collectFiles ($ path )
113
+ {
114
+ $ ds = preg_quote (DIRECTORY_SEPARATOR );
115
+ $ flags = \FilesystemIterator::CURRENT_AS_FILEINFO
116
+ | \FilesystemIterator::SKIP_DOTS ;
117
+ $ iterator = new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ path , $ flags ));
118
+
119
+ return new \RegexIterator (
120
+ $ iterator ,
121
+ '# ' . $ ds . 'etc ' . $ ds . 'di\.php$# ' ,
122
+ \RegexIterator::MATCH ,
123
+ \RegexIterator::USE_KEY
124
+ );
125
+ }
126
+
127
+ /**
128
+ * @return array
129
+ */
130
+ private function getTestConfiguration ()
131
+ {
132
+ $ result = [];
133
+ $ ds = DIRECTORY_SEPARATOR ;
134
+ $ path = __DIR__ . $ ds . str_repeat ('.. ' . $ ds , 5 ) . 'Magento ' ;
135
+
136
+ foreach ($ this ->collectFiles ($ path ) as $ file ) {
137
+ $ config = include $ file ->getPathname ();
138
+ $ result = array_replace_recursive ($ result , $ config );
139
+ }
140
+
141
+ return $ result ;
142
+ }
105
143
}
0 commit comments