This commit is contained in:
2020-10-06 14:27:47 +07:00
commit 586be80cf6
16613 changed files with 3274099 additions and 0 deletions

238
vendor/codeception/base/tests/README.md vendored Normal file
View File

@@ -0,0 +1,238 @@
# Codeception Internal Tests
In case you submit a pull request, you will be asked for writing a test.
There are 3 suites for testing
* cli - acceptance tests of CLI commands
* coverage - acceptance tests of code coverage
* unit - all unit/integration/etc tests.
## Set up
1. Clone the repository to your local machine
1. Make sure you have the MongoDB extension enabled. It's not included in PHP by default, you can download it from http://pecl.php.net/package/mongodb
1. Run `composer install` in the cloned project directory
To run the web tests:
1. Start PHP's internal webserver in the project directory:
```
php -S 127.0.0.1:8000 -t tests/data/app
```
1. Start Selenium server
1. Run:
```
php codecept run web --env chrome
```
## Unit
The most important tests in this suite are Module tests located in `test/unit/Codeception/Module`. Unlike you would expect, most of tests there are integrational tests. For example, `WebDriverTest` requires an actual Selenium Server to be running.
### Testing a Module
These are basic steps if you want to add a test for a module:
1. Find corresponding module test in `tests/unit/Codeception/Module`
2. Start web server or selenium server if needed
3. Write a test
4. Execute only that test. **Do not start all test suite**
Requirements:
* PhpBrowser - demo application running on web server
* WebDriver, Selenium2 - demo application on web server + selenium server
* Frameworks (general all-framework tests) - demo application
* MongoDb, AMQP, Facebook, etc - corresponding backends
### Demo Application
When a module requires a web server with the demo application running, you can find this app in `tests/data/app`. To execute tests for **PhpBrowser** or **WebDriver** you need to start a web server for this dir:
```
php -S 127.0.0.1:8000 -t tests/data/app
```
If you run `FrameworkTest` for various frameworks, you don't need a web server running.
It is a very basic PHP application developed with `glue` microframework. To add a new html page for a test:
1. Create a new file in `tests/data/app/view`
1. Add a route in `tests/data/app/index.php`
1. Add a class in `tests/data/app/controllers.php`
To see the page in the browser, open `http://localhost:8000/your-route`
Then create a test in `tests/web/WebDriverTest.php`, and run it with `php codecept run web WebDriverTest::yourTest --env chrome`
### How to write module tests
Learn by examples! There are pretty much other tests already written. Please follow their structure.
By default you are supposed to access module methods via `module` property.
```php
<?php
$this->module->amOnPage('/form/checkbox');
$this->module->appendField('form input[name=terms]', 'I Agree123');
?>
```
To verify that form was submitted correctly you can use `data::get` method.
Example:
```php
<?php
function testPasswordField()
{
$this->module->amOnPage('/form/complex');
$this->module->submitForm('form', array(
'password' => '123456'
));
$form = data::get('form');
$this->assertEquals('123456', $form['password']);
}
?>
```
There is also a convention to use `shouldFail` method to set expected fail.
```php
<?php
protected function shouldFail()
{
$this->setExpectedException('PHPUnit_Framework_AssertionFailedError');
}
public function testAppendFieldRadioButtonByValueFails()
{
$this->shouldFail();
$this->module->amOnPage('/form/radio');
$this->module->appendField('form input[name=terms]','disagree123');
}
?>
```
## Cli
For most cases Codeception is self-tested using acceptance tests in *cli* suite. That is how Codeception core classes are tested. And actually there is no possibility to unit test many cases. Because you can't ask PHPUnit to mock PHPUnit classes.
If you send Pull Request to Codeception core and you don't know how to get it tested, just create new cli test for that. Probably you will need some additional files, maybe another suite configurations, so add them.
That is why Codeception can't have code coverage reports, as we rely on acceptance tests in testing core.
You can run all cli tests with
```
codecept run cli
```
Test cases are:
* generating codeception templates
* running tests with different configs in different modes
* testing execution order
* running multi-app tests
* etc
### Claypit + Sandbox
Before each test `tests/data/claypit` is copied to `tests/data/sandbox`, and all the test actions will be executed inside that sandbox. In the end this directory is removed. In sandbox different codeception tests may be executed and checked for exepected output.
Example test:
```php
<?php
$I = new CliGuy($scenario);
$I->wantToTest('build command');
$I->runShellCommand('php codecept build');
$I->seeInShellOutput('generated successfully');
$I->seeFileFound('CodeGuy.php','tests/unit');
$I->seeFileFound('CliGuy.php','tests/cli');
$I->seeInThisFile('seeFileFound(');
?>
```
There are various test suites in `tests/data/claypit`. Maybe you will need to create a new suite for your tests.
## Coverage
Acceptance tests that use demo application and `c3` collector, to check that a code coverage can be collected remotely. This tests are rarely updated, they should just work )
---
## Dockerized testing
### Local testing and development with `docker-compose`
Using `docker-compose` for test configurations
cd tests
Build the `codeception/codeception` image
docker-compose build
Start
docker-compose up -d
By default the image has `codecept` as its entrypoint, to run the tests simply supply the `run` command
docker-compose run --rm codecept help
Run suite
docker-compose run --rm codecept run cli
Run folder
docker-compose run --rm codecept run unit Codeception/Command
Run single test
docker-compose run --rm codecept run cli ExtensionsCest
Development bash
docker-compose run --rm --entrypoint bash codecept
Cleanup
docker-compose run --rm codecept clean
In parallel
docker-compose --project-name test-cli run -d --rm codecept run --html report-cli.html cli & \
docker-compose --project-name test-unit-command run -d --rm codecept run --html report-unit-command.html unit Codeception/Command & \
docker-compose --project-name test-unit-constraints run -d --rm codecept run --html report-unit-constraints.html unit Codeception/Constraints
### Adding services
Add Redis to `docker-compose.yml`
services:
[...]
redis:
image: redis:3
Update `host`
protected static $config = [
'database' => 15,
'host' => 'redis'
];
Run Redis tests
docker-compose run --rm codecept run unit Codeception/Module/RedisTest
Further Examples
firefox:
image: selenium/standalone-firefox-debug:2.52.0
chrome:
image: selenium/standalone-chrome-debug:2.52.0
mongo:
image: mongo

View File

@@ -0,0 +1,8 @@
class_name: AngularGuy
bootstrap: false
modules:
enabled:
- AngularJS:
url: http://davertmik.github.io/angular-demo-app
browser: firefox
- \Helper\Angular

View File

@@ -0,0 +1,69 @@
<?php
class AngularCest
{
public function _before(AngularGuy $I)
{
$I->amOnPage('/');
}
public function followLinks(AngularGuy $I)
{
$I->click('Get more info!');
$I->see('About', 'h1');
$I->seeInCurrentUrl('#/info');
$I->expect('Angular scope is rendered');
$I->see('Welcome to event app', 'p');
$I->click('Back to form');
$I->see('Create Event', 'h1');
}
public function fillFieldByName(AngularGuy $I)
{
$I->see('Create Event', 'h1');
$I->fillField('Name', 'davert');
$I->submit();
$I->dontSee('Please wait');
$I->see('Thank you');
$I->see('davert', '#data');
$I->seeInFormResult(['name' => 'davert']);
}
/**
* @depends fillFieldByName
* @param AngularGuy $I
*/
public function fillFieldByPlaceholder(AngularGuy $I)
{
$I->fillField('Please enter a name', 'davert');
$I->submit();
$I->seeInFormResult(['name' => 'davert']);
}
/**
* @depends fillFieldByName
* @param AngularGuy $
*/
public function fillRadioByLabel(AngularGuy $I)
{
$I->checkOption('Free');
$I->submit();
$I->seeInFormResult(['price' => '0']);
}
public function fillInWysiwyg(AngularGuy $I)
{
$I->expect('i can edit editable divs');
$I->fillField('.cke_editable', 'Hello world');
$I->wait(1);
$I->submit();
$I->seeInFormResult(['htmldesc' => "<p>Hello world</p>\n"]);
}
public function fillSelect(AngularGuy $I)
{
$I->selectOption('Guest Speaker', 'Iron Man');
$I->submit();
$I->seeInFormResult(["speaker1" => "iron_man"]);
}
}

View File

@@ -0,0 +1,8 @@
class_name: CliGuy
modules:
enabled:
- Filesystem
- Cli
- CliHelper
- CodeHelper
- Asserts

View File

@@ -0,0 +1,15 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('change configs and check that Guy is rebuilt');
$I->amInPath('tests/data/sandbox');
$I->writeToFile('tests/unit.suite.yml', <<<EOF
class_name: CodeGuy
modules:
enabled: [Cli, CodeHelper]
EOF
);
$I->executeCommand('run unit PassingTest.php --debug');
$I->seeInShellOutput('Cli');
$I->seeFileFound('tests/_support/_generated/CodeGuyActions.php');
$I->seeInThisFile('public function seeInShellOutput');
$I->seeInThisFile('public function runShellCommand');

View File

@@ -0,0 +1,82 @@
<?php
class BootstrapCest
{
protected $bootstrapPath;
public function _before(\CliGuy $I)
{
$this->bootstrapPath = 'tests/data/sandbox/boot'.uniqid();
@mkdir($this->bootstrapPath, 0777, true);
$I->amInPath($this->bootstrapPath);
}
public function bootstrap(\CliGuy $I)
{
$I->executeCommand('bootstrap');
$I->seeFileFound('codeception.yml');
$this->checkFilesCreated($I);
}
public function bootstrapWithNamespace(\CliGuy $I)
{
$I->executeCommand('bootstrap --namespace Generated');
$I->seeFileFound('codeception.yml');
$I->seeInThisFile('namespace: Generated');
$I->dontSeeInThisFile('namespace Generated\\');
$this->checkFilesCreated($I);
$I->seeFileFound('Acceptance.php', 'tests/_support/Helper');
$I->seeInThisFile('namespace Generated\Helper;');
$I->seeFileFound('AcceptanceTester.php', 'tests/_support');
$I->seeInThisFile('namespace Generated;');
}
public function bootstrapWithActor(\CliGuy $I)
{
$I->executeCommand('bootstrap --actor Ninja');
$I->seeFileFound('AcceptanceNinja.php', 'tests/_support/');
}
public function bootstrapEmpty(\CliGuy $I)
{
$I->executeCommand('bootstrap --empty');
$I->dontSeeFileFound('tests/acceptance');
$I->seeFileFound('codeception.yml');
}
public function bootstrapFromInit(\CliGuy $I)
{
$I->executeCommand('init bootstrap');
$this->checkFilesCreated($I);
}
public function bootstrapFromInitUsingClassName(\CliGuy $I)
{
$I->executeCommand('init "Codeception\Template\Bootstrap"');
$this->checkFilesCreated($I);
}
protected function checkFilesCreated(\CliGuy $I)
{
$I->seeDirFound('tests/_support');
$I->seeDirFound('tests/_data');
$I->seeDirFound('tests/_output');
$I->seeFileFound('functional.suite.yml', 'tests');
$I->seeFileFound('acceptance.suite.yml', 'tests');
$I->seeFileFound('unit.suite.yml', 'tests');
$I->seeFileFound('AcceptanceTester.php', 'tests/_support');
$I->seeFileFound('FunctionalTester.php', 'tests/_support');
$I->seeFileFound('UnitTester.php', 'tests/_support');
$I->seeFileFound('Acceptance.php', 'tests/_support/Helper');
$I->seeFileFound('Functional.php', 'tests/_support/Helper');
$I->seeFileFound('Unit.php', 'tests/_support/Helper');
}
}

View File

@@ -0,0 +1,13 @@
<?php
// @group core
$I = new CliGuy($scenario);
$I->wantToTest('build command');
$I->runShellCommand('php codecept build');
$I->seeInShellOutput('generated successfully');
$I->seeInSupportDir('CodeGuy.php');
$I->seeInSupportDir('CliGuy.php');
$I->seeInThisFile('class CliGuy extends \Codeception\Actor');
$I->seeInThisFile('use _generated\CliGuyActions');
$I->seeFileFound('CliGuyActions.php', 'tests/support/_generated');
$I->seeInThisFile('seeFileFound(');

View File

@@ -0,0 +1,16 @@
<?php
class CodeceptionYmlInTestsDirCest
{
/**
* @param CliGuy $I
*/
public function runTestPath(\CliGuy $I)
{
$I->amInPath('tests/data/codeception_yml_in_tests_dir');
$I->executeCommand('run unit/ExampleCest.php');
$I->seeResultCodeIs(0);
$I->dontSeeInShellOutput('RuntimeException');
$I->dontSeeInShellOutput('could not be found');
}
}

View File

@@ -0,0 +1,36 @@
<?php
class ConfigBundledSuitesCest
{
public function runBundledSuite(CliGuy $I)
{
$I->amInPath('tests/data/bundled_suites');
$I->executeCommand('build');
$I->executeCommand('run -vvv');
$I->seeInShellOutput('OK (1 test');
}
public function runTestByPath(CliGuy $I)
{
$I->amInPath('tests/data/bundled_suites');
$I->executeCommand('run BasicTest.php');
$I->seeInShellOutput('OK (1 test');
}
public function generateTestsForBundledSuite(CliGuy $I)
{
$I->amInPath('tests/data/bundled_suites');
$I->executeFailCommand('generate:cept unit Some');
$I->seeFileFound('SomeCept.php', '.');
$I->deleteFile('SomeCept.php');
$I->seeResultCodeIs(0);
$I->executeFailCommand('generate:cest unit Some');
$I->seeFileFound('SomeCest.php', '.');
$I->deleteFile('SomeCest.php');
$I->seeResultCodeIs(0);
$I->executeFailCommand('generate:test unit Some');
$I->seeResultCodeIs(0);
$I->seeFileFound('SomeTest.php', '.');
$I->deleteFile('SomeTest.php');
}
}

View File

@@ -0,0 +1,17 @@
<?php
class ConfigExtendsCest
{
/**
* @param CliGuy $I
*/
public function runIncludedSuites(\CliGuy $I)
{
$I->amInPath('tests/data/config_extends');
$I->executeCommand('run');
$I->seeInShellOutput('UnitCest');
$I->seeInShellOutput('OK (1 test, 1 assertion)');
$I->dontSeeInShellOutput('Exception');
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* @depends ConfigBundledSuitesCest:runBundledSuite
*/
class ConfigNoActorCest
{
/**
* @depends ConfigBundledSuitesCest:runBundledSuite
* @param CliGuy $I
*/
public function runSuitesWithoutActor(CliGuy $I)
{
$I->amInPath('tests/data/no_actor_suites');
$I->executeCommand('run -vvv');
$I->seeInShellOutput('OK (1 test');
}
public function suitesWithoutActorDontHaveActorFiles(CliGuy $I)
{
$I->amInPath('tests/data/no_actor_suites');
$I->executeCommand('build');
$I->dontSeeFileFound('*.php', 'tests/_support');
}
public function suitesWithoutActorGenerators(CliGuy $I)
{
$I->amInPath('tests/data/no_actor_suites');
$I->executeFailCommand('generate:cept unit Some');
$I->seeResultCodeIsNot(0);
$I->executeFailCommand('generate:cest unit Some');
$I->seeResultCodeIsNot(0);
$I->executeFailCommand('generate:test unit Some');
$I->seeResultCodeIs(0);
$I->seeFileFound('SomeTest.php', 'tests');
$I->seeInThisFile('class SomeTest extends \Codeception\Test\Unit');
$I->dontSeeInThisFile('$tester');
$I->deleteFile('tests/SomeTest.php');
}
}

View File

@@ -0,0 +1,40 @@
<?php
class ConfigParamsCest
{
public function checkYamlParamsPassed(CliGuy $I)
{
$I->amInPath('tests/data/params');
$I->executeCommand('run -c codeception_yaml.yml');
$I->seeInShellOutput('OK (1 test');
}
public function checkDotEnvParamsPassed(CliGuy $I)
{
$I->amInPath('tests/data/params');
$I->executeCommand('run -c codeception_dotenv.yml');
$I->seeInShellOutput('OK (1 test');
}
public function checkComplexDotEnvParamsPassed(CliGuy $I)
{
$I->amInPath('tests/data/params');
$I->executeCommand('run -c codeception_dotenv2.yml');
$I->seeInShellOutput('OK (1 test');
}
public function checkEnvParamsPassed(CliGuy $I)
{
$I->amInPath('tests/data/params');
$I->executeCommand('run --no-exit');
$I->seeInShellOutput('FAILURES');
$I->seeInShellOutput("Failed asserting that an array contains 'val1'");
}
public function checkParamsPassedInSelf(CliGuy $I)
{
$I->amInPath('tests/data/params');
$I->executeCommand('run -c codeception_self.yml');
$I->seeInShellOutput('OK (1 test');
}
}

View File

@@ -0,0 +1,38 @@
<?php
class ConfigValidateCest
{
public function _before(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
}
public function printsValidConfig(CliGuy $I)
{
$I->executeCommand('config:validate --no-ansi', false);
$I->dontSeeInShellOutput('ConfigurationException');
$I->seeInShellOutput('tests => tests');
$I->seeInShellOutput('data => tests/_data');
}
public function validatesInvalidConfigOnParse(CliGuy $I)
{
$I->executeCommand('config:validate -c codeception_invalid.yml --no-ansi', false);
$I->seeInShellOutput('Unable to parse at line 8');
$I->seeInShellOutput('codeception_invalid.yml');
}
public function validatesInvalidConfigBeforeRun(CliGuy $I)
{
$I->executeCommand('config:validate -c codeception_invalid.yml --no-ansi', false);
$I->seeInShellOutput('Unable to parse at line 8');
$I->seeInShellOutput('codeception_invalid.yml');
}
public function validatesConfigWithOverrideOption(CliGuy $I)
{
$I->executeCommand('config:validate -o "reporters: report: \Custom\Reporter" --no-ansi');
$I->seeInShellOutput('report => \Custom\Reporter');
}
}

View File

@@ -0,0 +1,12 @@
<?php
class ConfigWithPresetsCest
{
public function loadWithPresets(CliGuy $I)
{
$I->amInPath('tests/data/presets');
$I->executeCommand('run -c codeception.yml');
$I->seeInShellOutput('OK (1 test');
}
}

View File

@@ -0,0 +1,170 @@
<?php
class DataProviderFailuresAndExceptionsCest
{
/**
* @param CliGuy $I
*/
protected function moveToPath(\CliGuy $I)
{
$I->amInPath('tests/data/dataprovider_failures_and_exceptions');
}
/**
* This looks at only the contents of stdout when there is a failure in parsing a dataProvider annotation.
* When there is a failure all the useful information should go to stderr, so stdout is left with
* only the version headers.
*
* @param CliGuy $I
* @before moveToPath
*/
public function runTestWithDataProvidersFailureStdout(\CliGuy $I)
{
/**
* On windows /dev/null is NUL so detect running OS and return the appropriate string for redirection.
* As some systems have php_uname and co disabled, we use the DIRECTORY_SEPARATOR constant to
* figure out if we are running on windows or not.
*/
$devNull = (DIRECTORY_SEPARATOR === '\\')?'NUL':'/dev/null';
$I->executeCommand('run -n -v unit DataProvidersFailureCest 2> '.$devNull,false);
// We should only see the version headers in stdout when there is this kind of failure.
$I->canSeeShellOutputMatches('/^Codeception PHP Testing Framework v[0-9\.]+\nPowered by PHPUnit .+ by Sebastian Bergmann and contributors\.$/');
$I->seeResultCodeIs(1);
}
/**
* This redirects stderr to stdout so that we can test the contents of stderr. Stderr is where all the interesting
* information should be when there is a failure.
*
* @param CliGuy $I
* @before moveToPath
*/
public function runTestWithDataProvidersFailureStderr(\CliGuy $I)
{
$I->executeCommand('run -n unit DataProvidersFailureCest 2>&1',false);
$I->seeInShellOutput('Couldn\'t parse test');
$I->seeInShellOutput('DataProvider \'rectangle\' for DataProvidersFailureCest->testIsTriangle');
$I->seeInShellOutput('Make sure that the dataprovider exist within the test class.');
// For Unit tests PHPUnit throws the errors, this confirms that we haven't ended up running PHPUnit test Loader
$I->dontSeeInShellOutput('PHPUnit_Framework_Warning');
$I->dontSeeInShellOutput('The data provider specified for DataProvidersFailureCest::testIsTriangle');
$I->dontSeeInShellOutput('Method rectangle does not exist');
$I->dontSeeInShellOutput('FAILURES!');
$I->dontSeeInShellOutput('WARNINGS!');
$I->dontSeeInShellOutput('OK');
$I->dontSeeInShellOutput('Tests: 1, Assertions: 0, Warnings: 1.');
// In normal mode the Exception trace should not appear.
$I->dontSeeInShellOutput('Exception trace');
$I->seeResultCodeIs(1);
}
/**
* This adds the -v to the stderr test which should just add the Exception Trace to the output.
*
* @param CliGuy $I
* @before moveToPath
*/
public function runTestWithDataProvidersFailureStderrVerbose(\CliGuy $I)
{
$I->executeCommand('run -n unit DataProvidersFailureCest -v 2>&1',false);
$I->seeInShellOutput('Couldn\'t parse test');
$I->seeInShellOutput('DataProvider \'rectangle\' for DataProvidersFailureCest->testIsTriangle');
$I->seeInShellOutput('Make sure that the dataprovider exist within the test class.');
// For Unit tests PHPUnit throws the errors, this confirms that we haven't ended up running PHPUnit test Loader
$I->dontSeeInShellOutput('PHPUnit_Framework_Warning');
$I->dontSeeInShellOutput('The data provider specified for DataProvidersFailureCest::testIsTriangle');
$I->dontSeeInShellOutput('Method rectangle does not exist');
$I->dontSeeInShellOutput('FAILURES!');
$I->dontSeeInShellOutput('WARNINGS!');
$I->dontSeeInShellOutput('OK');
$I->dontSeeInShellOutput('Tests: 1, Assertions: 0, Warnings: 1.');
// In verbose mode the Exception trace should be output.
$I->seeInShellOutput('[Codeception\Exception\TestParseException]');
$I->seeInShellOutput('Exception trace');
$I->seeResultCodeIs(1);
}
/**
* This looks at only the contents of stdout when there is an exception thrown when executing a dataProvider
* function.
* When exception thrown all the useful information should go to stderr, so stdout is left with nothing.
*
* @param CliGuy $I
* @before moveToPath
*/
public function runTestWithDataProvidersExceptionStdout(\CliGuy $I)
{
/**
* On windows /dev/null is NUL so detect running OS and return the appropriate string for redirection.
* As some systems have php_uname and co disabled, we use the DIRECTORY_SEPARATOR constant to
* figure out if we are running on windows or not.
*/
$devNull = (DIRECTORY_SEPARATOR === '\\')?'NUL':'/dev/null';
$I->executeCommand('run -n unit DataProvidersExceptionCest -v 2> '.$devNull, false);
// Depending on the test environment, we either see nothing or just the headers here.
$I->canSeeShellOutputMatches('/^Codeception PHP Testing Framework v[0-9\.]+\nPowered by PHPUnit .+ by Sebastian Bergmann and contributors\.$/');
$I->seeResultCodeIs(1);
}
/**
* This redirects stderr to stdout so that we can test the contents of stderr. Stderr is where all the interesting
* information should be when there is a failure.
*
* @param CliGuy $I
* @before moveToPath
*/
public function runTestWithDataProvidersExceptionStderr(\CliGuy $I)
{
$I->executeCommand('run -n unit DataProvidersExceptionCest 2>&1', false);
// For Unit tests PHPUnit throws the errors, this confirms that we haven't ended up running PHPUnit test Loader
$I->dontSeeInShellOutput('There was 1 warning');
$I->dontSeeInShellOutput('PHPUnit_Framework_Warning');
$I->dontSeeInShellOutput('The data provider specified for DataProvidersExceptionTest::testIsTriangle');
$I->dontSeeInShellOutput('FAILURES!');
$I->dontSeeInShellOutput('WARNINGS!');
$I->dontSeeInShellOutput('OK');
// We should not see the messages related to a failure to parse the dataProvider function
$I->dontSeeInShellOutput('[Codeception\Exception\TestParseException]');
$I->dontSeeInShellOutput('Couldn\'t parse test');
$I->dontSeeInShellOutput('DataProvider \'rectangle\' for DataProvidersFailureCest->testIsTriangle ');
// We should just see the message
$I->seeInShellOutput('Something went wrong!!!');
// We don't have the verbose flag set, so there should be no trace.
$I->dontSeeInShellOutput('Exception trace:');
$I->seeResultCodeIs(1);
}
/**
* This adds the -v to the stderr test which should just add the Exception Trace to the output of stderr.
*
* @param CliGuy $I
* @before moveToPath
*/
public function runTestWithDataProvidersExceptionStderrVerbose(\CliGuy $I)
{
$I->executeCommand('run -n unit DataProvidersExceptionCest -v 2>&1', false);
// For Unit tests PHPUnit throws the errors, this confirms that we haven't ended up running PHPUnit test Loader
$I->dontSeeInShellOutput('There was 1 warning');
$I->dontSeeInShellOutput('PHPUnit_Framework_Warning');
$I->dontSeeInShellOutput('The data provider specified for DataProvidersExceptionTest::testIsTriangle');
$I->dontSeeInShellOutput('FAILURES!');
$I->dontSeeInShellOutput('WARNINGS!');
$I->dontSeeInShellOutput('OK');
// We should not see the messages related to a failure to parse the dataProvider function
$I->dontSeeInShellOutput('[Codeception\Exception\TestParseException]');
$I->dontSeeInShellOutput('Couldn\'t parse test');
$I->dontSeeInShellOutput('DataProvider \'rectangle\' for DataProvidersFailureCest->testIsTriangle is ');
// We should just see the message
$I->seeInShellOutput('Something went wrong!!!');
// We have the verbose flag set, so there should be a trace.
$I->seeInShellOutput('[Exception]');
$I->seeInShellOutput('Exception trace:');
$I->seeResultCodeIs(1);
}
}

View File

@@ -0,0 +1,25 @@
<?php
class DryRunCest
{
public function _before(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
}
public function runCestWithExamples(CliGuy $I)
{
$I->executeCommand('dry-run scenario ExamplesCest --no-ansi');
$I->seeInShellOutput('ExamplesCest: Files exists annotation');
}
public function runFeature(CliGuy $I)
{
$I->executeCommand('dry-run scenario File.feature --no-ansi');
$I->seeInShellOutput('Run gherkin: Check file exists');
$I->seeInShellOutput('In order to test a feature');
$I->seeInShellOutput('As a user');
$I->seeInShellOutput('Given i have terminal opened');
$I->seeInShellOutput('INCOMPLETE');
$I->seeInShellOutput('Step definition for `I have only idea of what\'s going on here` not found');
}
}

View File

@@ -0,0 +1,14 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('see that exception in before does not cause fatal error in after');
$I->amInPath('tests/data/exception_in_before');
$I->executeFailCommand('run --xml --no-ansi');
$I->seeInShellOutput('[Exception] in before');
$I->dontSeeInShellOutput('[RuntimeException] in cept');
$I->dontSeeInShellOutput('[RuntimeException] in cest');
$I->dontSeeInShellOutput('[RuntimeException] in gherkin');
$I->seeInShellOutput('Tests: 4, Assertions: 0, Errors: 5');
//@todo if Unit format is ever fixed in PHPUnit, uncomment these lines
//$I->dontSeeInShellOutput('[RuntimeException] in test');
//$I->seeInShellOutput('Tests: 4, Assertions: 0, Errors: 4');

View File

@@ -0,0 +1,92 @@
<?php
class ExtensionsCest
{
// tests
public function useAlternativeFormatter(CliGuy $I)
{
$I->wantTo('use alternative formatter delivered through extensions');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run tests/dummy/FileExistsCept.php -c codeception_extended.yml');
$I->dontSeeInShellOutput("Check config");
$I->seeInShellOutput('[+] FileExistsCept');
$I->seeInShellOutput('Modules used: Filesystem, DumbHelper');
}
public function loadExtensionByOverride(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run tests/dummy/FileExistsCept.php -o "extensions: enabled: [\Codeception\Extension\SimpleReporter]"');
$I->dontSeeInShellOutput("Check config");
$I->seeInShellOutput('[+] FileExistsCept');
}
public function dynamicallyEnablingExtensions(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run dummy --ext DotReporter');
$I->seeInShellOutput('......');
$I->dontSeeInShellOutput('Optimistic');
$I->dontSeeInShellOutput('AnotherCest');
}
public function reRunFailedTests(CliGuy $I)
{
$ds = DIRECTORY_SEPARATOR;
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run unit FailingTest.php -c codeception_extended.yml --no-exit');
$I->seeInShellOutput('FAILURES');
$I->seeFileFound('failed', 'tests/_output');
$I->seeFileContentsEqual("tests{$ds}unit{$ds}FailingTest.php:testMe");
$I->executeCommand('run -g failed -c codeception_extended.yml --no-exit');
$I->seeInShellOutput('Tests: 1, Assertions: 1, Failures: 1');
$failGroup = "some-failed";
$I->executeCommand("run unit FailingTest.php -c codeception_extended.yml --no-exit --override \"extensions: config: Codeception\\Extension\\RunFailed: fail-group: {$failGroup}\"");
$I->seeInShellOutput('FAILURES');
$I->seeFileFound($failGroup, 'tests/_output');
$I->seeFileContentsEqual("tests{$ds}unit{$ds}FailingTest.php:testMe");
$I->executeCommand("run -g {$failGroup} -c codeception_extended.yml --no-exit --override \"extensions: config: Codeception\\Extension\\RunFailed: fail-group: {$failGroup}\"");
$I->seeInShellOutput('Tests: 1, Assertions: 1, Failures: 1');
}
public function checkIfExtensionsReceiveCorrectOptions(CliGuy $I)
{
$I->wantTo('check if extensions receive correct options');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run tests/dummy/AnotherCest.php:optimistic -c codeception_extended.yml');
$I->seeInShellOutput('Low verbosity');
$I->executeCommand('run tests/dummy/AnotherCest.php:optimistic -c codeception_extended.yml -v');
$I->seeInShellOutput('Medium verbosity');
$I->executeCommand('run tests/dummy/AnotherCest.php:optimistic -c codeception_extended.yml -vv');
$I->seeInShellOutput('High verbosity');
$I->executeCommand('run tests/dummy/AnotherCest.php:optimistic -c codeception_extended.yml -vvv');
$I->seeInShellOutput('Extreme verbosity');
}
public function runPerSuiteExtensions(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run extended,scenario', false);
$I->seeInShellOutput('Suite setup for extended');
$I->seeInShellOutput('Test setup for Hello');
$I->seeInShellOutput('Test teardown for Hello');
$I->seeInShellOutput('Suite teardown for extended');
$I->dontSeeInShellOutput('Suite setup for scenario');
$I->seeInShellOutput('Config1: value1');
$I->seeInShellOutput('Config2: value2');
}
public function runPerSuiteExtensionsInEnvironment(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run extended --env black', false);
$I->seeInShellOutput('Suite setup for extended');
$I->seeInShellOutput('Test setup for Hello');
$I->seeInShellOutput('Config1: black_value');
$I->seeInShellOutput('Config2: value2');
}
}

View File

@@ -0,0 +1,22 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('generate sample Cept');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('generate:cept dummy DummyCept');
$I->seeFileFound('DummyCept.php', 'tests/dummy');
$I->seeInThisFile('$I = new DumbGuy($scenario);');
$I->deleteThisFile();
$I->amGoingTo('create scenario in folder');
$I->executeCommand('generate:cept dummy path/DummyCept');
$I->seeFileFound('DummyCept.php', 'tests/dummy/path');
$I->deleteThisFile();
$I->amGoingTo('create file with Cept.php suffix');
$I->executeCommand('generate:cept dummy DummyCept.php');
$I->seeFileFound('DummyCept.php');
$I->deleteThisFile();
$I->amGoingTo('create file without any suffix');
$I->executeCommand('generate:cept dummy Dummy');
$I->seeFileFound('DummyCept.php');

View File

@@ -0,0 +1,6 @@
<?php
$I = new CliGuy\GeneratorSteps($scenario);
$I->wantTo('generate sample Cest');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('generate:cest dummy DummyClass');
$I->seeFileWithGeneratedClass('DummyClass');

View File

@@ -0,0 +1,13 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('generate gherkin steps');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('generate:feature scenario Login');
$I->seeInShellOutput('Feature was created');
$I->seeFileFound('Login.feature', 'tests/scenario');
$I->seeInThisFile('Feature: Login');
$I->deleteThisFile();
$I->executeCommand('generate:feature scenario dummy/Login');
$I->seeFileFound('Login.feature', 'tests/scenario/dummy');
$I->seeInThisFile('Feature: Login');

View File

@@ -0,0 +1,9 @@
<?php
$I = new CliGuy\GeneratorSteps($scenario);
$I->wantTo('generate new group');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('generate:group core');
$I->seeFileWithGeneratedClass('Core', 'tests/_support/Group');
$I->seeInThisFile("static \$group = 'core'");
$I->dontSeeInThisFile('public function _before(\Codeception\Event\Test \$e)');
$I->seeFileFound('tests/_bootstrap.php');

View File

@@ -0,0 +1,7 @@
<?php
$I = new CliGuy\GeneratorSteps($scenario);
$I->wantTo('generate helper');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('generate:helper Db');
$I->seeFileWithGeneratedClass('Db', 'tests/_support/Helper');
$I->seeInThisFile('Db extends \Codeception\Module');

View File

@@ -0,0 +1,38 @@
<?php
/**
* @guy CliGuy\GeneratorSteps
*/
class GeneratePageObjectCest
{
public function generateGlobalPageObject(CliGuy\GeneratorSteps $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('generate:page Login');
$I->seeFileWithGeneratedClass('Login', 'tests/_support/Page');
$I->seeInThisFile('static $URL = ');
$I->dontSeeInThisFile('public function __construct(\DumbGuy $I)');
$I->seeFileFound('tests/_bootstrap.php');
}
public function generateSuitePageObject(CliGuy\GeneratorSteps $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('generate:page dummy Login');
$I->seeFileWithGeneratedClass('Login', 'tests/_support/Page/Dummy');
$I->seeInThisFile('namespace Page\\Dummy;');
$I->seeInThisFile('class Login');
$I->seeInThisFile('protected $dumbGuy;');
$I->seeInThisFile('public function __construct(\DumbGuy $I)');
}
public function generateGlobalPageObjectInDifferentPath(CliGuy\GeneratorSteps $I)
{
$I->executeCommand('generate:page Login -c tests/data/sandbox');
$I->amInPath('tests/data/sandbox');
$I->seeFileWithGeneratedClass('Login', 'tests/_support/Page');
$I->seeInThisFile('static $URL = ');
$I->dontSeeInThisFile('public function __construct(\DumbGuy $I)');
$I->seeFileFound('tests/_bootstrap.php');
}
}

View File

@@ -0,0 +1,14 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('generate test scenario');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('generate:scenarios dummy');
$I->seeFileFound('File_Exists.txt', 'tests/_data/scenarios');
$I->seeFileContentsEqual(<<<EOF
I WANT TO CHECK CONFIG EXISTS
I see file found "\$codeception"
EOF
);

View File

@@ -0,0 +1,7 @@
<?php
$I = new CliGuy\GeneratorSteps($scenario);
$I->wantTo('generate step object');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('generate:stepobject dummy Login --silent');
$I->seeFileWithGeneratedClass('Login', 'tests/_support/Step/Dummy');
$I->seeInThisFile('Login extends \DumbGuy');

View File

@@ -0,0 +1,39 @@
<?php
class GenerateSuiteCest
{
public function generateSimpleSuite(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('generate:suite house HouseGuy');
$I->seeFileFound('house.suite.yml', 'tests');
$I->expect('actor class is generated');
$I->seeInThisFile('actor: HouseGuy');
$I->seeInThisFile('- \Helper\House');
$I->seeFileFound('House.php', 'tests/_support/Helper');
$I->seeInThisFile('namespace Helper;');
$I->seeDirFound('tests/house');
$I->seeFileFound('_bootstrap.php', 'tests/house');
$I->expect('suite is not created due to dashes');
$I->executeCommand('generate:suite invalid-dash-suite');
$I->seeInShellOutput('contains invalid characters');
}
public function generateSuiteWithCustomConfig(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('bootstrap --empty src/FooBar --namespace FooBar');
$I->executeCommand('generate:suite house HouseGuy -c src/FooBar');
$I->seeDirFound('src/FooBar/tests/house');
$I->seeFileFound('house.suite.yml', 'src/FooBar/tests');
$I->expect('guy class is generated');
$I->seeInThisFile('actor: HouseGuy');
$I->seeInThisFile('- \FooBar\Helper\House');
$I->seeFileFound('House.php', 'src/FooBar/tests/_support/Helper');
$I->seeInThisFile('namespace FooBar\Helper;');
$I->expect('suite is not created due to dashes');
$I->executeCommand('generate:suite invalid-dash-suite');
$I->seeInShellOutput('contains invalid characters');
}
}

View File

@@ -0,0 +1,9 @@
<?php
$I = new CliGuy\GeneratorSteps($scenario);
$I->wantTo('generate sample Test');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('generate:test dummy Sommy');
$I->seeFileWithGeneratedClass('SommyTest');
$I->seeInThisFile('class SommyTest extends \Codeception\Test\Unit');
$I->seeInThisFile('protected $tester');
$I->seeInThisFile("function _before(");

View File

@@ -0,0 +1,75 @@
<?php
/**
* @group gherkin
*/
class GherkinCest
{
public function _before(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
}
public function steps(CliGuy $I)
{
$I->executeCommand('gherkin:steps scenario');
$I->seeInShellOutput('I have terminal opened');
$I->seeInShellOutput('ScenarioGuy::terminal');
$I->seeInShellOutput('there is a file :name');
$I->seeInShellOutput('I see file :name');
$I->seeInShellOutput('ScenarioGuy::matchFile');
}
public function snippets(CliGuy $I)
{
$I->executeCommand('gherkin:snippets scenario');
$I->seeInShellOutput('@Given I have only idea of what\'s going on here');
$I->seeInShellOutput('public function iHaveOnlyIdeaOfWhatsGoingOnHere');
}
public function snippetsScenarioFile(CliGuy $I)
{
$I->executeCommand('gherkin:snippets scenario FileExamples.feature');
$I->dontSeeInShellOutput('@Given I have only idea of what\'s going on here');
$I->dontSeeInShellOutput('public function iHaveOnlyIdeaOfWhatsGoingOnHere');
}
public function snippetsScenarioFolder(CliGuy $I)
{
$I->executeCommand('gherkin:snippets scenario subfolder');
$I->seeInShellOutput('Given I have a feature in a subfolder');
$I->seeInShellOutput('public function iHaveAFeatureInASubfolder');
$I->dontSeeInShellOutput('@Given I have only idea of what\'s going on here');
$I->dontSeeInShellOutput('public function iHaveOnlyIdeaOfWhatsGoingOnHere');
}
public function snippetsPyStringArgument(CliGuy $I)
{
$I->executeCommand('gherkin:snippets scenario PyStringArgumentExample.feature');
$I->seeInShellOutput('@Given I have PyString argument :arg1');
$I->seeInShellOutput('public function iHavePyStringArgument($arg1)');
$I->dontSeeInShellOutput('public function iSeeOutput($arg1)');
}
public function runIncompletedStepWithPyStringArgument(CliGuy $I)
{
$I->executeCommand('run scenario "PyStringArgumentExample.feature:PyString argument" --steps');
$I->seeInShellOutput('Step definition for `I have PyString argument ""` not found in contexts');
$I->dontSeeInShellOutput('Step definition for `I see output` not found in contexts');
}
public function runSameStepWithInlineAndPyStringArgument(CliGuy $I)
{
$I->executeCommand('run scenario "InlineArgumentExample.feature:Running step with inline argument" --steps');
$I->seeInShellOutput("Argument: test");
$I->executeCommand('run scenario "PyStringArgumentExample.feature:Running step with PyString argument" --steps');
$I->seeInShellOutput("Argument: First line\nSecond line");
}
public function snippetsScenarioUtf8(CliGuy $I)
{
$I->executeCommand('gherkin:snippets scenario Utf8Example.feature');
$I->seeInShellOutput('@Given я написал сценарий на языке :arg1');
$I->seeInShellOutput('public function step_62e20dc62($arg1)');
}
}

View File

@@ -0,0 +1,60 @@
<?php
class GlobalCommandOptionCest
{
public function configOption(CliGuy $I)
{
$I->wantTo("start codeception with --config option");
$I->amInPath('tests/data/register_command/');
$I->executeCommand('--config standard/codeception.yml');
$I->seeInShellOutput('myProject:myCommand');
}
public function configOptionWithEqualSign(CliGuy $I)
{
$I->wantTo("start codeception with --config= option");
$I->amInPath('tests/data/register_command/');
$I->executeCommand('--config=standard/codeception.yml');
$I->seeInShellOutput('myProject:myCommand');
}
public function configOptionShortcut(CliGuy $I)
{
$I->wantTo("start codeception with shortcut -c option");
$I->amInPath('tests/data/register_command/');
$I->executeCommand('-c standard/codeception.yml');
$I->seeInShellOutput('myProject:myCommand');
}
public function configOptionShortcutWithoutSpace(CliGuy $I)
{
$I->wantTo("start codeception with shortcut -c option and not Space");
$I->amInPath('tests/data/register_command/');
$I->executeCommand('-cstandard/codeception.yml');
$I->seeInShellOutput('myProject:myCommand');
}
public function configOptionShortcutWithoutSpaceAndOther(CliGuy $I)
{
$I->wantTo("start codeception with two shortcuts and -c option has not Space");
$I->amInPath('tests/data/register_command/');
$I->executeCommand('-vcstandard/codeception.yml');
$I->seeInShellOutput('version');
}
public function configStartWithoutOption(CliGuy $I)
{
$I->wantTo("start first time codeception without options");
$I->amInPath('tests/data/register_command/');
$I->executeCommand('');
$I->seeInShellOutput('Available commands:');
}
public function configStartWithWrongPath(CliGuy $I)
{
$I->wantTo('start codeception with wrong path to a codeception.yml file');
$I->amInPath('tests/data/register_command/');
$I->executeFailCommand('-c no/exists/codeception.yml');
$I->seeInShellOutput('Your configuration file `no/exists/codeception.yml` could not be found.');
}
}

View File

@@ -0,0 +1,9 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('see that my group events fire only once');
$I->amInPath('tests/data/claypit');
$I->executeCommand('run dummy -g countevents -c codeception_grouped.yml --no-colors');
$I->seeInShellOutput('Group Before Events: 1');
$I->dontSeeInShellOutput('Group Before Events: 2');
$I->seeInShellOutput('Group After Events: 1');
$I->dontSeeInShellOutput('Group After Events: 2');

View File

@@ -0,0 +1,10 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('see that my group extension works');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run skipped -g notorun -c codeception_grouped.yml');
$I->dontSeeInShellOutput("======> Entering NoGroup Test Scope\nMake it incomplete");
$I->dontSeeInShellOutput('<====== Ending NoGroup Test Scope');
$I->executeCommand('run dummy -g ok -c codeception_grouped.yml');
$I->dontSeeInShellOutput("======> Entering Ok Test Scope\nMake it incomplete");
$I->dontSeeInShellOutput('<====== Ending Ok Test Scope');

View File

@@ -0,0 +1,167 @@
<?php
class IncludedCest
{
public function _before()
{
\Codeception\Util\FileSystem::doEmptyDir('tests/data/included/_log');
file_put_contents('tests/data/included/_log/.gitkeep', '');
}
/**
* @param CliGuy $I
*/
protected function moveToIncluded(\CliGuy $I)
{
$I->amInPath('tests/data/included');
}
/**
* @before moveToIncluded
* @param CliGuy $I
*/
public function runSuitesFromIncludedConfigs(\CliGuy $I)
{
$I->executeCommand('run');
$I->seeInShellOutput('[Jazz]');
$I->seeInShellOutput('Jazz.functional Tests');
$I->seeInShellOutput('[Jazz\Pianist]');
$I->seeInShellOutput('Jazz\Pianist.functional Tests');
$I->seeInShellOutput('[Shire]');
$I->seeInShellOutput('Shire.functional Tests');
}
/**
* @before moveToIncluded
* @param CliGuy $I
*/
public function runTestsFromIncludedConfigs(\CliGuy $I)
{
$ds = DIRECTORY_SEPARATOR;
$I->executeCommand("run jazz{$ds}tests{$ds}functional{$ds}DemoCept.php", false);
// Suite is not run
$I->dontSeeInShellOutput('[Jazz]');
// DemoCept tests are run
$I->seeInShellOutput('Jazz.functional Tests');
$I->seeInShellOutput('DemoCept');
// Other include tests are not run
$I->dontSeeInShellOutput('[Shire]');
$I->dontSeeInShellOutput('Shire.functional Tests');
$I->dontSeeInShellOutput('[Jazz\Pianist]');
$I->dontSeeInShellOutput('Jazz\Pianist.functional Tests');
}
/**
* @before moveToIncluded
* @param CliGuy $I
*/
public function runTestsFromIncludedConfigsNested(\CliGuy $I)
{
$I->executeCommand('run jazz/pianist/tests/functional/PianistCept.php', false);
// Suite is not run
$I->dontSeeInShellOutput('[Jazz\Pianist]');
// DemoCept tests are run
$I->seeInShellOutput('Jazz\Pianist.functional Tests');
$I->seeInShellOutput('PianistCept');
// Other include tests are not run
$I->dontSeeInShellOutput('[Shire]');
$I->dontSeeInShellOutput('Shire.functional Tests');
$I->dontSeeInShellOutput('[Jazz]');
$I->dontSeeInShellOutput('Jazz.functional Tests');
}
/**
* @before moveToIncluded
* @param CliGuy $I
*/
public function runTestsFromIncludedConfigsSingleTest(\CliGuy $I)
{
$ds = DIRECTORY_SEPARATOR;
$I->executeCommand("run jazz{$ds}tests{$ds}unit{$ds}SimpleTest.php:testSimple", false);
// Suite is not run
$I->dontSeeInShellOutput('[Jazz]');
// SimpleTest:testSimple is run
$I->seeInShellOutput('Jazz.unit Tests');
$I->dontSeeInShellOutput('Jazz.functional Tests');
$I->seeInShellOutput('SimpleTest');
// SimpleTest:testSimpler is not run
$I->dontSeeInShellOutput('SimplerTest');
// Other include tests are not run
$I->dontSeeInShellOutput('[Shire]');
$I->dontSeeInShellOutput('Shire.functional Tests');
$I->dontSeeInShellOutput('[Jazz\Pianist]');
$I->dontSeeInShellOutput('Jazz\Pianist.functional Tests');
}
/**
* @before moveToIncluded
* @param CliGuy $I
*/
public function runIncludedWithXmlOutput(\CliGuy $I)
{
$I->executeCommand('run --xml');
$I->amInPath('_log');
$I->seeFileFound('report.xml');
$I->seeInThisFile('<testsuite name="Jazz.functional" tests="1" assertions="1"');
$I->seeInThisFile('<testsuite name="Jazz\Pianist.functional" tests="1" assertions="1"');
$I->seeInThisFile('<testsuite name="Shire.functional" tests="1" assertions="1"');
$I->seeInThisFile('<testcase name="Hobbit"');
$I->seeInThisFile('<testcase name="Demo"');
$I->seeInThisFile('<testcase name="Pianist"');
}
/**
* @before moveToIncluded
* @param CliGuy $I
*/
public function runIncludedWithHtmlOutput(\CliGuy $I)
{
$I->executeCommand('run --html');
$I->amInPath('_log');
$I->seeFileFound('report.html');
$I->seeInThisFile('Codeception Results');
$I->seeInThisFile('Jazz.functional Tests');
$I->seeInThisFile('Check that jazz musicians can add numbers');
$I->seeInThisFile('Jazz\Pianist.functional Tests');
$I->seeInThisFile('Check that jazz pianists can add numbers');
$I->seeInThisFile('Shire.functional Tests');
}
/**
* @before moveToIncluded
* @group coverage
* @param CliGuy $I
*/
public function runIncludedWithCoverage(\CliGuy $I)
{
$I->executeCommand('run --coverage-xml');
$I->amInPath('_log');
$I->seeFileFound('coverage.xml');
$I->seeInThisFile('BillEvans" namespace="Jazz\Pianist">');
$I->seeInThisFile('Musician" namespace="Jazz">');
$I->seeInThisFile('Hobbit" namespace="Shire">');
}
/**
* @before moveToIncluded
* @param CliGuy $I
*/
public function buildIncluded(\CliGuy $I)
{
$I->executeCommand('build');
$I->seeInShellOutput('generated successfully');
$I->seeInShellOutput('Jazz\\TestGuy');
$I->seeInShellOutput('Jazz\\Pianist\\TestGuy');
$I->seeInShellOutput('Shire\\TestGuy');
}
}

View File

@@ -0,0 +1,28 @@
<?php
class MixedIncludeCest
{
/**
* @after checkAllSuitesExecuted
* @param CliGuy $I
*/
public function runIncludedSuites(\CliGuy $I)
{
$I->amInPath('tests/data/included_mix');
$I->executeCommand('run');
}
/**
* @after checkAllSuitesExecuted
* @param \CliGuy $I
*/
public function runIncludedSuiteFromCurrentDir(\CliGuy $I)
{
$I->executeCommand('run -c tests/data/included_mix');
}
protected function checkAllSuitesExecuted(\CliGuy $I)
{
$I->seeInShellOutput('AcmePack.unit Tests (1)');
$I->seeInShellOutput('Unit Tests (1)');
}
}

View File

@@ -0,0 +1,117 @@
<?php
class OrderCest
{
public function checkOneFile(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run order LoadingOrderCept.php');
$I->expect('global bootstrap, initialization, beforeSuite, before, bootstrap(B), test(T), after, afterSuite');
$I->seeFileFound('order.txt', 'tests/_output');
$I->seeFileContentsEqual("BIB([ST])");
}
public function checkForFails(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run order FailedCept.php --no-exit');
$I->seeFileFound('order.txt', 'tests/_output');
$I->expect('global bootstrap, initialization, beforeSuite, before, bootstrap, test, fail, after, afterSuite');
$I->seeFileContentsEqual("BIB([STF])");
}
public function checkForCanCantFails(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run order CanCantFailCept.php --no-exit');
$I->seeFileFound('order.txt', 'tests/_output');
$I->expect(
'global bootstrap, initialization, beforeSuite, before, bootstrap, test,'
. ' fail, fail, test, after, afterSuite'
);
$I->seeFileContentsEqual("BIB([STFFT])");
}
public function checkForCanCantFailsInCest(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run order CanCantFailCest.php --no-exit');
$I->seeFileFound('order.txt', 'tests/_output');
$I->expect(
'global bootstrap, initialization, beforeSuite, before, bootstrap, test,'
. ' fail, fail, test, test, fail, fail, test, after, afterSuite'
);
$I->seeFileContentsEqual("BIB([TFT][TFT])");
}
public function checkSimpleFiles(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run order --no-exit --group simple');
$I->seeFileFound('order.txt', 'tests/_output');
$I->seeFileContentsEqual("BIBP({{{{[ST][STFFT][STF][ST]}}}})");
}
public function checkCestOrder(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run tests/order/ReorderCest.php --no-exit');
$I->seeFileFound('order.txt', 'tests/_output');
$I->seeFileContentsEqual("BIB([0123456])");
}
public function checkFailingCestOrder(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run tests/order/FailedCest.php --no-exit -vvv');
$I->seeFileFound('order.txt', 'tests/_output');
$I->seeFileContentsEqual("BIB([a%F])");
}
public function checkCodeceptionTest(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run order CodeTest.php --no-exit');
$I->seeFileFound('order.txt', 'tests/_output');
$I->expect('
global bootstrap,
initialization,
beforeSuite,
beforeClass,
@beforeClass,
bootstrap,
before,
@before
test,
after,
@after,
afterSuite,
afterClass,
@afterClass');
$I->seeFileContentsEqual("BIB({{[<C>]}})");
}
public function checkAfterBeforeClassInTests(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run order BeforeAfterClassTest.php');
$I->seeFileFound('order.txt', 'tests/_output');
$I->seeInThisFile('BIB({[1][2]})');
}
public function checkAfterBeforeClassInTestWithDataProvider(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run order BeforeAfterClassWithDataProviderTest.php');
$I->seeFileFound('order.txt', 'tests/_output');
$I->seeInThisFile('BIB({[A][B][C]})');
}
public function checkBootstrapIsLoadedBeforeTests(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run order ParsedLoadedTest.php');
$I->seeFileFound('order.txt', 'tests/_output');
$I->seeInThisFile('BIBP(T)');
}
}

View File

@@ -0,0 +1,35 @@
<?php
class RegisterCommandCest
{
public function registerCommand(CliGuy $I)
{
$I->amInPath('tests/data/register_command/standard');
$I->executeCommand('list');
$I->seeInShellOutput('myProject:myCommand');
}
public function registerCommandWithConfigurationAtNewPlace(CliGuy $I)
{
$I->amInPath('tests/data/register_command/');
$I->executeCommand('list -c standard/codeception.yml');
$I->seeInShellOutput('myProject:yourCommand');
}
public function startMyCommand(CliGuy $I)
{
$myname = get_current_user();
$I->amInPath('tests/data/register_command/standard');
$I->executeCommand('myProject:myCommand');
$I->seeInShellOutput("Hello {$myname}!");
}
public function startMyCommandWithOptionAndConfigurationAtNewPlace(CliGuy $I)
{
$myname = get_current_user();
$I->amInPath('tests/data/register_command');
$I->executeCommand('myProject:myCommand --config standard/codeception.yml --friendly');
$I->seeInShellOutput("Hello {$myname},");
$I->seeInShellOutput("how are you?");
}
}

View File

@@ -0,0 +1,498 @@
<?php
class RunCest
{
public function _before(\CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
}
public function runOneFile(\CliGuy $I)
{
$I->wantTo('execute one test');
$I->executeCommand('run tests/dummy/FileExistsCept.php');
$I->seeInShellOutput("OK (");
}
public function runOneFileWithColors(\CliGuy $I)
{
$I->wantTo('execute one test');
$I->executeCommand('run --colors tests/dummy/FileExistsCept.php');
$I->seeInShellOutput("OK (");
$I->seeInShellOutput("\033[35;1mFileExistsCept:\033[39;22m Check config exists");
}
/**
* @group reports
* @group core
*
* @param CliGuy $I
*/
public function runHtml(\CliGuy $I)
{
$I->wantTo('execute tests with html output');
$I->executeCommand('run dummy --html');
$I->seeFileFound('report.html', 'tests/_output');
}
/**
* @group reports
*
* @param CliGuy $I
*/
public function runJsonReport(\CliGuy $I)
{
$I->wantTo('check json reports');
$I->executeCommand('run dummy --json');
$I->seeFileFound('report.json', 'tests/_output');
$I->seeInThisFile('"suite":');
$I->seeInThisFile('"dummy"');
$I->assertNotNull(json_decode(file_get_contents('tests/_output/report.json')));
}
/**
* @group reports
*
* @param CliGuy $I
*/
public function runTapReport(\CliGuy $I)
{
$I->wantTo('check tap reports');
$I->executeCommand('run dummy --tap');
$I->seeFileFound('report.tap.log', 'tests/_output');
}
/**
* @group reports
*
* @param CliGuy $I
*/
public function runXmlReport(\CliGuy $I)
{
$I->wantTo('check xml reports');
$I->executeCommand('run dummy --xml');
$I->seeFileFound('report.xml', 'tests/_output');
$I->seeInThisFile('<?xml');
$I->seeInThisFile('<testsuite name="dummy"');
$I->seeInThisFile('<testcase name="FileExists"');
$I->seeInThisFile('feature="');
}
/**
* @group reports
* @param CliGuy $I
*/
public function runXmlReportsInStrictMode(\CliGuy $I)
{
$I->wantTo('check xml in strict mode');
$I->executeCommand('run dummy --xml -c codeception_strict_xml.yml');
$I->seeFileFound('report.xml', 'tests/_output');
$I->seeInThisFile('<?xml');
$I->seeInThisFile('<testsuite name="dummy"');
$I->seeInThisFile('<testcase name="FileExists"');
$I->dontSeeInThisFile('feature="');
}
/**
* @group reports
*
* @param CliGuy $I
*/
public function runCustomReport(\CliGuy $I)
{
if (\PHPUnit\Runner\Version::series() >= 7) {
throw new \Codeception\Exception\Skip('Not for PHPUnit 7');
}
$I->executeCommand('run dummy --report -c codeception_custom_report.yml');
$I->seeInShellOutput('FileExistsCept: Check config exists');
$I->dontSeeInShellOutput('Ok');
}
public function runOneGroup(\CliGuy $I)
{
$I->executeCommand('run skipped -g notorun');
$I->seeInShellOutput('Skipped Tests (1)');
$I->seeInShellOutput("IncompleteMeCept");
$I->dontSeeInShellOutput("SkipMeCept");
}
public function skipRunOneGroup(\CliGuy $I)
{
$I->executeCommand('run skipped --skip-group notorun');
$I->seeInShellOutput('Skipped Tests (2)');
$I->seeInShellOutput("SkipMeCept");
$I->dontSeeInShellOutput("IncompleteMeCept");
}
public function skipGroupOfCest(\CliGuy $I)
{
$I->executeCommand('run dummy');
$I->seeInShellOutput('Optimistic');
$I->seeInShellOutput('Dummy Tests (6)');
$I->executeCommand('run dummy --skip-group ok');
$I->seeInShellOutput('Pessimistic');
$I->seeInShellOutput('Dummy Tests (5)');
$I->dontSeeInShellOutput('Optimistic');
}
public function runTwoSuites(\CliGuy $I)
{
$I->executeCommand('run skipped,dummy --no-exit');
$I->seeInShellOutput("Skipped Tests (3)");
$I->seeInShellOutput("Dummy Tests (6)");
$I->dontSeeInShellOutput("Remote Tests");
}
public function skipSuites(\CliGuy $I)
{
$I->executeCommand(
'run dummy --skip skipped --skip remote --skip remote_server --skip order --skip unit '
. '--skip powers --skip math --skip messages'
);
$I->seeInShellOutput("Dummy Tests");
$I->dontSeeInShellOutput("Remote Tests");
$I->dontSeeInShellOutput("Remote_server Tests");
$I->dontSeeInShellOutput("Order Tests");
}
public function runOneTestFromUnit(\CliGuy $I)
{
$I->executeCommand('run tests/dummy/AnotherTest.php:testFirst');
$I->seeInShellOutput("AnotherTest: First");
$I->seeInShellOutput('OK');
$I->dontSeeInShellOutput('AnotherTest: Second');
}
public function runOneTestFromCest(\CliGuy $I)
{
$I->executeCommand('run tests/dummy/AnotherCest.php:optimistic');
$I->seeInShellOutput("Optimistic");
$I->dontSeeInShellOutput('Pessimistic');
}
public function runTestWithDataProviders(\CliGuy $I)
{
$I->executeCommand('run tests/unit/DataProvidersTest.php');
$I->seeInShellOutput('Is triangle | "real triangle"');
$I->seeInShellOutput('Is triangle | #0');
$I->seeInShellOutput('Is triangle | #1');
$I->seeInShellOutput('DataProvidersTest');
$I->seeInShellOutput("OK");
}
public function runOneGroupWithDataProviders(\CliGuy $I)
{
$I->executeCommand('run unit -g data-providers');
$I->seeInShellOutput('Is triangle | "real triangle"');
$I->seeInShellOutput('Is triangle | #0');
$I->seeInShellOutput('Is triangle | #1');
$I->seeInShellOutput('DataProvidersTest');
$I->seeInShellOutput("OK");
}
public function runTestWithFailFast(\CliGuy $I)
{
$I->executeCommand('run unit --skip-group error --no-exit');
$I->seeInShellOutput('FailingTest: Me');
$I->seeInShellOutput("PassingTest: Me");
$I->executeCommand('run unit --fail-fast --skip-group error --no-exit');
$I->seeInShellOutput('There was 1 failure');
$I->dontSeeInShellOutput("PassingTest: Me");
}
public function runWithCustomOutputPath(\CliGuy $I)
{
$I->executeCommand('run dummy --xml myverycustom.xml --html myownhtmlreport.html');
$I->seeFileFound('myverycustom.xml', 'tests/_output');
$I->seeInThisFile('<?xml');
$I->seeInThisFile('<testsuite name="dummy"');
$I->seeInThisFile('<testcase name="FileExists"');
$I->seeFileFound('myownhtmlreport.html', 'tests/_output');
$I->dontSeeFileFound('report.xml', 'tests/_output');
$I->dontSeeFileFound('report.html', 'tests/_output');
}
public function runTestsWithDependencyInjections(\CliGuy $I)
{
$I->executeCommand('run math');
$I->seeInShellOutput('MathCest: Test addition');
$I->seeInShellOutput('MathCest: Test subtraction');
$I->seeInShellOutput('MathCest: Test square');
$I->seeInShellOutput('MathTest: All');
$I->seeInShellOutput('OK (');
$I->dontSeeInShellOutput('fail');
$I->dontSeeInShellOutput('error');
}
public function runErrorTest(\CliGuy $I)
{
$I->executeCommand('run unit ErrorTest --no-exit');
$I->seeInShellOutput('There was 1 error');
$I->seeInShellOutput('Array to string conversion');
$I->seeInShellOutput('ErrorTest.php');
}
public function runTestWithException(\CliGuy $I)
{
$I->executeCommand('run unit ExceptionTest --no-exit -v');
$I->seeInShellOutput('There was 1 error');
$I->seeInShellOutput('Helllo!');
$I->expect('Exceptions are not wrapped into ExceptionWrapper');
$I->dontSeeInShellOutput('PHPUnit_Framework_ExceptionWrapper');
$I->seeInShellOutput('RuntimeException');
}
public function runTestsWithSteps(\CliGuy $I)
{
$I->executeCommand('run scenario SuccessCept --steps');
$I->seeInShellOutput(<<<EOF
Scenario --
I am in path "."
I see file found "scenario.suite.yml"
PASSED
EOF
);
}
/**
* @param CliGuy $I
*/
public function runTestWithFailedScenario(\CliGuy $I, $scenario)
{
if (!extension_loaded('xdebug') && !defined('HHVM_VERSION')) {
$scenario->skip("Xdebug not loaded");
}
$I->executeCommand('run scenario FailedCept --steps --no-exit');
$I->seeInShellOutput(<<<EOF
FailedCept: Fail when file is not found
Signature: FailedCept
Test: tests/scenario/FailedCept.php
Scenario --
I am in path "."
I see file found "games.zip"
FAIL
EOF
);
$I->expect('to see scenario trace');
$I->seeInShellOutput(<<<EOF
Scenario Steps:
2. \$I->seeFileFound("games.zip") at tests/scenario/FailedCept.php:5
1. \$I->amInPath(".") at tests/scenario/FailedCept.php:4
EOF
);
}
/**
* @param CliGuy $I
*/
public function runTestWithSubSteps(\CliGuy $I, $scenario)
{
if (!extension_loaded('xdebug') && !defined('HHVM_VERSION')) {
$scenario->skip("Xdebug not loaded");
}
$file = "codeception" . DIRECTORY_SEPARATOR . "c3";
$I->executeCommand('run scenario SubStepsCept --steps');
$I->seeInShellOutput(<<<EOF
Scenario --
I am in path "."
I see code coverage files are present
EOF
);
// I split this assertion into two, because extra space is printed after "present" on HHVM
$I->seeInShellOutput(<<<EOF
I see file found "c3.php"
I see file found "composer.json"
I see in this file "$file"
EOF
);
}
public function runDependentCest(CliGuy $I)
{
$I->executeCommand('run order DependentCest --no-exit');
$I->seeInShellOutput('Skipped: 1');
}
public function runDependentTest(CliGuy $I)
{
$I->executeCommand('run unit DependsTest --no-exit');
$I->seeInShellOutput('Skipped: 1');
$I->executeCommand('run unit --no-exit');
$I->seeInShellOutput('Skipped: 2');
}
public function runGherkinTest(CliGuy $I)
{
$I->executeCommand('run scenario File.feature --steps');
$I->seeInShellOutput(<<<EOF
In order to test a feature
As a user
I need to be able to see output
EOF
);
$I->seeInShellOutput('Given i have terminal opened');
$I->seeInShellOutput('When i am in current directory');
$I->seeInShellOutput('Then there is a file "scenario.suite.yml"');
$I->seeInShellOutput('And there are keywords in "scenario.suite.yml"');
$I->seeInShellOutput(<<<EOF
| class_name | ScenarioGuy |
| enabled | Filesystem |
EOF
);
$I->seeInShellOutput('PASSED');
}
public function reportsCorrectFailedStep(CliGuy $I)
{
$I->executeCommand('run scenario File.feature -v');
$I->seeInShellOutput('OK, but incomplete');
$I->seeInShellOutput('Step definition for `I have only idea of what\'s going on here` not found in contexts');
}
public function runFailingGherkinTest(CliGuy $I)
{
$I->executeCommand('run scenario Fail.feature -v --no-exit');
$I->seeInShellOutput('Step I see file "games.zip"');
$I->seeInShellOutput('Step I see file "tools.zip"');
}
public function runGherkinScenarioWithMultipleStepDefinitions(CliGuy $I)
{
$I->executeCommand('run scenario "File.feature:Check file once more" --steps');
$I->seeInShellOutput('When there is a file "scenario.suite.yml"');
$I->seeInShellOutput('Then i see file "scenario.suite.yml"');
$I->dontSeeInShellOutput('Step definition for `I see file "scenario.suite.yml"` not found in contexts');
$I->seeInShellOutput('PASSED');
}
public function runGherkinScenarioOutline(CliGuy $I)
{
$I->executeCommand('run scenario FileExamples.feature -v');
$I->seeInShellOutput('OK (3 tests');
}
/**
* @param CliGuy $I
* @after checkExampleFiles
*/
public function runTestWithAnnotationExamples(CliGuy $I)
{
$I->executeCommand('run scenario ExamplesCest:filesExistsAnnotation --steps');
}
/**
* @param CliGuy $I
* @after checkExampleFiles
*/
public function runTestWithJsonExamples(CliGuy $I)
{
$I->executeCommand('run scenario ExamplesCest:filesExistsByJson --steps');
}
/**
* @param CliGuy $I
* @after checkExampleFiles
*/
public function runTestWithArrayExamples(CliGuy $I)
{
$I->executeCommand('run scenario ExamplesCest:filesExistsByArray --steps');
}
protected function checkExampleFiles(CliGuy $I)
{
$I->seeInShellOutput('OK (3 tests');
$I->seeInShellOutput('I see file found "scenario.suite.yml"');
$I->seeInShellOutput('I see file found "dummy.suite.yml"');
$I->seeInShellOutput('I see file found "unit.suite.yml"');
}
public function runTestWithComplexExample(CliGuy $I)
{
$I->executeCommand('run scenario ExamplesCest:filesExistsComplexJson --debug');
$I->seeInShellOutput('Files exists complex json | {"path":"."');
$I->seeInShellOutput('OK (1 test');
$I->seeInShellOutput('I see file found "scenario.suite.yml"');
$I->seeInShellOutput('I see file found "dummy.suite.yml"');
$I->seeInShellOutput('I see file found "unit.suite.yml"');
}
public function overrideConfigOptionsToChangeReporter(CliGuy $I)
{
if (!class_exists('PHPUnit_Util_Log_TeamCity')) {
throw new \Codeception\Exception\Skip('Reporter does not exist for this PHPUnit version');
}
$I->executeCommand('run scenario --report -o "reporters: report: PHPUnit_Util_Log_TeamCity" --no-exit');
$I->seeInShellOutput('##teamcity[testStarted');
$I->dontSeeInShellOutput('............Ok');
}
public function overrideModuleOptions(CliGuy $I)
{
$I->executeCommand('run powers PowerIsRisingCept --no-exit');
$I->seeInShellOutput('FAILURES');
$I->executeCommand('run powers PowerIsRisingCept -o "modules: config: PowerHelper: has_power: true" --no-exit');
$I->dontSeeInShellOutput('FAILURES');
}
public function runTestWithAnnotationExamplesFromGroupFileTest(CliGuy $I)
{
$I->executeCommand('run scenario -g groupFileTest1 --steps');
$I->seeInShellOutput('OK (3 tests');
}
public function testsWithConditionalFails(CliGuy $I)
{
$I->executeCommand('run scenario ConditionalCept --no-exit');
$I->seeInShellOutput('There were 3 failures');
$I->seeInShellOutput('Fail File "not-a-file" not found');
$I->seeInShellOutput('Fail File "not-a-dir" not found');
$I->seeInShellOutput('Fail File "nothing" not found');
}
public function runTestWithAnnotationDataprovider(CliGuy $I)
{
$I->executeCommand('run scenario -g dataprovider --steps');
$I->seeInShellOutput('OK (15 tests');
}
public function runFailedTestAndCheckOutput(CliGuy $I)
{
$I->executeCommand('run scenario FailedCept', false);
$testPath = implode(DIRECTORY_SEPARATOR, ['tests', 'scenario', 'FailedCept.php']);
$I->seeInShellOutput('1) FailedCept: Fail when file is not found');
$I->seeInShellOutput('Test ' . $testPath);
$I->seeInShellOutput('Step See file found "games.zip"');
$I->seeInShellOutput('Fail File "games.zip" not found at ""');
}
public function runTestWithCustomSetupMethod(CliGuy $I)
{
$I->executeCommand('run powers PowerUpCest');
$I->dontSeeInShellOutput('FAILURES');
}
public function runCestWithTwoFailedTest(CliGuy $I)
{
$I->executeCommand('run scenario PartialFailedCest', false);
$I->seeInShellOutput('See file found "testcasetwo.txt"');
$I->seeInShellOutput('See file found "testcasethree.txt"');
$I->seeInShellOutput('Tests: 3,');
$I->seeInShellOutput('Failures: 2.');
}
public function runWarningTests(CliGuy $I)
{
$I->executeCommand('run unit WarningTest.php', false);
$I->seeInShellOutput('There was 1 warning');
$I->seeInShellOutput('WarningTest::testWarningInvalidDataProvider');
$I->seeInShellOutput('Tests: 1,');
$I->seeInShellOutput('Warnings: 1.');
}
}

View File

@@ -0,0 +1,128 @@
<?php
class RunEnvironmentCest
{
public function testDevEnvironment(CliGuy $I)
{
$I->wantTo('execute test in --dev environment');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run dummy --env=dev');
$I->seeInShellOutput("OK (");
}
public function testProdEnvironment(CliGuy $I)
{
$I->wantTo('execute test in non existent --prod environment');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run dummy --env=prod');
$I->dontSeeInShellOutput("OK (");
$I->seeInShellOutput("No tests executed");
}
public function testEnvironmentParams(CliGuy $I)
{
$I->wantTo('execute check that env params applied');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run powers PowerIsRisingCept.php --env=dev -vv --steps');
$I->seeInShellOutput('I got the power');
$I->seeInShellOutput("PASSED");
$I->seeInShellOutput("OK (");
}
public function testWithoutEnvironmentParams(CliGuy $I)
{
$I->wantTo('execute check that env params applied');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run powers PowerIsRisingCept.php -vv --no-exit');
$I->seeInShellOutput("I have no power");
$I->seeInShellOutput("FAIL");
}
public function runTestForSpecificEnvironment(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run powers MageGuildCest.php --env whisky');
$I->seeInShellOutput('MageGuildCest: Red label');
$I->seeInShellOutput('MageGuildCest: Black label');
$I->seeInShellOutput('MageGuildCest: Power of the universe');
$I->seeInShellOutput('OK (3 tests, 3 assertions)');
}
public function runTestForNotIncludedEnvironment(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run powers MageGuildCest.php --env dev');
$I->seeInShellOutput('MageGuildCest: Power of the universe');
$I->seeInShellOutput('OK (1 test, 1 assertion)');
}
public function testEnvFileLoading(CliGuy $I)
{
$I->wantTo('test that env configuration files are loaded correctly');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run messages MessageCest.php:allMessages -vv --env env2');
$I->seeInShellOutput('message1: MESSAGE1 FROM ENV2-DIST.');
$I->seeInShellOutput('message2: MESSAGE2 FROM ENV2.');
$I->seeInShellOutput('message3: MESSAGE3 FROM SUITE.');
$I->seeInShellOutput('message4: DEFAULT MESSAGE4.');
}
public function testEnvMerging(CliGuy $I)
{
$I->wantTo('test that given environments are merged properly');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run messages MessageCest.php:allMessages -vv --env env1,env2');
$I->seeInShellOutput('message1: MESSAGE1 FROM ENV2-DIST.');
$I->seeInShellOutput('message4: MESSAGE4 FROM SUITE-ENV1.');
$I->executeCommand('run messages MessageCest.php:allMessages -vv --env env2,env1');
$I->seeInShellOutput('message1: MESSAGE1 FROM SUITE-ENV1.');
$I->seeInShellOutput('message4: MESSAGE4 FROM SUITE-ENV1.');
}
public function runTestForMultipleEnvironments(CliGuy $I)
{
$I->wantTo('check that multiple required environments are taken into account');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run messages MessageCest.php:multipleEnvRequired -vv --env env1');
$I->dontSeeInShellOutput('Multiple env given');
$I->executeCommand('run messages MessageCest.php:multipleEnvRequired -vv --env env2');
$I->dontSeeInShellOutput('Multiple env given');
$I->executeCommand('run messages MessageCest.php:multipleEnvRequired -vv --env env1,env2');
$I->seeInShellOutput('Multiple env given');
$I->executeCommand('run messages MessageCest.php:multipleEnvRequired -vv --env env2,env1');
$I->seeInShellOutput('Multiple env given');
}
public function generateEnvConfig(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('g:env firefox');
$I->seeInShellOutput('firefox config was created');
$I->seeFileFound('tests/_envs/firefox.yml');
}
public function runEnvironmentForCept(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run messages --env email');
$I->seeInShellOutput('Test emails');
$I->dontSeeInShellOutput('Multiple env given');
$I->executeCommand('run messages --env env1');
$I->dontSeeInShellOutput('Test emails');
}
public function showExceptionForUnconfiguredEnvironment(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run skipped NoEnvironmentCept --no-exit');
$I->seeInShellOutput("Environment nothing was not configured but used");
$I->seeInShellOutput('WARNING');
}
public function environmentsFromSubfolders(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run messages MessageCest.php:allMessages -vv --env env3');
$I->seeInShellOutput('MESSAGE2 FROM ENV3');
}
}

View File

@@ -0,0 +1,7 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('execute incomplete test');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run skipped IncompleteMeCept.php');
$I->seeInShellOutput("I IncompleteMeCept: Make it incomplete");
$I->seeInShellOutput('OK, but incomplete, skipped, or risky tests!');

View File

@@ -0,0 +1,16 @@
<?php
class RunSingleTestWithIncludeCest
{
public function run(\CliGuy $I)
{
$I->amInPath('tests/data/single_test_with_include');
$I->wantTo('execute one test with include in config');
$I->executeCommand('run unit/ExampleCest.php');
$I->seeResultCodeIs(0);
$I->dontSeeInShellOutput('RuntimeException');
$I->dontSeeInShellOutput('could not be found');
}
}

View File

@@ -0,0 +1,8 @@
<?php
$I = new CliGuy($scenario);
$I->wantTo('run skipped test');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run skipped SkipMeCept.php');
$I->seeInShellOutput("S SkipMeCept: Skip it");
$I->seeInShellOutput('OK, but incomplete, skipped, or risky tests!');
$I->seeInShellOutput('run with `-v` to get more info');

View File

@@ -0,0 +1,28 @@
<?php
class SecondTestIsExecutedWhenTheFirstTestFailsCest
{
public function testIsExecuted(CliGuy $I)
{
$I->wantTo('see that the second test is executed');
$I->amInPath('tests/data/first_test_fails');
$I->executeFailCommand('run --xml --no-ansi');
$I->seeInShellOutput('Tests: 2, Assertions: 1, Errors: 1');
$I->seeInShellOutput('E twoTestsCest: Failing');
$I->seeInShellOutput('+ twoTestsCest: Successful');
}
public function endTestEventIsEmitted(CliGuy $I)
{
if (\PHPUnit\Runner\Version::series() >= 7) {
throw new \Codeception\Exception\Skip('Not for PHPUnit 7');
}
$I->wantTo('see that all start and end events are emitted');
$I->amInPath('tests/data/first_test_fails');
$I->executeFailCommand('run --xml --no-ansi --report -o "reporters: report: CustomReporter"');
$I->seeInShellOutput('STARTED: twoTestsCest: Failing');
$I->seeInShellOutput('ENDED: twoTestsCest: Failing');
$I->seeInShellOutput('STARTED: twoTestsCest: Successful');
$I->seeInShellOutput('ENDED: twoTestsCest: Successful');
}
}

View File

@@ -0,0 +1,19 @@
<?php
$testsPath = __DIR__ . '/../';
$I = new CliGuy($scenario);
$I->wantTo('generate xml reports for unit tests');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run unit --xml --no-exit');
$I->seeFileFound('report.xml', 'tests/_output');
$I->seeInThisFile('<?xml');
$I->seeInThisFile('<testsuite name="unit"');
$I->seeInThisFile('<testcase name="testMe" class="PassingTest"');
$I->seeInThisFile('<testcase name="testIsTriangle with data set #0" class="DataProvidersTest" '.
'file="' . realpath($testsPath . '/data/sandbox/tests/unit/DataProvidersTest.php') .'" ');
$I->seeInThisFile('<testcase name="testOne" class="DependsTest"');
if (!class_exists('PHPUnit_Framework_ExpectationFailedException')) {
$I->seeInThisFile('<failure type="PHPUnit\Framework\ExpectationFailedException">FailingTest::testMe');
} else {
$I->seeInThisFile('<failure type="PHPUnit_Framework_ExpectationFailedException">FailingTest::testMe');
}

View File

@@ -0,0 +1,34 @@
<?php
class WildcardIncludeCest
{
/**
* @after checkAllSuitesExecuted
* @param CliGuy $I
*/
public function runIncludedSuites(\CliGuy $I)
{
$I->amInPath('tests/data/included_w');
$I->executeCommand('run');
}
/**
* @after checkAllSuitesExecuted
* @param \CliGuy $I
*/
public function runIncludedSuiteFromCurrentDir(\CliGuy $I)
{
$I->executeCommand('run -c tests/data/included_w');
}
protected function checkAllSuitesExecuted(\CliGuy $I)
{
$I->seeInShellOutput('[ToastPack]');
$I->seeInShellOutput('ToastPack.unit Tests');
$I->seeInShellOutput('[EwokPack]');
$I->seeInShellOutput('EwokPack.unit Tests');
$I->seeInShellOutput('[AcmePack]');
$I->seeInShellOutput('AcmePack.unit Tests');
$I->dontSeeInShellOutput('[Spam]');
$I->dontSeeInShellOutput('[SpamPack]');
}
}

View File

@@ -0,0 +1,2 @@
<?php
\Codeception\Util\Autoload::addNamespace('CliGuy', __DIR__.DIRECTORY_SEPARATOR.'_steps');

View File

@@ -0,0 +1,19 @@
<?php
namespace CliGuy;
class GeneratorSteps extends \CliGuy
{
public function seeFileWithGeneratedClass($class, $path = '')
{
$I = $this;
$I->seeFileFound($class.'.php', $path);
$I->seeInThisFile('class '.$class);
}
public function seeAutoloaderWasAdded($prefix, $path)
{
$I = $this;
$I->seeFileFound('_bootstrap.php', $path);
$I->seeInThisFile("\\Codeception\\Util\\Autoload::addNamespace('$prefix', __DIR__.DIRECTORY_SEPARATOR.");
}
}

View File

@@ -0,0 +1,3 @@
class_name: CoverGuy
modules:
enabled: [Filesystem, Cli, CliHelper, CoverHelper]

View File

@@ -0,0 +1,12 @@
<?php
$I = new CoverGuy($scenario);
$I->wantTo('run local code coverage for cest and test');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run math MathTest --coverage');
$I->seeInShellOutput('Classes: 100.00%');
$I->seeInShellOutput('Methods: 100.00%');
$I->amGoingTo('run local codecoverage in cest');
$I->executeCommand('run math MathCest --coverage');
$I->seeInShellOutput('Classes: 100.00%');
$I->seeInShellOutput('Methods: 100.00%');

View File

@@ -0,0 +1,6 @@
<?php
$I = new CoverGuy($scenario);
$I->wantTo('try generate remote codecoverage xml report');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run remote_server --coverage-html remote_server');
$I->seeFileFound('index.html', 'tests/_output/remote_server');

View File

@@ -0,0 +1,7 @@
<?php
$I = new CoverGuy($scenario);
$I->wantTo('try generate remote codecoverage xml report');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run remote_server --coverage-xml remote_server.xml');
$I->seeFileFound('remote_server.xml', 'tests/_output');
$I->seeInThisFile('coverage generated');

View File

@@ -0,0 +1,8 @@
<?php
$I = new CoverGuy($scenario);
$I->wantTo('try generate remote crap4j xml report');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run remote --coverage-crap4j');
$I->seeInShellOutput('Crap4j report generated in crap4j.xml');
$I->seeFileFound('crap4j.xml', 'tests/_output');
#$I->seeCoverageStatsNotEmpty();

View File

@@ -0,0 +1,9 @@
<?php
$I = new CoverGuy($scenario);
$I->wantTo('try generate codecoverage xml report with environment');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run remote --coverage-xml --env default');
$I->seeInShellOutput('Code Coverage Report');
$I->dontSeeInShellOutput('RemoteException');
$I->seeFileFound('coverage.xml', 'tests/_output');
$I->seeCoverageStatsNotEmpty();

View File

@@ -0,0 +1,7 @@
<?php
$I = new CoverGuy($scenario);
$I->wantTo('try generate remote codecoverage xml report');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run remote --coverage-html');
$I->seeFileFound('index.html', 'tests/_output/coverage');
$I->seeCoverageStatsNotEmpty();

View File

@@ -0,0 +1,8 @@
<?php
$I = new CoverGuy($scenario);
$I->wantTo('try generate remote codecoverage phpunit report');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run remote --coverage-phpunit');
$I->seeFileFound('index.xml', 'tests/_output/coverage-phpunit');
$I->seeCoverageStatsNotEmpty();

View File

@@ -0,0 +1,7 @@
<?php
$I = new CoverGuy($scenario);
$I->wantTo('try generate remote codecoverage text report');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run remote --coverage-text');
$I->seeFileFound('coverage.txt', 'tests/_output');
$I->seeCoverageStatsNotEmpty();

View File

@@ -0,0 +1,8 @@
<?php
$I = new CoverGuy($scenario);
$I->wantTo('try generate remote codecoverage xml report');
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run remote --coverage-xml');
$I->seeInShellOutput('Code Coverage Report');
$I->seeFileFound('coverage.xml', 'tests/_output');
$I->seeCoverageStatsNotEmpty();

View File

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

View File

@@ -0,0 +1,2 @@
*.db
*.db_snapshot

View File

@@ -0,0 +1,67 @@
<?php
class DummyClass
{
protected $checkMe = 1;
protected $properties = array('checkMeToo' => 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 getCheckMeToo() {
return $this->checkMeToo;
}
public function call() {
$this->targetMethod();
return true;
}
public function targetMethod() {
return true;
}
public function exceptionalMethod() {
throw new Exception('Catch it!');
}
public function __set($name, $value) {
if ($this->isMagical($name)) {
$this->properties[$name] = $value;
}
}
public function __get($name) {
if ($this->__isset($name)) {
return $this->properties[$name];
}
}
public function __isset($name) {
return $this->isMagical($name) && isset($this->properties[$name]);
}
private function isMagical($name) {
$reflectionClass = new \ReflectionClass($this);
return !$reflectionClass->hasProperty($name);
}
}

View File

@@ -0,0 +1,68 @@
<?php
class DummyOverloadableClass
{
protected $checkMe = 1;
protected $properties = array('checkMeToo' => 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 getCheckMeToo() {
return $this->checkMeToo;
}
public function call() {
$this->targetMethod();
return true;
}
public function targetMethod() {
return true;
}
public function exceptionalMethod() {
throw new Exception('Catch it!');
}
public function __get($name) {
//seeing as we're not implementing __set here, add check for __mocked
$return = null;
if ($name === '__mocked') {
$return = isset($this->__mocked) ? $this->__mocked : null;
} else {
if ($this->__isset($name)) {
$return = $this->properties[$name];
}
}
return $return;
}
public function __isset($name) {
return $this->isMagical($name) && isset($this->properties[$name]);
}
private function isMagical($name) {
$reflectionClass = new \ReflectionClass($this);
return !$reflectionClass->hasProperty($name);
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace FailDependenciesCyclic;
class IncorrectDependenciesClass
{
public function _inject(AnotherClass $a) {}
}
class AnotherClass
{
public function _inject(IncorrectDependenciesClass $a) {}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace FailDependenciesInChain;
class IncorrectDependenciesClass
{
public function _inject(AnotherClass $a) {}
}
class AnotherClass
{
private function __construct() {}
}

View File

@@ -0,0 +1,7 @@
<?php
namespace FailDependenciesNonExistent;
class IncorrectDependenciesClass
{
public function _inject(NonExistentClass $a) {}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace FailDependenciesPrimitiveParam;
class IncorrectDependenciesClass
{
public function _inject(AnotherClass $a, $optional = 'default', $anotherOptional = 123) {}
}
class AnotherClass
{
public function _inject($required) {}
}

View File

@@ -0,0 +1,2 @@
<?php
$I do nothing here

View File

@@ -0,0 +1,13 @@
<?php
class SimpleAdminGroupCest
{
/**
* @group admin
*/
function testAdminGroup()
{
}
}

View File

@@ -0,0 +1,3 @@
<?php
$I = new CodeGuy($scenario);
$I->wantTo('drink beer, actually...');

View File

@@ -0,0 +1,18 @@
<?php
class SimpleCest
{
public $class = 'DummyClass';
public function helloWorld(\CodeGuy $I) {
$I->execute(function() { return 2+2; })
->seeResultEquals('4');
}
public function goodByeWorld(\CodeGuy $I) {
$I->execute(function() { return 2+2; })
->seeResultNotEquals('3');
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Also test multiple namespaces/classes per single file.
*/
namespace SimpleA {
class SimpleTest extends \Codeception\Test\Unit
{
public function testFoo() {
return true;
}
public function testBar() {
return true;
}
}
}
namespace SimpleB {
class SimpleTest extends \Codeception\Test\Unit
{
public function testBaz() {
return true;
}
}
}

View File

@@ -0,0 +1,8 @@
<?php
class SampleTest extends \PHPUnit\Framework\TestCase
{
public function testOfTest() {
$this->assertTrue(true);
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace simpleDI {
use \simpleDIHelpers\NeededHelper as Needed;
class LoadedTestWithDependencyInjectionCest
{
public $a;
public function __construct($optional = 'abc') {}
public function _inject(Needed $a) { $this->a = $a; }
public function testOne() {}
public function testTwo() {}
}
abstract class SkippedAbstractCest
{
public function testNothing() {}
}
class SkippedWithPrivateConstructorCest
{
private function __construct() {}
public function testNothing() {}
}
class AnotherCest
{
public function testSome() {}
}
}
namespace simpleDIHelpers {
class NeededHelper
{
public function _inject(AnotherHelper $a, YetAnotherHelper $b, $optionalParam = 123) {}
}
class AnotherHelper
{
public function __construct() {}
}
class YetAnotherHelper
{
public function __construct() {}
}
}

View File

@@ -0,0 +1,11 @@
<?php
class SimpleWithNoClassCest
{
public function phpFuncitons(CodeGuy $I) {
$I->execute(function() { return strtoupper('hello'); });
$I->seeResultEquals('HELLO');
}
}

View File

@@ -0,0 +1,4 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php

Binary file not shown.

View File

@@ -0,0 +1,272 @@
<?php
class index {
function GET($matches) {
include __DIR__.'/view/index.php';
}
function POST($matches) {
include __DIR__.'/view/index.php';
}
}
class info {
function GET() {
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) data::set('ajax',array('GET'));
data::set('params', $_GET);
include __DIR__.'/view/info.php';
}
}
class redirect {
function GET() {
header('Location: /info');
}
}
class redirect4 {
function GET() {
header('Location: /search?ln=test@gmail.com&sn=testnumber');
}
}
class redirect_relative {
function GET() {
header('Location: info');
}
}
class redirect2 {
function GET() {
include __DIR__.'/view/redirect2.php';
}
}
class redirect3 {
function GET() {
header('Refresh:0;url=/info');
}
}
class redirect_twice {
function GET() {
header('Location: /redirect3');
}
}
class redirect_params {
function GET() {
include __DIR__.'/view/redirect_params.php';
}
}
class redirect_interval {
function GET() {
include __DIR__.'/view/redirect_interval.php';
}
}
class redirect_meta_refresh {
function GET() {
include __DIR__.'/view/redirect_meta_refresh.php';
}
}
class redirect_header_interval {
function GET() {
include __DIR__.'/view/index.php';
header('Refresh:1800;url=/info');
}
}
class redirect_base_uri_has_path {
function GET() {
header('Refresh:0;url=/somepath/info');
}
}
class redirect_base_uri_has_path_302 {
function GET() {
header('Location: /somepath/info', true, 302);
}
}
class location_201 {
function GET() {
header('Location: /info', true, 201);
}
}
class external_url {
function GET() {
include __DIR__ . '/view/external_url.php';
}
}
class login {
function GET($matches) {
include __DIR__.'/view/login.php';
}
function POST() {
data::set('form', $_POST);
include __DIR__.'/view/login.php';
}
}
class cookies {
function GET($matches) {
if (isset($_COOKIE['foo']) && $_COOKIE['foo'] === 'bar1') {
if (isset($_COOKIE['baz']) && $_COOKIE['baz'] === 'bar2') {
header('Location: /info');
}
} else {
include __DIR__.'/view/cookies.php';
}
}
function POST() {
setcookie('f', 'b', time() + 60, null, null, false, true);
setcookie('foo', 'bar1', time() + 60, null, 'sub.localhost', false, true);
setcookie('baz', 'bar2', time() + 60, null, 'sub.localhost', false, true);
data::set('form', $_POST);
include __DIR__.'/view/cookies.php';
}
}
class cookiesHeader {
public function GET()
{
header("Set-Cookie: a=b;Path=/;");
header("Set-Cookie: c=d;Path=/;", false);
include __DIR__.'/view/index.php';
}
}
class iframe {
public function GET()
{
include __DIR__.'/view/iframe.php';
}
}
class facebookController {
function GET($matches) {
include __DIR__.'/view/facebook.php';
}
}
class form {
function GET($matches) {
data::set('query', $_GET);
$url = strtolower($matches[1]);
if (empty($matches[1])) {
$url = 'index';
}
include __DIR__.'/view/form/'.$url.'.php';
}
function POST() {
data::set('query', $_GET);
data::set('form', $_POST);
data::set('files', $_FILES);
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
data::set('ajax','post');
}
$notice = 'Thank you!';
include __DIR__.'/view/index.php';
}
}
class articles {
function DELETE() {
}
function PUT() {
}
}
class search {
function GET($matches) {
$result = null;
if (isset($_GET['searchQuery']) && $_GET['searchQuery'] == 'test') {
$result = 'Success';
}
data::set('params', $_GET);
include __DIR__.'/view/search.php';
}
}
class httpAuth {
function GET() {
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="test"');
header('HTTP/1.0 401 Unauthorized');
echo 'Unauthorized';
return;
}
if ($_SERVER['PHP_AUTH_PW'] == 'password') {
echo "Welcome, " . $_SERVER['PHP_AUTH_USER'];
return;
}
echo "Forbidden";
}
}
class register {
function GET() {
include __DIR__.'/view/register.php';
}
function POST() {
$this->GET();
}
}
class contentType1 {
function GET() {
header('Content-Type:', true);
include __DIR__.'/view/content_type.php';
}
}
class contentType2 {
function GET() {
header('Content-Type:', true);
include __DIR__.'/view/content_type2.php';
}
}
class unsetCookie {
function GET() {
header('Set-Cookie: a=; Expires=Thu, 01 Jan 1970 00:00:01 GMT');
}
}
class basehref {
function GET() {
include __DIR__.'/view/basehref.php';
}
}
class jserroronload {
function GET() {
include __DIR__.'/view/jserroronload.php';
}
}
class userAgent {
function GET() {
echo $_SERVER['HTTP_USER_AGENT'];
}
}
class minimal {
function GET() {
include __DIR__.'/view/minimal.php';
}
}

View File

@@ -0,0 +1,42 @@
<?php
class data {
public static $filename = '/db';
public static function get($key) {
$data = self::load();
return $data[$key];
}
public static function set($key, $value)
{
$data = self::load();
$data[$key] = $value;
self::save($data);
}
public static function remove($key)
{
$data = self::load();
unset($data[$key]);
self::save($data);
}
public static function clean()
{
self::save(array());
}
protected static function load()
{
$data = file_get_contents(__DIR__.self::$filename);
$data = $data ? unserialize($data) : $data = array();
if (!is_array($data)) $data = array();
return $data;
}
protected static function save($data)
{
file_put_contents(__DIR__.self::$filename, serialize($data));
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* glue
*
* Provides an easy way to map URLs to classes. URLs can be literal
* strings or regular expressions.
*
* When the URLs are processed:
* * delimiter (/) are automatically escaped: (\/)
* * The beginning and end are anchored (^ $)
* * An optional end slash is added (/?)
* * The i option is added for case-insensitive searches
*
* Example:
*
* $urls = array(
* '/' => 'index',
* '/page/(\d+) => 'page'
* );
*
* class page {
* function GET($matches) {
* echo "Your requested page " . $matches[1];
* }
* }
*
* glue::stick($urls);
*
*/
class glue {
/**
* stick
*
* the main static function of the glue class.
*
* @param array $urls The regex-based url to class mapping
* @throws Exception Thrown if corresponding class is not found
* @throws Exception Thrown if no match is found
* @throws BadMethodCallException Thrown if a corresponding GET,POST is not found
*
*/
static function stick ($urls) {
$method = strtoupper($_SERVER['REQUEST_METHOD']);
$path = $_SERVER['REQUEST_URI'];
$found = false;
krsort($urls);
foreach ($urls as $regex => $class) {
$regex = str_replace('/', '\/', $regex);
$regex = '^' . $regex . '\/?$';
if (preg_match("/$regex/i", $path, $matches)) {
$found = true;
if (class_exists($class)) {
$obj = new $class;
if (method_exists($obj, $method)) {
$obj->$method($matches);
} else {
throw new BadMethodCallException("Method, $method, not supported.");
}
} else {
throw new Exception("Class, $class, not found.");
}
break;
}
}
if (!$found) {
throw new Exception("URL, $path, not found.");
}
}
}

View File

@@ -0,0 +1,8 @@
hhvm.server.port = 8000
hhvm.server.type = proxygen
hhvm.server.default_document = index.php
hhvm.server.error_document404 = index.php
hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc
hhvm.log.use_log_file = false
hhvm.hack.lang.auto_typecheck=0
hhvm.hack.lang.look_for_typechecker=0

View File

@@ -0,0 +1,54 @@
<?php
if (!headers_sent()) header('Content-Type: text/html; charset=UTF-8');
require_once __DIR__.'/../../../autoload.php';
if (file_exists(__DIR__ . '/../sandbox/c3.php')) {
require __DIR__ . '/../sandbox/c3.php';
} else {
require __DIR__ . '/../claypit/c3.php';
}
require_once('glue.php');
require_once('data.php');
require_once('controllers.php');
$urls = array(
'/' => 'index',
'/info' => 'info',
'/cookies' => 'cookies',
'/cookies2' => 'cookiesHeader',
'/search.*' => 'search',
'/login' => 'login',
'/redirect' => 'redirect',
'/redirect2' => 'redirect2',
'/redirect3' => 'redirect3',
'/redirect4' => 'redirect4',
'/redirect_params' => 'redirect_params',
'/redirect_interval' => 'redirect_interval',
'/redirect_header_interval' => 'redirect_header_interval',
'/redirect_meta_refresh' => 'redirect_meta_refresh',
'/location_201' => 'location_201',
'/relative_redirect' => 'redirect_relative',
'/relative/redirect' => 'redirect_relative',
'/redirect_twice' => 'redirect_twice',
'/relative/info' => 'info',
'/somepath/redirect_base_uri_has_path' => 'redirect_base_uri_has_path',
'/somepath/redirect_base_uri_has_path_302' => 'redirect_base_uri_has_path_302',
'/somepath/info' => 'info',
'/facebook\??.*' => 'facebookController',
'/form/(.*?)(#|\?.*?)?' => 'form',
'/user-agent' => 'userAgent',
'/articles\??.*' => 'articles',
'/auth' => 'httpAuth',
'/register' => 'register',
'/content-iso' => 'contentType1',
'/content-cp1251' => 'contentType2',
'/unset-cookie' => 'unsetCookie',
'/external_url' => 'external_url',
'/iframe' => 'iframe',
'/basehref' => 'basehref',
'/jserroronload' => 'jserroronload',
'/minimal' => 'minimal',
);
glue::stick($urls);

View File

@@ -0,0 +1,23 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<base href="/form/">
<p>
<a href="example7">Relative Link</a>
</p>
<form action="example5" method="post">
<input type="text" name="rus" value="Верно"/>
<div id="button-container">
<input type="submit" value="Relative Form"/>
</div>
</form>
</body>
</html>

View File

@@ -0,0 +1,6 @@
<html>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<body>
<h1>ANSI</h1>
</body>
</html>

View File

@@ -0,0 +1,9 @@
<html>
<meta charset="windows-1251">
<body>
<h1>CP1251</h1>
<p>
<?= print_r(headers_list()); ?>
</p>
</body>
</html>

View File

@@ -0,0 +1,8 @@
<html>
<body>
<?php echo "<pre>" . print_r($_COOKIE, 1) . "</pre>";
?>
<h1>Cookies.php View</h1>
</body>
</html>

View File

@@ -0,0 +1,5 @@
<html>
<body>
<a href="http://codeception.com/">Next</a>
</body>
</html>

View File

@@ -0,0 +1,110 @@
<?php
/**
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
use Facebook\Exceptions\FacebookSDKException;
/**
* Facebook gives cross-site-request-forgery-validation-failed without
* initializing session data and without having the
* 'persistent_data_handler' => 'session' property below
*/
session_start();
/**
* you should update these values when debugging,
* NOTE website URL for the app must be be set to http://localhost:8000/
*/
$fb = new Facebook\Facebook(array(
'app_id' => '460287924057084',
'app_secret' => 'e27a5a07f9f07f52682d61dd69b716b5',
'default_graph_version' => 'v2.5',
'persistent_data_handler' => 'session'
));
$helper = $fb->getRedirectLoginHelper();
$permissions = [];
//after logging in facebook will redirect us to this callback page
$callback = 'http://localhost:8000/facebook';
try {
$accessToken = $helper->getAccessToken();
if ($accessToken) {
//if everything is ok we have accessToken from the callback
$response = $fb->get('/me', $accessToken);
$user = $response->getGraphUser()->asArray();
$logoutUrl = $helper->getLogoutUrl($accessToken, $callback);
$errorCode = 0;
} else {
//the first time we come to this page access token will be null
$loginUrl = $helper->getLoginUrl($callback);
$errorCode = 1;
$user = null;
}
} catch (FacebookSDKException $e) {
//the second time we come to this we might get this if something is wrong with login
$errorCode = " 3 " . $e->getMessage();
$user = null;
}
?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>php-sdk</title>
<style>
body {
font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
}
h1 a {
text-decoration: none;
color: #3b5998;
}
h1 a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>php-sdk</h1>
<pre><?php print_r("\n errorCode: $errorCode\n"); ?></pre>
<?php if ($user): ?>
<a href="<?php echo $logoutUrl; ?>">Logout</a>
<?php else: ?>
<div>
Login using OAuth 2.0 handled by the PHP SDK:
<a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
</div>
<?php endif ?>
<h3>PHP Session</h3>
<pre><?php print_r($_SESSION); ?></pre>
<?php if ($user): ?>
<h3>You</h3>
<img src="https://graph.facebook.com/<?php echo $user['id']; ?>/picture">
<h3>Your User Object (/me)</h3>
<pre><?php print_r($user); ?></pre>
<?php else: ?>
<strong><em>You are not Connected.</em></strong>
<?php endif ?>
</body>
</html>

View File

@@ -0,0 +1,21 @@
<html>
<title>TestEd Beta 2.0</title>
<body>
<h1>Welcome to test app!</h1>
<form action="#a" method="post">
<input name="field1" />
<input type="submit" value="Hash Form" title="Hash Form Title" />
<button type="submit" title="Hash Button Form"></button>
</form>
<a href="#b">Hash Link</a>
<a href="#c">
<input type="submit" value="Hash Button" />
</a>
</body>
</html>

View File

@@ -0,0 +1,21 @@
<!doctype html>
<html>
<head><title>hi</title></head>
<body>
TEST TEST
<form name="form1">
<label><input type="radio" name="first_test_radio" value="Yes"/>Yes</label>
<label><input type="radio" name="first_test_radio" value="No"/>No</label>
<br/>
<label><input type="radio" name="second_test_radio" value="Yes" />Yes</label>
<label><input type="radio" name="second_test_radio" value="No" />No</label>
</form>
<form name="form2">
<label><input type="radio" name="first_test_radio" value="Yes"/>Yes</label>
<label><input type="radio" name="first_test_radio" value="No"/>No</label>
<br/>
<label><input type="radio" name="second_test_radio" value="Yes" />Yes</label>
<label><input type="radio" name="second_test_radio" value="No" />No</label>
</form>
</body>
</html>

View File

@@ -0,0 +1,13 @@
<html>
<body>
<form action="/form/complex" method="post">
<div id="bmessage-topicslinks">
<div class="checkbox"><label><input type="checkbox" name="BMessage[topicsLinks][]" value="1"> Label 1</label></div>
<div class="checkbox"><label><input type="checkbox" name="BMessage[topicsLinks][]" value="2"> Label 2</label></div>
<div class="checkbox"><label><input type="checkbox" name="BMessage[topicsLinks][]" value="3"> Label 3</label></div>
<div class="checkbox"><label><input type="checkbox" name="BMessage[topicsLinks][]" value="4"> Label 4</label></div>
</div>
<input type="submit" value="Submit" />
</form>
</body>
</html>

View File

@@ -0,0 +1,13 @@
<html>
<body>
<h1>Hello world</h1>
<form action="/form/complex" method="post">
<textarea name="captions[]" class="caption"></textarea>
<input class="input-quantity row-1" name="items[1][quantity]" type="text" value="1" id="items[1][quantity]">
<textarea name="items[1][]" class="caption"></textarea>
<input type="text" name="users[]" />
<input type="file" name="files[]" />
<input type="submit" value="Submit"/>
</form>
</body>
</html>

View File

@@ -0,0 +1,7 @@
<html>
<body>
<div id="field">
12,345
</div>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!doctype html>
<html>
<head><title>hi</title></head>
<body>
TEST TEST
<label><input type="radio" name="first_test_radio" value="Yes"/>Yes</label>
<label><input type="radio" name="first_test_radio" value="No"/>No</label>
<br/>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<!doctype html>
<html>
<head><title>hi</title></head>
<body>
<form name="form" action="/form/bug2841" method="post" enctype="multipart/form-data">
<input name="in" type="text" id="texty">
<button type="submit" name="submit-registration" id="submit-registration" class="submit-registration">CLICKY</button>
</form>
</body>
</html>

View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<textarea id="ta" name="foo" rows="3">bar baz
</textarea>
</body>
</html>

View File

@@ -0,0 +1,15 @@
<html><body>
<form method="post">
<select name="test">
<option value="_none">- None -</option>
</select>
</form>
<?php
if (isset($_POST['test']) && $_POST['test'] !== '_none') {
echo 'ERROR';
}
?>
</body></html>

View File

@@ -0,0 +1,4 @@
<html><body>
<a href="/">222</a>
</body></html>

View File

@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>grabValueFrom issue</title>
</head>
<body>
<form method="get">
<input type="text" name="empty" id="empty">
<textarea name="empty_textarea" id="empty_textarea"></textarea>
<textarea name="textarea[name][]" id="textarea_with_square_bracket"></textarea>
</form>
</body>
</html>

View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>issue #3983</title>
</head>
<body>
<form method="get" action="/form/bug3953">
<select name="select_name" id="select_id">
<option value="one">first</option>
<option value="two">second</option>
</select>
<input type="text" name="search_name">
<button>Submit</button>
</form>
</body>
</html>

View File

@@ -0,0 +1,7 @@
<html>
<body>
<div>
<button>The Button</button>
</div>
</body>
</html>

View File

@@ -0,0 +1,8 @@
<html>
<body>
<form action="/form/button" method="POST">
<input type="hidden" name="text" value="val" />
<button type="submit" name="btn0">Submit</button>
</form>
</body>
</html>

View File

@@ -0,0 +1,10 @@
<html>
<body>
<form action="/form/button" method="POST">
<button type="submit" name="btn0">Submit</button>
</form>
<a href="/info"><input type="submit" value="More Info"></a>
<a href="/info"><span><input type="submit" value="Span Info"></span></a>
</body>
</html>

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