5
5
*/
6
6
namespace tests \util ;
7
7
8
+ use Magento \FunctionalTestingFramework \ObjectManager ;
8
9
use Magento \FunctionalTestingFramework \Test \Handlers \TestObjectHandler ;
9
10
use Magento \FunctionalTestingFramework \Util \TestGenerator ;
10
11
use PHPUnit \Framework \TestCase ;
11
12
12
13
abstract class MftfTestCase extends TestCase
13
14
{
14
- const RESOURCES_PATH = __DIR__ . '/../verification/Resources ' ;
15
+ const RESOURCES_PATH = __DIR__ .
16
+ DIRECTORY_SEPARATOR .
17
+ '.. ' .
18
+ DIRECTORY_SEPARATOR .
19
+ 'verification ' .
20
+ DIRECTORY_SEPARATOR .
21
+ 'Resources ' ;
15
22
16
23
/**
17
24
* Private function which takes a test name, generates the test and compares with a correspondingly named txt file
@@ -37,4 +44,57 @@ public function generateAndCompareTest($testName)
37
44
$ cestFile
38
45
);
39
46
}
40
- }
47
+
48
+ /**
49
+ * Private function which attempts to generate tests given an invalid shcema of a various type
50
+ *
51
+ * @param string[] $fileContents
52
+ * @param string $objectType
53
+ * @param string $expectedError
54
+ * @throws \Exception
55
+ */
56
+ public function validateSchemaErrorWithTest ($ fileContents , $ objectType ,$ expectedError )
57
+ {
58
+ $ this ->clearHandler ();
59
+ $ fullTestModulePath = TESTS_MODULE_PATH .
60
+ DIRECTORY_SEPARATOR .
61
+ 'TestModule ' .
62
+ DIRECTORY_SEPARATOR .
63
+ $ objectType .
64
+ DIRECTORY_SEPARATOR ;
65
+
66
+ foreach ($ fileContents as $ fileName => $ fileContent ) {
67
+ $ tempFile = $ fullTestModulePath . $ fileName ;
68
+ $ handle = fopen ($ tempFile , 'w ' ) or die ('Cannot open file: ' . $ tempFile );
69
+ fwrite ($ handle , $ fileContent );
70
+ fclose ($ handle );
71
+ }
72
+ try {
73
+ $ this ->expectExceptionMessage ($ expectedError );
74
+ TestObjectHandler::getInstance ()->getObject ("someTest " );
75
+ } finally {
76
+ foreach (array_keys ($ fileContents ) as $ fileName ) {
77
+ unlink ($ fullTestModulePath . $ fileName );
78
+ }
79
+ $ this ->clearHandler ();
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Clears test handler and object manager to force recollection of test data
85
+ *
86
+ * @throws \Exception
87
+ */
88
+ private function clearHandler ()
89
+ {
90
+ // clear test object handler to force recollection of test data
91
+ $ property = new \ReflectionProperty (TestObjectHandler::class, 'testObjectHandler ' );
92
+ $ property ->setAccessible (true );
93
+ $ property ->setValue (null );
94
+
95
+ // clear test object handler to force recollection of test data
96
+ $ property = new \ReflectionProperty (ObjectManager::class, 'instance ' );
97
+ $ property ->setAccessible (true );
98
+ $ property ->setValue (null );
99
+ }
100
+ }
0 commit comments