Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Data Fields
SuiteGenerationTest Class Reference
Inheritance diagram for SuiteGenerationTest:
MftfTestCase

Public Member Functions

 setUp ()
 
 testSuiteGeneration1 ()
 
 testSuiteGenerationHooks ()
 
 tearDown ()
 
- Public Member Functions inherited from MftfTestCase
 generateAndCompareTest ($testName)
 
 validateSchemaErrorWithTest ($fileContents, $objectType, $expectedError)
 

Static Public Member Functions

static setUpBeforeClass ()
 
static tearDownAfterClass ()
 

Data Fields

const RESOURCES_DIR = TESTS_BP . DIRECTORY_SEPARATOR . 'verification' . DIRECTORY_SEPARATOR . 'Resources'
 
const CONFIG_YML_FILE = TESTS_BP . DIRECTORY_SEPARATOR . SuiteGenerator::YAML_CODECEPTION_CONFIG_FILENAME
 
const GENERATE_RESULT_DIR
 
- Data Fields inherited from MftfTestCase
const RESOURCES_PATH
 

Detailed Description

Definition at line 19 of file SuiteGenerationTest.php.

Member Function Documentation

◆ setUp()

setUp ( )

Definition at line 48 of file SuiteGenerationTest.php.

49  {
50  // copy config yml file to test dir
51  $fileSystem = new \Symfony\Component\Filesystem\Filesystem();
52  $fileSystem->copy(
53  realpath(
54  FW_BP
55  . DIRECTORY_SEPARATOR
56  . 'etc'
57  . DIRECTORY_SEPARATOR
58  . 'config'
59  . DIRECTORY_SEPARATOR
60  . 'codeception.dist.yml'
61  ),
62  self::CONFIG_YML_FILE
63  );
64 
65  TestLoggingUtil::getInstance()->setMockLoggingUtil();
66  }

◆ setUpBeforeClass()

static setUpBeforeClass ( )
static

Set up config.yml for testing

Definition at line 40 of file SuiteGenerationTest.php.

41  {
42  // destroy _generated if it exists
43  if (file_exists(self::GENERATE_RESULT_DIR)) {
44  DirSetupUtil::rmdirRecursive(self::GENERATE_RESULT_DIR);
45  }
46  }

◆ tearDown()

tearDown ( )

revert any changes made to config.yml remove _generated directory

Definition at line 292 of file SuiteGenerationTest.php.

293  {
294  DirSetupUtil::rmdirRecursive(self::GENERATE_RESULT_DIR);
295 
296  // delete config yml file from test dir
297  $fileSystem = new \Symfony\Component\Filesystem\Filesystem();
298  $fileSystem->remove(
299  self::CONFIG_YML_FILE
300  );
301  }

◆ tearDownAfterClass()

static tearDownAfterClass ( )
static

Remove yml if created during tests and did not exist before

Definition at line 306 of file SuiteGenerationTest.php.

307  {
308  TestLoggingUtil::getInstance()->clearMockLoggingUtil();
309  }

◆ testSuiteGeneration1()

testSuiteGeneration1 ( )

Test basic generation of a suite

Definition at line 71 of file SuiteGenerationTest.php.

72  {
73  $groupName = 'functionalSuite1';
74 
75  $expectedContents = [
76  'additionalTestCest.php',
77  'additionalIncludeTest2Cest.php',
78  'IncludeTest2Cest.php',
79  'IncludeTestCest.php'
80  ];
81 
82  // Generate the Suite
83  SuiteGenerator::getInstance()->generateSuite($groupName);
84 
85  // Validate log message and add group name for later deletion
86  TestLoggingUtil::getInstance()->validateMockLogStatement(
87  'info',
88  "suite generated",
89  ['suite' => $groupName, 'relative_path' => "_generated" . DIRECTORY_SEPARATOR . $groupName]
90  );
91 
92  self::$TEST_GROUPS[] = $groupName;
93 
94  // Validate Yaml file updated
95  $yml = Yaml::parse(file_get_contents(self::CONFIG_YML_FILE));
96  $this->assertArrayHasKey($groupName, $yml['groups']);
97 
98  $suiteResultBaseDir = self::GENERATE_RESULT_DIR .
99  DIRECTORY_SEPARATOR .
100  $groupName .
101  DIRECTORY_SEPARATOR;
102 
103  // Validate tests have been generated
104  $dirContents = array_diff(scandir($suiteResultBaseDir), ['..', '.']);
105 
106  foreach ($expectedContents as $expectedFile) {
107  $this->assertTrue(in_array($expectedFile, $dirContents));
108  }
109  }

◆ testSuiteGenerationHooks()

testSuiteGenerationHooks ( )

Test hook groups generated during suite generation

Definition at line 172 of file SuiteGenerationTest.php.

173  {
174  $groupName = 'functionalSuiteHooks';
175 
176  $expectedContents = [
177  'IncludeTestCest.php'
178  ];
179 
180  // Generate the Suite
181  SuiteGenerator::getInstance()->generateSuite($groupName);
182 
183  // Validate log message and add group name for later deletion
184  TestLoggingUtil::getInstance()->validateMockLogStatement(
185  'info',
186  "suite generated",
187  ['suite' => $groupName, 'relative_path' => "_generated" . DIRECTORY_SEPARATOR . $groupName]
188  );
189  self::$TEST_GROUPS[] = $groupName;
190 
191  // Validate Yaml file updated
192  $yml = Yaml::parse(file_get_contents(self::CONFIG_YML_FILE));
193  $this->assertArrayHasKey($groupName, $yml['groups']);
194 
195  $suiteResultBaseDir = self::GENERATE_RESULT_DIR .
196  DIRECTORY_SEPARATOR .
197  $groupName .
198  DIRECTORY_SEPARATOR;
199 
200  // Validate tests have been generated
201  $dirContents = array_diff(scandir($suiteResultBaseDir), ['..', '.']);
202 
203  foreach ($expectedContents as $expectedFile) {
204  $this->assertTrue(in_array($expectedFile, $dirContents));
205  }
206 
207  //assert group file created and contains correct contents
208  $groupFile = PROJECT_ROOT .
209  DIRECTORY_SEPARATOR .
210  "src" .
211  DIRECTORY_SEPARATOR .
212  "Magento" .
213  DIRECTORY_SEPARATOR .
214  "FunctionalTestingFramework" .
215  DIRECTORY_SEPARATOR .
216  "Group" .
217  DIRECTORY_SEPARATOR .
218  $groupName .
219  ".php";
220 
221  $this->assertTrue(file_exists($groupFile));
222  $this->assertFileEquals(
223  self::RESOURCES_PATH . DIRECTORY_SEPARATOR . $groupName . ".txt",
224  $groupFile
225  );
226  }
const PROJECT_ROOT
Definition: _bootstrap.php:8

Field Documentation

◆ CONFIG_YML_FILE

const CONFIG_YML_FILE = TESTS_BP . DIRECTORY_SEPARATOR . SuiteGenerator::YAML_CODECEPTION_CONFIG_FILENAME

Definition at line 22 of file SuiteGenerationTest.php.

◆ GENERATE_RESULT_DIR

const GENERATE_RESULT_DIR
Initial value:
= TESTS_BP .
DIRECTORY_SEPARATOR .
"verification" .
DIRECTORY_SEPARATOR .
"_generated" .
DIRECTORY_SEPARATOR

Definition at line 23 of file SuiteGenerationTest.php.

◆ RESOURCES_DIR

const RESOURCES_DIR = TESTS_BP . DIRECTORY_SEPARATOR . 'verification' . DIRECTORY_SEPARATOR . 'Resources'

Definition at line 21 of file SuiteGenerationTest.php.


The documentation for this class was generated from the following file: