हम वास्तव में संकल्पना विस्तार कक्षाओं का उपयोग करके इसे काफी आसानी से पूरा कर सकते हैं। एक्सटेंशन के साथ हम क्या करेंगे:
हमारे एक्सटेंशन के साथ "परीक्षण से पहले" और "परीक्षण के बाद" कार्यक्रमों में हुक करें हमारी वेब सेवा को इंगित करने के लिए डीबी मॉड्यूल को पुन: कॉन्फ़िगर करें, मॉड्यूल को पुन: प्रारंभ करें और निष्पादित करें प्रत्येक वेब सेवा के लिए दोहराएं प्रारंभ करने के लिए, हमें पहले हमारे स्वीकृति परीक्षणों में डीबी मॉड्यूल को सक्षम करने की आवश्यकता है। डीबी मॉड्यूल को स्थापित करने के लिए निर्देशों का पालन करें। यहां महत्वपूर्ण बात यह है कि हम झूठी और पॉपअप को गलत पर सेट करते हैं और डंप पॉइंट को वैध फ़ाइल में सेट करते हैं। हम झूठ बोलने और साफ करने के लिए सेट अप करते हैं क्योंकि हम नहीं चाहते हैं कि प्रत्येक परीक्षण के बाद डीबी मॉड्यूल पॉप्युलेटिंग और सफाई हो। खैर, हम तरह करते हैं, लेकिन डिफ़ॉल्ट रूप से डीबी मॉड्यूल केवल एक डेटाबेस के साथ संचार करता है जहां हमें एकाधिक की आवश्यकता होती है।
दूसरा, बुनियादी संहिता विस्तार बनाने के लिए निर्देशों का पालन करें। अगर केवल आग को अपने एक्सटेंशन सेटअप यदि किसी विशेष परीक्षण ठीक से टिप्पणी की जाती है, जो
class YourExtensionClass extends \Codeception\Platform\Extension {
// events to listen on
static $events = array(
'test.before' => 'beforeTest',
'test.after' => 'afterTest',
);
function beforeTest(\CodeCeption\Event\Test $e)
{
// get the test and groups
$test = $e->getTest();
$groups = $test->getScenario()->getGroups();
// only restore if annotated to do so
if (in_array('api', $groups)) {
// get the Db module
$db = $this->getModule('Db');
// re-initialize with web service one api config and execute
$webserviceOneConfig = $this->getWebServiceOneConfig($this->config);
$db->_reconfigure($webserviceOneConfig);
$db->_initialize();
$db->_before($test);
// re-initialize with web service two api config and execute
$webserviceTwoConfig = $this->getWebServiceTwoConfig($this->config);
$db->_reconfigure($webserviceTwoConfig);
$db->_initialize();
$db->_before($test);
}
}
function afterTest(\CodeCeption\Event\Test $e)
{
// get the test and groups
$test = $e->getTest();
$groups = $test->getScenario()->getGroups();
// only restore if annotated to do so
if (in_array('api', $groups)) {
// get the Db module
$db = $this->getModule('Db');
// re-initialize with web service one api config and execute
$webserviceOneConfig = $this->getWebServiceOneConfig($this->config);
$db->_reconfigure($webserviceOneConfig);
$db->_initialize();
$db->_after($test);
// re-initialize with web service two api config and execute
$webserviceTwoConfig = $this->getWebServiceTwoConfig($this->config);
$db->_reconfigure($webserviceTwoConfig);
$db->_initialize();
$db->_after($test);
}
}
private function getWebServiceOneConfig($config)
{
return array(
'dsn' => 'your first webservice db dsn',
'dump' => '/path/to/your/first/dump/file',
'populate' => true,
'cleanup' => true,
);
}
private function getWebServiceTwoConfig($config)
{
return array(
'dsn' => 'your second webservice db dsn',
'dump' => '/path/to/your/second/dump/file',
'populate' => true,
'cleanup' => true,
);
}
: यदि आप सेटअप अपनी कक्षा के बाद, विन्यस्त और अपने बूटस्ट्रैप में शामिल, आप निम्न कोड एक गाइड के रूप में उपयोग कर सकते :
// in a Cest
/**
* @group api
*/
public function hereIsSomeTest(WebGuy $I)
{
...
}
// in a Cept
$scenario->group('api');
$I = new WebGuy($scenario);
मैं सेटअप विस्तार "API" एनोटेशन का पालन करना तो मैं सेटअप करने के लिए नहीं था और हर एक परीक्षण पर मेरी एपीआई डेटाबेस फाड़, केवल उन है कि डेटा के साथ सौदा। हालांकि, आप अपनी जरूरतों के अनुसार बहुत आसानी से संशोधित कर सकते हैं।
[स्रोत फ़ाइल] को देखकर (https://github.com/Codeception/Codeception/blob/2.1/src/Codeception/Module/Db.php) मुझे लगता है कि यह बॉक्स से बाहर संभव नहीं है । –