This commit is contained in:
2020-02-01 16:47:12 +07:00
commit 4c619ad6e6
16739 changed files with 3329179 additions and 0 deletions

View File

@@ -0,0 +1,377 @@
<?php
// @codingStandardsIgnoreFile
// @codeCoverageIgnoreStart
/**
* C3 - Codeception Code Coverage
*
* @author tiger
*/
// $_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_DEBUG'] = 1;
if (isset($_COOKIE['CODECEPTION_CODECOVERAGE'])) {
$cookie = json_decode($_COOKIE['CODECEPTION_CODECOVERAGE'], true);
// fix for improperly encoded JSON in Code Coverage cookie with WebDriver.
// @see https://github.com/Codeception/Codeception/issues/874
if (!is_array($cookie)) {
$cookie = json_decode($cookie, true);
}
if ($cookie) {
foreach ($cookie as $key => $value) {
$_SERVER["HTTP_X_CODECEPTION_" . strtoupper($key)] = $value;
}
}
}
if (!array_key_exists('HTTP_X_CODECEPTION_CODECOVERAGE', $_SERVER)) {
return;
}
if (!function_exists('__c3_error')) {
function __c3_error($message)
{
$errorLogFile = defined('C3_CODECOVERAGE_ERROR_LOG_FILE') ?
C3_CODECOVERAGE_ERROR_LOG_FILE :
C3_CODECOVERAGE_MEDIATE_STORAGE . DIRECTORY_SEPARATOR . 'error.txt';
if (is_writable($errorLogFile)) {
file_put_contents($errorLogFile, $message);
} else {
$message = "Could not write error to log file ($errorLogFile), original message: $message";
}
if (!headers_sent()) {
header('X-Codeception-CodeCoverage-Error: ' . str_replace("\n", ' ', $message), true, 500);
}
setcookie('CODECEPTION_CODECOVERAGE_ERROR', $message);
}
}
// phpunit codecoverage shimming
if (!class_exists('PHP_CodeCoverage') and class_exists('SebastianBergmann\CodeCoverage\CodeCoverage')) {
class_alias('SebastianBergmann\CodeCoverage\CodeCoverage', 'PHP_CodeCoverage');
class_alias('SebastianBergmann\CodeCoverage\Report\Text', 'PHP_CodeCoverage_Report_Text');
class_alias('SebastianBergmann\CodeCoverage\Report\PHP', 'PHP_CodeCoverage_Report_PHP');
class_alias('SebastianBergmann\CodeCoverage\Report\Clover', 'PHP_CodeCoverage_Report_Clover');
class_alias('SebastianBergmann\CodeCoverage\Report\Crap4j', 'PHP_CodeCoverage_Report_Crap4j');
class_alias('SebastianBergmann\CodeCoverage\Report\Html\Facade', 'PHP_CodeCoverage_Report_HTML');
class_alias('SebastianBergmann\CodeCoverage\Report\Xml\Facade', 'PHP_CodeCoverage_Report_XML');
class_alias('SebastianBergmann\CodeCoverage\Exception', 'PHP_CodeCoverage_Exception');
}
// phpunit version
if (!class_exists('PHPUnit_Runner_Version') && class_exists('PHPUnit\Runner\Version')) {
class_alias('PHPUnit\Runner\Version', 'PHPUnit_Runner_Version');
}
// Autoload Codeception classes
if (!class_exists('\\Codeception\\Codecept')) {
if (file_exists(__DIR__ . '/codecept.phar')) {
require_once 'phar://' . __DIR__ . '/codecept.phar/autoload.php';
} elseif (stream_resolve_include_path(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
// Required to load some methods only available at codeception/autoload.php
if (stream_resolve_include_path(__DIR__ . '/vendor/codeception/codeception/autoload.php')) {
require_once __DIR__ . '/vendor/codeception/codeception/autoload.php';
}
} elseif (stream_resolve_include_path('Codeception/autoload.php')) {
require_once 'Codeception/autoload.php';
} else {
__c3_error('Codeception is not loaded. Please check that either PHAR or Composer package can be used');
}
}
// Load Codeception Config
$config_dist_file = realpath(__DIR__) . DIRECTORY_SEPARATOR . 'codeception.dist.yml';
$config_file = realpath(__DIR__) . DIRECTORY_SEPARATOR . 'codeception.yml';
if (isset($_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_CONFIG'])) {
$config_file = realpath(__DIR__) . DIRECTORY_SEPARATOR . $_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_CONFIG'];
}
if (file_exists($config_file)) {
// Use codeception.yml for configuration.
} elseif (file_exists($config_dist_file)) {
// Use codeception.dist.yml for configuration.
$config_file = $config_dist_file;
} else {
__c3_error(sprintf("Codeception config file '%s' not found", $config_file));
}
try {
\Codeception\Configuration::config($config_file);
} catch (\Exception $e) {
__c3_error($e->getMessage());
}
if (!defined('C3_CODECOVERAGE_MEDIATE_STORAGE')) {
// workaround for 'zend_mm_heap corrupted' problem
gc_disable();
$memoryLimit = ini_get('memory_limit');
$requiredMemory = '384M';
if ((substr($memoryLimit, -1) === 'M' && (int)$memoryLimit < (int)$requiredMemory)
|| (substr($memoryLimit, -1) === 'K' && (int)$memoryLimit < (int)$requiredMemory * 1024)
|| (ctype_digit($memoryLimit) && (int)$memoryLimit < (int)$requiredMemory * 1024 * 1024)
) {
ini_set('memory_limit', $requiredMemory);
}
define('C3_CODECOVERAGE_MEDIATE_STORAGE', Codeception\Configuration::logDir() . 'c3tmp');
define('C3_CODECOVERAGE_PROJECT_ROOT', Codeception\Configuration::projectDir());
define('C3_CODECOVERAGE_TESTNAME', $_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE']);
function __c3_build_html_report(PHP_CodeCoverage $codeCoverage, $path)
{
$writer = new PHP_CodeCoverage_Report_HTML();
$writer->process($codeCoverage, $path . 'html');
if (file_exists($path . '.tar')) {
unlink($path . '.tar');
}
$phar = new PharData($path . '.tar');
$phar->setSignatureAlgorithm(Phar::SHA1);
$files = $phar->buildFromDirectory($path . 'html');
array_map('unlink', $files);
if (in_array('GZ', Phar::getSupportedCompression())) {
if (file_exists($path . '.tar.gz')) {
unlink($path . '.tar.gz');
}
$phar->compress(\Phar::GZ);
// close the file so that we can rename it
unset($phar);
unlink($path . '.tar');
rename($path . '.tar.gz', $path . '.tar');
}
return $path . '.tar';
}
function __c3_build_clover_report(PHP_CodeCoverage $codeCoverage, $path)
{
$writer = new PHP_CodeCoverage_Report_Clover();
$writer->process($codeCoverage, $path . '.clover.xml');
return $path . '.clover.xml';
}
function __c3_build_crap4j_report(PHP_CodeCoverage $codeCoverage, $path)
{
$writer = new PHP_CodeCoverage_Report_Crap4j();
$writer->process($codeCoverage, $path . '.crap4j.xml');
return $path . '.crap4j.xml';
}
function __c3_build_phpunit_report(PHP_CodeCoverage $codeCoverage, $path)
{
$writer = new PHP_CodeCoverage_Report_XML(\PHPUnit_Runner_Version::id());
$writer->process($codeCoverage, $path . 'phpunit');
if (file_exists($path . '.tar')) {
unlink($path . '.tar');
}
$phar = new PharData($path . '.tar');
$phar->setSignatureAlgorithm(Phar::SHA1);
$files = $phar->buildFromDirectory($path . 'phpunit');
array_map('unlink', $files);
if (in_array('GZ', Phar::getSupportedCompression())) {
if (file_exists($path . '.tar.gz')) {
unlink($path . '.tar.gz');
}
$phar->compress(\Phar::GZ);
// close the file so that we can rename it
unset($phar);
unlink($path . '.tar');
rename($path . '.tar.gz', $path . '.tar');
}
return $path . '.tar';
}
function __c3_send_file($filename)
{
if (!headers_sent()) {
readfile($filename);
}
return __c3_exit();
}
/**
* @param $filename
* @param bool $lock Lock the file for writing?
* @return [null|PHP_CodeCoverage|\SebastianBergmann\CodeCoverage\CodeCoverage, resource]
*/
function __c3_factory($filename, $lock=false)
{
$file = null;
if ($filename !== null && is_readable($filename)) {
if ($lock) {
$file = fopen($filename, 'r+');
if (flock($file, LOCK_EX)) {
$phpCoverage = unserialize(stream_get_contents($file));
} else {
__c3_error("Failed to acquire write-lock for $filename");
}
} else {
$phpCoverage = unserialize(file_get_contents($filename));
}
return array($phpCoverage, $file);
} else {
$phpCoverage = new PHP_CodeCoverage();
}
if (isset($_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_SUITE'])) {
$suite = $_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_SUITE'];
try {
$settings = \Codeception\Configuration::suiteSettings($suite, \Codeception\Configuration::config());
} catch (Exception $e) {
__c3_error($e->getMessage());
}
} else {
$settings = \Codeception\Configuration::config();
}
try {
\Codeception\Coverage\Filter::setup($phpCoverage)
->whiteList($settings)
->blackList($settings);
} catch (Exception $e) {
__c3_error($e->getMessage());
}
return array($phpCoverage, $file);
}
function __c3_exit()
{
if (!isset($_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_DEBUG'])) {
exit;
}
return null;
}
function __c3_clear()
{
\Codeception\Util\FileSystem::doEmptyDir(C3_CODECOVERAGE_MEDIATE_STORAGE);
}
}
if (!is_dir(C3_CODECOVERAGE_MEDIATE_STORAGE)) {
if (mkdir(C3_CODECOVERAGE_MEDIATE_STORAGE, 0777, true) === false) {
__c3_error('Failed to create directory "' . C3_CODECOVERAGE_MEDIATE_STORAGE . '"');
}
}
// evaluate base path for c3-related files
$path = realpath(C3_CODECOVERAGE_MEDIATE_STORAGE) . DIRECTORY_SEPARATOR . 'codecoverage';
$requested_c3_report = (strpos($_SERVER['REQUEST_URI'], 'c3/report') !== false);
$complete_report = $current_report = $path . '.serialized';
if ($requested_c3_report) {
set_time_limit(0);
$route = ltrim(strrchr($_SERVER['REQUEST_URI'], '/'), '/');
if ($route === 'clear') {
__c3_clear();
return __c3_exit();
}
list($codeCoverage, ) = __c3_factory($complete_report);
switch ($route) {
case 'html':
try {
__c3_send_file(__c3_build_html_report($codeCoverage, $path));
} catch (Exception $e) {
__c3_error($e->getMessage());
}
return __c3_exit();
case 'clover':
try {
__c3_send_file(__c3_build_clover_report($codeCoverage, $path));
} catch (Exception $e) {
__c3_error($e->getMessage());
}
return __c3_exit();
case 'crap4j':
try {
__c3_send_file(__c3_build_crap4j_report($codeCoverage, $path));
} catch (Exception $e) {
__c3_error($e->getMessage());
}
return __c3_exit();
case 'serialized':
try {
__c3_send_file($complete_report);
} catch (Exception $e) {
__c3_error($e->getMessage());
}
return __c3_exit();
case 'phpunit':
try {
__c3_send_file(__c3_build_phpunit_report($codeCoverage, $path));
} catch (Exception $e) {
__c3_error($e->getMessage());
}
return __c3_exit();
}
} else {
list($codeCoverage, ) = __c3_factory(null);
$codeCoverage->start(C3_CODECOVERAGE_TESTNAME);
if (!array_key_exists('HTTP_X_CODECEPTION_CODECOVERAGE_DEBUG', $_SERVER)) {
register_shutdown_function(
function () use ($codeCoverage, $current_report) {
$codeCoverage->stop();
if (!file_exists(dirname($current_report))) { // verify directory exists
if (!mkdir(dirname($current_report), 0777, true)) {
__c3_error("Can't write CodeCoverage report into $current_report");
}
}
// This will either lock the existing report for writing and return it along with a file pointer,
// or return a fresh PHP_CodeCoverage object without a file pointer. We'll merge the current request
// into that coverage object, write it to disk, and release the lock. By doing this in the end of
// the request, we avoid this scenario, where Request 2 overwrites the changes from Request 1:
//
// Time ->
// Request 1 [ <read> <write> ]
// Request 2 [ <read> <write> ]
//
// In addition, by locking the file for exclusive writing, we make sure no other request try to
// read/write to the file at the same time as this request (leading to a corrupt file). flock() is a
// blocking call, so it waits until an exclusive lock can be acquired before continuing.
list($existingCodeCoverage, $file) = __c3_factory($current_report, true);
$existingCodeCoverage->merge($codeCoverage);
if ($file === null) {
file_put_contents($current_report, serialize($existingCodeCoverage), LOCK_EX);
} else {
fseek($file, 0);
fwrite($file, serialize($existingCodeCoverage));
fflush($file);
flock($file, LOCK_UN);
fclose($file);
}
}
);
}
}
// @codeCoverageIgnoreEnd

View File

@@ -0,0 +1,28 @@
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
colors: false
memory_limit: 1024M
lint: false
log: true
groups:
failed: tests/_log/failed
groupFileTest1: tests/_data/groupFileTest1
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
extensions:
config:
SuiteExtension:
config2: value2

View File

@@ -0,0 +1,19 @@
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
colors: false
silent: false
log: false
reporters:
report: MyReportPrinter
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql

View File

@@ -0,0 +1,21 @@
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
colors: false
log: false
extensions:
enabled:
- Codeception\Extension\SimpleReporter
- Codeception\Extension\RunFailed
- VerbosityLevelOutput
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql

View File

@@ -0,0 +1,19 @@
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
colors: false
silent: false
log: false
extensions:
enabled: [MyGroupHighlighter, SkipGroup, Group\CountEvents]
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql

View File

@@ -0,0 +1,18 @@
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
coloe
silent: false
log: false
strict_xml: true
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql

View File

@@ -0,0 +1,18 @@
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
colors: false
silent: false
log: false
strict_xml: true
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql

View File

@@ -0,0 +1,5 @@
{
"require-dev": {
"codeception/c3": "2.0.x-dev"
}
}

View File

@@ -0,0 +1,11 @@
<?php
require_once __DIR__.'/_data/MyGroupHighlighter.php';
require_once __DIR__.'/_data/VerbosityLevelOutput.php';
if (\PHPUnit\Runner\Version::series() < 7) {
require_once __DIR__.'/_data/MyReportPrinter.php';
}
@unlink(\Codeception\Configuration::outputDir().'order.txt');
$fh = fopen(\Codeception\Configuration::outputDir().'order.txt', 'a');
fwrite($fh, 'B');

View File

@@ -0,0 +1,42 @@
<?php
class DummyClass
{
protected $checkMe = 1;
function __construct($checkMe = 1)
{
$this->checkMe = "constructed: ".$checkMe;
}
public function helloWorld() {
return "hello";
}
public function goodByeWorld() {
return "good bye";
}
protected function notYourBusinessWorld()
{
return "goAway";
}
public function getCheckMe() {
return $this->checkMe;
}
public function call() {
$this->targetMethod();
return true;
}
public function targetMethod() {
return true;
}
public function exceptionalMethod() {
throw new Exception('Catch it!');
}
}

View File

@@ -0,0 +1,18 @@
<?php
use Codeception\Event\TestEvent;
use Codeception\GroupObject;
class MyGroupHighlighter extends GroupObject
{
static $group = 'notorun';
public function _before(TestEvent $e)
{
$this->writeln("======> Entering NoGroup Test Scope");
}
public function _after(TestEvent $e)
{
$this->writeln("<====== Ending NoGroup Test Scope");
}
}

View File

@@ -0,0 +1,39 @@
<?php
use Codeception\PHPUnit\ConsolePrinter;
use Codeception\PHPUnit\ResultPrinter;
class MyReportPrinter extends ResultPrinter implements ConsolePrinter
{
public function endTest(\PHPUnit\Framework\Test $test, $time)
{
$name = \Codeception\Test\Descriptor::getTestAsString($test);
if ($this->testStatus == \PHPUnit\Runner\BaseTestRunner::STATUS_FAILURE) {
$this->write('×');
} else {
if ($this->testStatus == \PHPUnit\Runner\BaseTestRunner::STATUS_SKIPPED) {
$this->write('S');
} else {
if ($this->testStatus == \PHPUnit\Runner\BaseTestRunner::STATUS_INCOMPLETE) {
$this->write('I');
} else {
if ($this->testStatus == \PHPUnit\Runner\BaseTestRunner::STATUS_ERROR) {
$this->write('E');
} else {
$this->write('✔');
}
}
}
}
if (strlen($name) > 75) {
$name = substr($name, 0, 70);
}
$this->write(" $name \n");
}
public function printResult(\PHPUnit\Framework\TestResult $result)
{
}
}

View File

@@ -0,0 +1,29 @@
<?php
use Codeception\Event\PrintResultEvent;
use Codeception\Events;
use Codeception\Extension;
use Symfony\Component\Console\Output\OutputInterface;
class VerbosityLevelOutput extends Extension
{
public static $events = [
Events::RESULT_PRINT_AFTER => 'printResult',
];
public function printResult(PrintResultEvent $e)
{
$this->writeln(var_export($this->options, false));
$this->writeln("Modules used: " . implode(', ', $this->getCurrentModuleNames()));
if ($this->options['verbosity'] <= OutputInterface::VERBOSITY_NORMAL) {
$this->writeln('Low verbosity');
} else if ($this->options['verbosity'] == OutputInterface::VERBOSITY_VERBOSE) {
$this->writeln('Medium verbosity');
} else if ($this->options['verbosity'] == OutputInterface::VERBOSITY_VERY_VERBOSE) {
$this->writeln('High verbosity');
} else {
$this->writeln('Extreme verbosity');
}
}
}

View File

@@ -0,0 +1 @@
/* Replace this file with actual dump of your database */

View File

@@ -0,0 +1 @@
tests/scenario/ExamplesCest.php:filesExistsAnnotation

View File

@@ -0,0 +1,4 @@
modules:
config:
MessageHelper:
message1: MESSAGE1 FROM ENV2-DIST.

View File

@@ -0,0 +1,4 @@
modules:
config:
MessageHelper:
message2: MESSAGE2 FROM ENV2.

View File

@@ -0,0 +1,4 @@
modules:
config:
MessageHelper:
message2: MESSAGE2 FROM ENV3.

View File

@@ -0,0 +1,27 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
*/
class AbsolutelyOtherGuy extends \Codeception\Actor
{
use _generated\AbsolutelyOtherGuyActions;
/**
* Define custom actions here
*/
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
*/
class CodeGuy extends \Codeception\Actor
{
use _generated\CodeGuyActions;
/**
* Define custom actions here
*/
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Codeception\Module;
// here you can define custom functions for CodeGuy
class CodeHelper extends \Codeception\Module
{
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
*/
class DumbGuy extends \Codeception\Actor
{
use _generated\DumbGuyActions;
/**
* Define custom actions here
*/
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Codeception\Module;
// here you can define custom functions for DumbGuy
class DumbHelper extends \Codeception\Module
{
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class ExtendedGuy extends \Codeception\Actor
{
use _generated\ExtendedGuyActions;
/**
* Define custom actions here
*/
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Group;
use \Codeception\Event\TestEvent;
/**
* Group class is Codeception Extension which is allowed to handle to all internal events.
* This class itself can be used to listen events for test execution of one particular group.
* It may be especially useful to create fixtures data, prepare server, etc.
*
* INSTALLATION:
*
* To use this group extension, include it to "extensions" option of global Codeception config.
*/
class CountEvents extends \Codeception\GroupObject
{
public static $group = 'countevents';
public static $beforeCount = 0;
public static $afterCount = 0;
public function _before(TestEvent $e)
{
$this::$beforeCount++;
$this->writeln("Group Before Events: " . $this::$beforeCount);
}
public function _after(TestEvent $e)
{
$this::$afterCount++;
$this->writeln("Group After Events: " . $this::$afterCount);
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Extended extends \Codeception\Module
{
}

View File

@@ -0,0 +1,9 @@
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Scenario extends \Codeception\Module
{
}

View File

@@ -0,0 +1,11 @@
<?php
namespace Math;
class Adder
{
public function perform($a, $b)
{
return $a + $b;
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Math;
class CalcHelper extends \Codeception\Module
{
/**
* @var Adder
*/
protected $adder;
/**
* @var Subtractor
*/
protected $subtractor;
protected $pi = 3;
protected function _inject(Adder $adder, Subtractor $subtractor)
{
$this->adder = $adder;
$this->subtractor = $subtractor;
}
public function add($a, $b)
{
return $this->adder->perform($a, $b);
}
public function subtract($a, $b)
{
return $this->subtractor->perform($a, $b);
}
public function squareOfCircle($radius)
{
return $this->pi * pow($radius, 2);
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace Math;
class Subtractor
{
public function perform($a, $b)
{
return $a - $b;
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
*/
class MathTester extends \Codeception\Actor
{
use _generated\MathTesterActions;
/**
* Define custom actions here
*/
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
*/
class MessageGuy extends \Codeception\Actor
{
use _generated\MessageGuyActions;
/**
* Define custom actions here
*/
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codeception\Module;
class MessageHelper extends \Codeception\Module
{
protected $config = [
'message1' => 'DEFAULT MESSAGE1.',
'message2' => 'DEFAULT MESSAGE2.',
'message3' => 'DEFAULT MESSAGE3.',
'message4' => 'DEFAULT MESSAGE4.',
];
public function getMessage($name)
{
return $this->config[$name];
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
*/
class OrderGuy extends \Codeception\Actor
{
use _generated\OrderGuyActions;
/**
* Define custom actions here
*/
}

View File

@@ -0,0 +1,66 @@
<?php
namespace Codeception\Module;
use Codeception\Configuration;
use Codeception\Module;
use Codeception\TestInterface;
class OrderHelper extends Module
{
public function _initialize()
{
self::appendToFile('I');
}
public function _before(TestInterface $test)
{
self::appendToFile('[');
}
public function _after(TestInterface $test)
{
self::appendToFile(']');
}
public function _failed(TestInterface $test, $fail)
{
self::appendToFile('F');
}
public function failNow()
{
$this->fail("intentionally");
}
public function seeFailNow()
{
$this->fail("intentionally");
}
public function dontSeeFailNow()
{
$this->fail("intentionally");
}
public function _beforeSuite($settings = array())
{
self::appendToFile('(');
}
public function _afterSuite()
{
self::appendToFile(')');
}
public function writeToFile($text)
{
self::appendToFile($text);
}
public static function appendToFile($marker)
{
$fh = fopen(Configuration::outputDir().'order.txt', 'a');
fwrite($fh, $marker);
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
*/
class OtherGuy extends \Codeception\Actor
{
use _generated\OtherGuyActions;
/**
* Define custom actions here
*/
}

View File

@@ -0,0 +1,6 @@
<?php
namespace Codeception\Module;
class OtherHelper extends \Codeception\Module
{
}

View File

@@ -0,0 +1,47 @@
<?php
namespace Page\Math;
class Trigonometry
{
// include url of current page
public static $URL = '';
/**
* Declare UI map for this page here. CSS or XPath allowed.
* public static $usernameField = '#username';
* public static $formSubmitButton = "#mainForm input[type=submit]";
*/
/**
* Basic route example for your current URL
* You can append any additional parameter to URL
* and use it in tests like: Page\Edit::route('/123-post');
*/
public static function route($param)
{
return static::$URL.$param;
}
/**
* @var \MathTester;
*/
protected $mathTester;
public function __construct(\MathTester $I)
{
$this->mathTester = $I;
}
public function tan($arg)
{
$this->mathTester->expect('i get tan of '.$arg);
return tan($arg);
}
public function assertTanIsLessThen($tan, $val)
{
$this->mathTester->assertLessThan($val, $this->tan($tan));
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
*/
class PowerGuy extends \Codeception\Actor
{
use _generated\PowerGuyActions;
/**
* Define custom actions here
*/
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Codeception\Module;
// here you can define custom functions for PowerGuy
class PowerHelper extends \Codeception\Module
{
protected $config = array('has_power' => false);
public function _hasPower()
{
return $this->config['has_power'];
}
public function gotThePower()
{
if (!$this->config['has_power']) $this->fail("I have no power :(");
}
public function castFireball()
{
$this->assertTrue(true);
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
*/
class ScenarioGuy extends \Codeception\Actor
{
use _generated\ScenarioGuyActions;
public function seeCodeCoverageFilesArePresent()
{
$this->seeFileFound('c3.php');
$this->seeFileFound('composer.json');
$this->seeInThisFile('codeception/c3');
}
/**
* @Given I have terminal opened
*/
public function terminal()
{
$this->comment('I am terminal user!');
}
/**
* @When I am in current directory
*/
public function openCurrentDir()
{
$this->amInPath('.');
}
/**
* @Given I am inside :dir
*/
public function openDir($path)
{
$this->amInPath($path);
}
/**
* @Then there is a file :name
* @Then I see file :name
*/
public function matchFile($name)
{
$this->seeFileFound($name);
}
/**
* @Then there are keywords in :smth
*/
public function thereAreValues($file, \Behat\Gherkin\Node\TableNode $node)
{
$this->seeFileFound($file);
foreach ($node->getRows() as $row) {
$this->seeThisFileMatches('~' . implode('.*?', $row) . '~');
}
}
/**
* @Then I see output :arg1
*/
public function iSeeOutput($arg1)
{
}
/**
* @Then I print :arg1
*/
public function iPrint($arg1)
{
echo "Argument: $arg1\n";
}
}

View File

@@ -0,0 +1,11 @@
<?php
class SkipGroup extends \Codeception\GroupObject
{
public static $group = 'abc';
public function _before(\Codeception\Event\TestEvent $e)
{
$e->getTest()->markTestSkipped('WE SKIP TEST');
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
*/
class SkipGuy extends \Codeception\Actor
{
use _generated\SkipGuyActions;
/**
* Define custom actions here
*/
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Codeception\Module;
// here you can define custom functions for SkipGuy
class SkipHelper extends \Codeception\Module
{
}

View File

@@ -0,0 +1,11 @@
<?php
namespace Step\Order;
class CanCantSteps extends \OrderGuy
{
public function someStep()
{
// nothing in here...
}
}

View File

@@ -0,0 +1,40 @@
<?php
use Codeception\Event\SuiteEvent;
use Codeception\Event\TestEvent;
use Codeception\Events;
use Codeception\Extension;
class SuiteExtension extends Extension
{
public static $events = [
Events::SUITE_BEFORE => 'beforeSuite',
Events::SUITE_AFTER => 'afterSuite',
Events::TEST_BEFORE => 'beforeTest',
Events::TEST_AFTER => 'afterTest',
];
protected $config = ['config1' => 'novalue', 'config2' => 'novalue'];
public function beforeSuite(SuiteEvent $e )
{
$this->writeln('Config1: ' . $this->config['config1']);
$this->writeln('Config2: ' . $this->config['config2']);
$this->writeln('Suite setup for ' . $e->getSuite()->getName());
}
public function afterSuite(SuiteEvent $e)
{
$this->writeln('Suite teardown for '. $e->getSuite()->getName());
}
public function beforeTest(TestEvent $event)
{
$this->writeln('Test setup for ' . $event->getTest()->getMetadata()->getName());
}
public function afterTest(TestEvent $event)
{
$this->writeln('Test teardown for ' . $event->getTest()->getMetadata()->getName());
}
}

View File

@@ -0,0 +1,5 @@
class_name: DumbGuy
modules:
enabled: [Filesystem, DumbHelper]
env:
dev: []

View File

@@ -0,0 +1,19 @@
<?php
class AnotherCest
{
/**
* @group ok
* @param DumbGuy $I
*/
public function optimistic(DumbGuy $I) {
$I->expect('everything is ok');
}
public function pessimistic(DumbGuy $I)
{
$I->expect('everything is bad');
}
}

View File

@@ -0,0 +1,13 @@
<?php
class AnotherTest extends \PHPUnit\Framework\TestCase
{
public function testFirst() {
$this->assertTrue(true);
}
public function testSecond()
{
$this->assertFalse(false);
}
}

View File

@@ -0,0 +1,6 @@
<?php
require '_bootstrap.php';
$I = new DumbGuy($scenario);
$I->wantTo('check config exists');
$I->seeFileFound($codeception);

View File

@@ -0,0 +1,13 @@
<?php
class GroupEventsCest
{
/**
* @group countevents
* @param DumbGuy $I
*/
public function countGroupEvents(DumbGuy $I)
{
$I->wantTo('affirm that Group events fire only once');
}
}

View File

@@ -0,0 +1,8 @@
<?php
// Here you can initialize variables that will for your tests
require_once \Codeception\Configuration::dataDir().'DummyClass.php';
$overload = \Codeception\Configuration::dataDir().'DummyOverloadableClass.php';
if (file_exists($overload)) {
require_once($overload);
}
$codeception = 'codeception.yml';

View File

@@ -0,0 +1,15 @@
class_name: ExtendedGuy
modules:
enabled:
- \Helper\Extended
extensions:
enabled:
- SuiteExtension:
config1: value1
env:
black:
extensions:
config:
SuiteExtension:
config1: black_value

View File

@@ -0,0 +1,3 @@
<?php
$I = new ExtendedGuy($scenario);
$I->comment('hello world');

View File

@@ -0,0 +1,2 @@
<?php
// Here you can initialize variables that will be available to your tests

View File

@@ -0,0 +1,8 @@
class_name: MathTester
modules:
enabled: [Asserts]
coverage:
enabled: true
include:
- 'tests/_support/Math/Adder.php'
- 'tests/_support/Math/Substractor.php'

View File

@@ -0,0 +1,44 @@
<?php
use \Math\CalcHelper as Calc;
class MathCest
{
/**
* @var Calc
*/
protected $calc;
protected function _inject(Calc $calc)
{
$this->calc = $calc;
}
public function testAddition(MathTester $I)
{
$I->assertEquals(3, $this->calc->add(1, 2));
$I->assertEquals(0, $this->calc->add(10, -10));
}
public function testSubtraction(MathTester $I)
{
$I->assertEquals(1, $this->calc->subtract(3, 2));
$I->assertEquals(0, $this->calc->subtract(5, 5));
}
public function testSquare(MathTester $I)
{
$I->assertEquals(3, $this->calc->squareOfCircle(1));
$I->assertEquals(12, $this->calc->squareOfCircle(2));
}
public function testTrigonometry(MathTester $I, \Page\Math\Trigonometry $t)
{
$I->assertLessThan(0.9, $t->tan(0.5));
}
public function testTrigonometryPage(\Page\Math\Trigonometry $t)
{
$t->assertTanIsLessThen(0.5, 0.9);
}
}

View File

@@ -0,0 +1,28 @@
<?php
use Math\CalcHelper as Calc;
class MathTest extends \Codeception\Test\Unit
{
/**
* @var \MathTester
*/
protected $tester;
/**
* @var Calc
*/
protected $calc;
protected function _inject(Calc $calc)
{
$this->calc = $calc;
}
public function testAll()
{
$this->assertEquals(3, $this->calc->add(1, 2));
$this->assertEquals(1, $this->calc->subtract(3, 2));
$this->assertEquals(75, $this->calc->squareOfCircle(5));
}
}

View File

@@ -0,0 +1,2 @@
<?php
// Here you can initialize variables that will for your tests

View File

@@ -0,0 +1,28 @@
class_name: MessageGuy
paths:
tests: tests
log: tests/_log
data: tests/_data
helpers: tests/_helpers
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: false
log: false
modules:
enabled:
- MessageHelper
config:
MessageHelper:
message3: MESSAGE3 FROM SUITE.
env:
email: []
env1:
modules:
config:
MessageHelper:
message1: MESSAGE1 FROM SUITE-ENV1.
message4: MESSAGE4 FROM SUITE-ENV1.

View File

@@ -0,0 +1,5 @@
<?php
// @env email
$I = new MessageGuy($scenario);
$I->wantTo('Test emails');
$I->expect('emails are sent');

View File

@@ -0,0 +1,34 @@
<?php
class MessageCest
{
public function allMessages(MessageGuy $I)
{
$this->showMessage($I, 1);
$this->showMessage($I, 2);
$this->showMessage($I, 3);
$this->showMessage($I, 4);
}
public function message2(MessageGuy $I)
{
$this->showMessage($I, 2);
}
protected function showMessage(MessageGuy $I, $num)
{
$I->expect('message'.$num.': ' . $I->getMessage('message'.$num));
}
/**
*
* @env env2,env1
*
* @param MessageGuy $I
*/
public function multipleEnvRequired(MessageGuy $I)
{
$I->expect('Multiple env given');
}
}

View File

@@ -0,0 +1,2 @@
<?php
// Here you can initialize variables that will for your tests

View File

@@ -0,0 +1,3 @@
class_name: OrderGuy
modules:
enabled: [OrderHelper]

View File

@@ -0,0 +1,6 @@
<?php
// @group simple
\Codeception\Module\OrderHelper::appendToFile('S');
$I = new OrderGuy($scenario);
$I->wantTo('write a marker to file to determine loading order');
$I->appendToFile('T');

View File

@@ -0,0 +1,34 @@
<?php
/**
* @group App
* @group New
*/
class BeforeAfterClassTest extends \Codeception\Test\Unit
{
/**
* @beforeClass
*/
public static function setUpSomeSharedFixtures()
{
\Codeception\Module\OrderHelper::appendToFile('{');
}
public function testOne()
{
\Codeception\Module\OrderHelper::appendToFile('1');
}
public function testTwo()
{
\Codeception\Module\OrderHelper::appendToFile('2');
}
/**
* @afterClass
*/
public static function tearDownSomeSharedFixtures()
{
\Codeception\Module\OrderHelper::appendToFile('}');
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* @group App
* @group New
*/
class BeforeAfterClassWithDataProviderTest extends \Codeception\TestCase\Test
{
/**
* @beforeClass
*/
public static function setUpSomeSharedFixtures()
{
\Codeception\Module\OrderHelper::appendToFile('{');
}
/**
* @dataProvider getAbc
*
* @param string $letter
*/
public function testAbc($letter)
{
\Codeception\Module\OrderHelper::appendToFile($letter);
}
public static function getAbc()
{
return [['A'], ['B'], ['C']];
}
/**
* @afterClass
*/
public static function tearDownSomeSharedFixtures()
{
\Codeception\Module\OrderHelper::appendToFile('}');
}
}

View File

@@ -0,0 +1,10 @@
<?php
// @group simple
\Codeception\Module\OrderHelper::appendToFile('S');
$I = new OrderGuy($scenario);
$I->wantTo('write a marker, use can* functions and write a marker after the failures');
$I->appendToFile('T');
$I->canSeeFailNow();
$I->cantSeeFailNow();
$I->wantTo('ensure a second marker is written after failures');
$I->appendToFile('T');

View File

@@ -0,0 +1,20 @@
<?php
use Step\Order\CanCantSteps;
class CanCantFailCest
{
public function testOne(CanCantSteps $I)
{
$I->appendToFile('T');
$I->canSeeFailNow();
$I->appendToFile('T');
}
public function testTwo(CanCantSteps $I)
{
$I->appendToFile('T');
$I->canSeeFailNow();
$I->appendToFile('T');
}
}

View File

@@ -0,0 +1,52 @@
<?php
use Codeception\Module\OrderHelper;
class CodeTest extends \Codeception\Test\Unit
{
public function testThis()
{
OrderHelper::appendToFile('C');
}
public static function setUpBeforeClass()
{
OrderHelper::appendToFile('{');
}
public static function tearDownAfterClass()
{
OrderHelper::appendToFile('}');
}
/**
* @before
*/
public function before()
{
OrderHelper::appendToFile('<');
}
/**
* @after
*/
public function after()
{
OrderHelper::appendToFile('>');
}
/**
* @beforeClass
*/
public static function beforeClass()
{
OrderHelper::appendToFile('{');
}
/**
* @afterClass
*/
public static function afterClass()
{
OrderHelper::appendToFile('}');
}
}

View File

@@ -0,0 +1,13 @@
<?php
class Dependent2Cest {
/**
* @depends DependentCest:firstOne
*/
public function thirdOne(OrderGuy $I)
{
}
}

View File

@@ -0,0 +1,18 @@
<?php
class DependentCest {
/**
* @depends firstOne
*/
public function secondOne(OrderGuy $I)
{
}
public function firstOne(OrderGuy $I)
{
$I->failNow();
}
}

View File

@@ -0,0 +1,7 @@
<?php
// @group simple
\Codeception\Module\OrderHelper::appendToFile('S');
$I = new OrderGuy($scenario);
$I->wantTo('write a marker and fail');
$I->appendToFile('T');
$I->failNow();

View File

@@ -0,0 +1,40 @@
<?php
class FailedCest {
protected function a($I)
{
$I->appendToFile('a');
}
protected function b($I)
{
$I->appendToFile('b');
}
/**
* @before a
* @after b
* @param OrderGuy $I
*/
public function useVariousWrappersForOrder(OrderGuy $I)
{
$I->appendToFile('%');
throw new Exception('Ups');
}
/**
* @param OrderGuy $I
*/
protected function _failed(OrderGuy $I)
{
$I->appendToFile('F');
}
protected function _after(OrderGuy $I)
{
$I->appendToFile('S');
}
}

View File

@@ -0,0 +1,6 @@
<?php
// @group simple
\Codeception\Module\OrderHelper::appendToFile('S');
$I = new OrderGuy($scenario);
$I->wantTo('write a marker to file to determine loading order');
$I->appendToFile('T');

View File

@@ -0,0 +1,10 @@
<?php
\Codeception\Module\OrderHelper::appendToFile('P'); // parsed
class ParsedLoadedTest extends \PHPUnit\Framework\TestCase
{
public function testSomething()
{
\Codeception\Module\OrderHelper::appendToFile('T');
}
}

View File

@@ -0,0 +1,53 @@
<?php
class ReorderCest {
/**
* @before a0
* @after a2
*/
protected function a1(OrderGuy $I)
{
$I->appendToFile('1');
}
protected function a0(OrderGuy $I)
{
$I->appendToFile('0');
}
protected function a2(OrderGuy $I)
{
$I->appendToFile('2');
}
/**
* @before a1
* @after a5
* @param OrderGuy $I
*/
public function useVariousWrappersForOrder(OrderGuy $I)
{
$I->appendToFile('3');
}
/**
* @before a4
* @after a6
* @param OrderGuy $I
*/
protected function a5(OrderGuy $I)
{
$I->appendToFile('5');
}
protected function a4(OrderGuy $I)
{
$I->appendToFile('4');
}
protected function a6(OrderGuy $I)
{
$I->appendToFile('6');
}
}

View File

@@ -0,0 +1,2 @@
<?php
\Codeception\Module\OrderHelper::appendToFile('B');

View File

@@ -0,0 +1,15 @@
class_name: PowerGuy
modules:
enabled: [PowerHelper, Asserts]
env:
dev:
modules:
config:
PowerHelper:
has_power: true
white:
dark:
magic:
green:
whisky:
red:

View File

@@ -0,0 +1,60 @@
<?php
class MageGuildCest
{
/**
* @env magic
* @env dark
* @param PowerGuy $I
*/
public function darkPower(PowerGuy $I)
{
$I->castFireball();
}
/**
* @env magic
* @env white
* @param PowerGuy $I
*/
public function whitePower(PowerGuy $I)
{
$I->castFireball();
}
/**
* @env magic
* @env green
* @param PowerGuy $I
*/
public function greenPower(PowerGuy $I)
{
$I->castFireball();
}
/**
* @env whisky
* @env red
* @param PowerGuy $I
*/
public function redLabel(PowerGuy $I)
{
$I->castFireball();
}
/**
* @env dark
* @env whisky
* @param PowerGuy $I
*/
public function blackLabel(PowerGuy $I)
{
$I->castFireball();
}
public function powerOfTheUniverse(PowerGuy $I)
{
$I->castFireball();
}
}

View File

@@ -0,0 +1,4 @@
<?php
$I = new PowerGuy($scenario);
$I->wantTo('reveal my power');
$I->gotThePower();

View File

@@ -0,0 +1,25 @@
<?php
class PowerUpCest
{
public function iHaveNoPower(PowerGuy $I)
{
$I->expectException('Exception', function() use ($I) {
$I->gotThePower();
});
}
/**
* @prepare drinkBluePotion
* @param PowerGuy $I
*/
public function iGotBluePotion(PowerGuy $I)
{
$I->gotThePower();
}
protected function drinkBluePotion(\Codeception\Module\PowerHelper $helper)
{
$helper->_reconfigure(['has_power' => true]);
}
}

View File

@@ -0,0 +1,2 @@
<?php
// Here you can initialize variables that will for your tests

View File

@@ -0,0 +1,25 @@
class_name: OtherGuy
modules:
enabled: [PhpBrowser, Filesystem, OtherHelper]
config:
PhpBrowser:
url: http://127.0.0.1:8000
env:
default:
webdriver:
modules:
enabled: [WebDriver, Filesystem, OtherHelper]
config:
WebDriver:
url: http://127.0.0.1:8000
browser: firefox
coverage:
enabled: true
remote: false
include:
- '/../app/*'

View File

@@ -0,0 +1,8 @@
<?php
$I = new OtherGuy($scenario);
$I->amOnPage('/');
$I->see('Welcome to test app');
$I->haveFriend("friend")->does(function(OtherGuy $I) {
$I->amOnPage('/info');
$I->see('Lots of valuable data');
});

View File

@@ -0,0 +1,2 @@
<?php
// Here you can initialize variables that will for your tests

View File

@@ -0,0 +1,24 @@
class_name: AbsolutelyOtherGuy
modules:
enabled: [PhpBrowser, Filesystem, OtherHelper]
config:
PhpBrowser:
url: http://127.0.0.1:8000
env:
default:
webdriver:
modules:
enabled: [WebDriver, Filesystem, OtherHelper]
config:
WebDriver:
url: http://127.0.0.1:8000
browser: firefox
coverage:
enabled: true
remote: true
include:
- '/../app/*'

View File

@@ -0,0 +1,5 @@
<?php
$I = new AbsolutelyOtherGuy($scenario);
$I->wantTo('show message');
$I->amOnPage('/');
$I->see('Welcome to test app');

View File

@@ -0,0 +1,2 @@
<?php
// Here you can initialize variables that will for your tests

View File

@@ -0,0 +1,6 @@
class_name: ScenarioGuy
modules:
enabled: [Filesystem, \Helper\Scenario]
gherkin:
contexts:
default: [ScenarioGuy]

View File

@@ -0,0 +1,6 @@
<?php
$I = new ScenarioGuy($scenario);
$I->amInPath('.');
$I->canSeeFileFound('not-a-file');
$I->canSeeFileFound('not-a-dir');
$I->canSeeFileFound('nothing');

View File

@@ -0,0 +1,80 @@
<?php
use Codeception\Example;
class DataProviderCest
{
/**
* @group dataprovider
* @dataProvider __exampleDataSource
*/
public function withDataProvider(ScenarioGuy $I, Example $example)
{
$I->amInPath($example['path']);
$I->seeFileFound($example['file']);
}
/**
* @group dataprovider
* @dataprovider protectedDataSource
*/
public function withProtectedDataProvider(ScenarioGuy $I, Example $example)
{
$I->amInPath($example['path']);
$I->seeFileFound($example['file']);
}
/**
* @group dataprovider
* @dataProvider __exampleDataSource
* @example(path=".", file="skipped.suite.yml")
*/
public function withDataProviderAndExample(ScenarioGuy $I, Example $example)
{
$I->amInPath($example['path']);
$I->seeFileFound($example['file']);
}
/**
* @group dataprovider
* @depends Codeception\Demo\Depends\DependencyForCest:forTestPurpose
* @dataprovider protectedDataSource
*/
public function testDependsWithDataProvider(ScenarioGuy $I, Example $example)
{
$I->amInPath($example['path']);
$I->seeFileFound($example['file']);
}
/**
* @group dataprovider
* @depends DataProviderCest:testDependsWithDataProvider
*/
public function testDependsOnTestWithDataProvider()
{
return true;
}
/**
* @return array
*/
public function __exampleDataSource()
{
return[
['path' => ".", 'file' => "scenario.suite.yml"],
['path' => ".", 'file' => "dummy.suite.yml"],
['path' => ".", 'file' => "unit.suite.yml"]
];
}
/**
* @return array
*/
protected function protectedDataSource()
{
return[
['path' => ".", 'file' => "scenario.suite.yml"],
['path' => ".", 'file' => "dummy.suite.yml"],
['path' => ".", 'file' => "unit.suite.yml"]
];
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Codeception\Demo\Depends;
class DependencyForCest
{
/**
* @group dataprovider
*/
public function forTestPurpose()
{
return 1;
}
}

View File

@@ -0,0 +1,51 @@
<?php
use Codeception\Example;
class ExamplesCest
{
/**
* @example(path=".", file="scenario.suite.yml")
* @example(path=".", file="dummy.suite.yml")
* @example(path=".", file="unit.suite.yml")
*/
public function filesExistsAnnotation(ScenarioGuy $I, Example $example)
{
$I->amInPath($example['path']);
$I->seeFileFound($example['file']);
}
/**
* @example { "path":".", "file":"scenario.suite.yml" }
* @example { "path":".", "file":"dummy.suite.yml" }
* @example { "path":".", "file":"unit.suite.yml" }
*/
public function filesExistsByJson(ScenarioGuy $I, Example $example)
{
$I->amInPath($example['path']);
$I->seeFileFound($example['file']);
}
/**
* @example [".", "scenario.suite.yml"]
* @example [".", "dummy.suite.yml"]
* @example [".", "unit.suite.yml"]
*/
public function filesExistsByArray(ScenarioGuy $I, Example $example)
{
$I->amInPath($example[0]);
$I->seeFileFound($example[1]);
}
/**
* @example [{"path":".", "file":"scenario.suite.yml"}, {"path":".", "file":"dummy.suite.yml"}, {"path":".", "file":"unit.suite.yml"}]
*/
public function filesExistsComplexJson(ScenarioGuy $I, Example $examples)
{
foreach ($examples as $example) {
$I->amInPath($example['path']);
$I->seeFileFound($example['file']);
}
}
}

View File

@@ -0,0 +1,10 @@
Feature: Run gherkin
In order to test a feature
As a user
I need to be able to see output
Scenario: Fail because file games.zip not exist
Then I see file "games.zip"
Scenario: Fail because file tools.zip not exist
Then I see file "tools.zip"

View File

@@ -0,0 +1,5 @@
<?php
$I = new ScenarioGuy($scenario);
$I->wantTo('fail when file is not found');
$I->amInPath('.');
$I->seeFileFound('games.zip');

View File

@@ -0,0 +1,22 @@
Feature: Run gherkin
In order to test a feature
As a user
I need to be able to see output
Scenario: Check file exists
Given I have terminal opened
When I am in current directory
Then there is a file "scenario.suite.yml"
And there are keywords in "scenario.suite.yml"
| class_name | ScenarioGuy |
| enabled | Filesystem |
Scenario: Describe a new feature
Given I have only idea of what's going on here
Scenario: Check file once more
Given I am in current directory
When there is a file "scenario.suite.yml"
Then I see file "scenario.suite.yml"

View File

@@ -0,0 +1,15 @@
Feature: Suite configs
In order to run tests
As a user
I need to have suite config files
Scenario Outline: Check file exists
Given I have terminal opened
When I am inside "<directory>"
Then there is a file "<filename>"
Examples:
| directory | filename |
| . | unit.suite.yml |
| . | scenario.suite.yml |
| . | dummy.suite.yml |

View File

@@ -0,0 +1,9 @@
Feature: Inline argument example
Scenario: Inline argument
Given I have inline argument "test"
When I print argument
Then I see output "test"
Scenario: Running step with inline argument
Given I print "test"

Some files were not shown because too many files have changed in this diff Show More