本文整理汇总了PHP中Codeception\TestCase类的典型用法代码示例。如果您正苦于以下问题:PHP TestCase类的具体用法?PHP TestCase怎么用?PHP TestCase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestCase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _failed
public function _failed(\Codeception\TestCase $test, $fail)
{
if (!$this->client || !$this->client->getInternalResponse()) {
return;
}
file_put_contents(\Codeception\Configuration::logDir() . basename($test->getFileName()) . '.page.debug.html', $this->client->getInternalResponse()->getContent());
}
示例2: _failed
public function _failed(TestCase $test, $fail)
{
if (!$this->client || !$this->client->getInternalResponse()) {
return;
}
$this->_savePageSource(codecept_output_dir() . str_replace(['::', '\\', '/'], ['.', '.', '.'], TestCase::getTestSignature($test)) . '.fail.html');
}
示例3: _setupTestCase
/**
* Setups common environment for a test case.
*
* @since 1.0.0
*
* @access protected
* @param \Codeception\TestCase $testCase The test case object.
* @param string $name Test case name.
* @param string $file The file name.
*/
protected function _setupTestCase(TestCase $testCase, $name, $file)
{
$testCase->setBackupGlobals(false);
$testCase->setBackupStaticAttributes(false);
$testCase->setRunTestInSeparateProcess(false);
$testCase->setInIsolation(false);
$testCase->setPreserveGlobalState(false);
if ($testCase instanceof Configurable) {
$testCase->configName($name);
$testCase->configFile($file);
$testCase->initConfig();
}
}
示例4: _failed
public function _failed(TestCase $test, $fail)
{
if (!$this->client || !$this->client->getInternalResponse()) {
return;
}
$filename = str_replace(['::', '\\', '/'], ['.', '', ''], TestCase::getTestSignature($test)) . '.fail.html';
file_put_contents(codecept_output_dir($filename), $this->client->getInternalResponse()->getContent());
}
示例5: testCeptNamings
/**
* @group core
*/
public function testCeptNamings()
{
$cept = new \Codeception\TestCase\Cept();
$cept->configName('LoginCept.php')->config('testFile', 'tests/acceptance/LoginCept.php');
$this->assertEquals('tests/acceptance/LoginCept.php', \Codeception\TestCase::getTestFileName($cept));
$this->assertEquals('tests/acceptance/LoginCept.php', \Codeception\TestCase::getTestFullName($cept));
$this->assertEquals('LoginCept', \Codeception\TestCase::getTestSignature($cept));
}
示例6: testCestNamings
/**
* @group core
*/
public function testCestNamings()
{
$cept = new \Codeception\TestCase\Cest();
$klass = new stdClass();
$cept->config('testClassInstance', $klass)->config('testMethod', 'user')->config('testFile', 'tests/acceptance/LoginCest.php');
$this->assertEquals('tests/acceptance/LoginCest.php:user', \Codeception\TestCase::getTestFullName($cept));
$this->assertEquals('tests/acceptance/LoginCest.php', \Codeception\TestCase::getTestFileName($cept));
$this->assertEquals('stdClass::user', \Codeception\TestCase::getTestSignature($cept));
}
示例7: getTestNames
protected function getTestNames($tests)
{
$testNames = [];
foreach ($tests as $test) {
if ($test instanceof \PHPUnit_Framework_TestCase) {
$testNames[] = \Codeception\TestCase::getTestSignature($test);
}
}
return $testNames;
}
示例8: _after
public function _after(TestCase $test)
{
$this->debug(__CLASS__ . '::' . __FUNCTION__ . '()');
$unfinished_transaction = $this->transaction_level > 0;
if ($unfinished_transaction) {
$this->debug("Unfinished transaction was found; rolling back (after test '{$test->getName(false)}')");
// wrap up the transaction so that the clean-up below can succeed.
// it is not possible to switch connectors mid-transaction.
$this->rollbackTransaction();
}
foreach ($this->test_cleanup_actions as $cleanup_action) {
$this->debugSection('cleanup', $cleanup_action->getDefinition());
call_user_func($cleanup_action, $this);
}
if ($unfinished_transaction) {
$this->fail("Unfinished transaction was found (after test '{$test->getName(false)}')");
}
$this->test_cleanup_actions = [];
parent::_after($test);
}
示例9: assertContainsTestName
protected function assertContainsTestName($name, $tests)
{
foreach ($tests as $test) {
if ($test instanceof \PHPUnit_Framework_TestCase) {
$testName = \Codeception\TestCase::getTestSignature($test);
if ($testName == $name) {
return;
}
codecept_debug($testName);
}
}
$this->fail("{$name} not found in tests");
}
示例10: saveFailed
public function saveFailed(PrintResultEvent $e)
{
$file = $this->getLogDir() . $this->config['file'];
$result = $e->getResult();
if ($result->wasSuccessful()) {
if (is_file($file)) {
unlink($file);
}
return;
}
$output = [];
foreach ($result->failures() as $fail) {
$output[] = $this->localizePath(TestCase::getTestFullName($fail->failedTest()));
}
foreach ($result->errors() as $fail) {
$output[] = $this->localizePath(TestCase::getTestFullName($fail->failedTest()));
}
file_put_contents($file, implode("\n", $output));
}
示例11: run
public function run()
{
if (!class_exists('\\Codeception\\Lib\\TestLoader')) {
throw new TaskException($this, "This task requires Codeception to be loaded. Please require autoload.php of Codeception");
}
$testLoader = new \Codeception\Lib\TestLoader($this->testsFrom);
$testLoader->loadTests();
$tests = $testLoader->getTests();
$i = 0;
$groups = [];
$this->printTaskInfo("Processing " . count($tests) . " files");
// splitting tests by groups
foreach ($tests as $test) {
$groups[$i % $this->numGroups + 1][] = \Codeception\TestCase::getTestFullName($test);
$i++;
}
// saving group files
foreach ($groups as $i => $tests) {
$filename = $this->saveTo . $i;
$this->printTaskInfo("Writing {$filename}");
file_put_contents($filename, implode("\n", $tests));
}
}
示例12: seeNoDifferenceToReferenceImage
/**
* Checks item in Memcached exists and the same as expected.
*
* @param string $referenceImageIdentifier
* @param null|string $selector
* @throws ModuleException
*/
public function seeNoDifferenceToReferenceImage($referenceImageIdentifier, $selector = null)
{
if ($selector === null) {
$selector = 'body';
}
$elements = $this->webDriver->_findElements($selector);
if (count($elements) == 0) {
throw new ElementNotFound($selector);
} elseif (count($elements) > 1) {
throw new ModuleException(__CLASS__, 'Multiple elements found for given selector "' . $selector . '" but need exactly one element!');
}
/** @var RemoteWebElement $element */
$image = $this->_createScreenshot($referenceImageIdentifier, reset($elements));
$windowSizeString = $this->moduleFileSystemUtil->getCurrentWindowSizeString($this->webDriver);
$referenceImagePath = $this->moduleFileSystemUtil->getReferenceImagePath($referenceImageIdentifier, $windowSizeString);
if (!file_exists($referenceImagePath)) {
// Ensure that the target directory exists
$this->moduleFileSystemUtil->createDirectoryRecursive(dirname($referenceImagePath));
copy($image->getImageFilename(), $referenceImagePath);
$this->currentTestCase->markTestIncomplete('Reference Image does not exist.
Test is skipeed but will now copy reference image to target directory...');
} else {
$referenceImage = new \Imagick($referenceImagePath);
/** @var \Imagick $comparedImage */
list($comparedImage, $difference) = $referenceImage->compareImages($image, \Imagick::METRIC_MEANSQUAREERROR);
$calculatedDifferenceValue = round((double) substr($difference, 0, 6) * 100, 2);
$this->currentTestCase->getScenario()->comment('Difference between reference and current image is around ' . $calculatedDifferenceValue . '%');
if ($calculatedDifferenceValue > $this->config['maxDifference']) {
$failImagePath = $this->moduleFileSystemUtil->getFailImagePath($referenceImageIdentifier, $windowSizeString, 'diff');
$this->moduleFileSystemUtil->createDirectoryRecursive(dirname($failImagePath));
$image->writeImage($this->moduleFileSystemUtil->getFailImagePath($referenceImageIdentifier, $windowSizeString, 'fail'));
$comparedImage->setImageFormat('png');
$comparedImage->writeImage($failImagePath);
$this->fail('Image does not match to the reference image.');
}
}
}
示例13: _before
public function _before(\Codeception\TestCase $test)
{
$this->scenario = $test->getScenario();
}
示例14: run
public function run()
{
foreach ($this->steps as $k => $step) {
$this->currentStep = $k;
$this->test->runStep($step);
}
}
示例15: runStep
public function runStep(Step $step)
{
$this->steps[] = $step;
$result = $this->test->runStep($step);
$step->executed = true;
return $result;
}