Skip to content

Commit 111d082

Browse files
author
Davert
committed
initial
0 parents  commit 111d082

File tree

152 files changed

+15354
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+15354
-0
lines changed

autoload.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
require_once 'vendor/UniversalClassLoader.php';
4+
5+
$loader = new UniversalClassLoader();
6+
$loader->registerNamespaces(array(
7+
'Codeception' => __DIR__ . '/src',
8+
'Monolog' => __DIR__ . '/vendor',
9+
'Symfony\Component' => __DIR__ . '/vendor',
10+
));
11+
12+
$loader->register();
13+
$loader->registerNamespaceFallbacks(array(__DIR__.'/vendor/Mink/vendor'));
14+
15+
include_once 'PHPUnit/Autoload.php';
16+
include_once 'mink/autoload.php';
17+
// require_once __DIR__.'/src/BaseTestGuy.php';

codecept

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
require_once 'autoload.php';
5+
6+
use Symfony\Component\Console\Application,
7+
Symfony\Component\Console\Input\InputInterface,
8+
Symfony\Component\Console\Input\InputDefinition,
9+
Symfony\Component\Console\Input\InputOption;
10+
11+
$app = new Application('Codeception', Codeception\Codecept::VERSION);
12+
$app->add(new Codeception\Command\Build('build'));
13+
$app->add(new Codeception\Command\Run('run'));
14+
$app->add(new Codeception\Command\Install('install'));
15+
$app->add(new Codeception\Command\Bootstrap('bootstrap'));
16+
$app->add(new Codeception\Command\GenerateScenarios('generate-scenarios'));
17+
$app->run();

codeception.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
paths:
2+
tests: tests
3+
output: tests/_log
4+
helpers: tests/helpers
5+
settings:
6+
bootstrap: _bootstrap.php
7+
suite_class: \PHPUnit_Framework_TestSuite
8+
colors: true
9+
silent: false
10+
memory_limit: 1024M
11+
log: true
12+
log_max_files: 10
13+
modules:
14+
config:
15+
Db:
16+
dsn: ''
17+
user: ''
18+
password: ''
19+
dump: tests/_data/dump.sql

config/codeception.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
paths:
2+
tests: tests
3+
output: tests/_log
4+
helpers: tests/helpers
5+
modules: tests/modules
6+
settings:
7+
bootstrap: _bootstrap.php
8+
suite_class: \PHPUnit_Framework_TestSuite
9+
colors: true
10+
silent: false
11+
memory_limit: 1024M
12+
silent: false

readme.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# TestGuy Standalone
2+
## Functional Testing Framework
3+
4+
TestGuy is a functional testing framework powered by PHPUnit.
5+
Designed make tests easy to write, read, and debug.
6+
7+
## Principles
8+
TestGuy library allows to write test scenarios in PHP with DSL designed to look like native English.
9+
Imagine your tester describes her actions and you write them as a functional tests!
10+
Tester can perform some actions and see the results. Whenever she doesn't see expected value the test fails.
11+
This is how testers act. And this is the same how TestGuy is acting.
12+
13+
TestGuy knows a little about internals of your application. When error occur it won't tell you which module triggered this error.
14+
Still it makes you confident that your app is still running correctly and users can perform the same scenarios the TestGuy does.
15+
16+
Cover your application with functional tests and let them stay simple to read, simple to write, and simple to debug.
17+
Use TestGuy!
18+
19+
## In a Glance
20+
This is the sample TestGuy test. User is accessing the site to create a new wiki page about the movie.
21+
He gets to 'new' page, submits form, and sees the page he just created. Also he performs additional checks, if the slug is generated and if the database record is saved.
22+
23+
``` php
24+
<?php
25+
26+
$I = new TestGuy($scenario);
27+
$I->wantTo('create wiki page');
28+
$I->amOnPage('/');
29+
$I->click('Pages');
30+
$I->click('New');
31+
$I->see('New Page');
32+
$I->submitForm('#pageForm', array('page' => array(
33+
'title' => 'Tree of Life Movie Review',
34+
'body' => 'Next time don\'t let Hollywood create arthouse =) '
35+
)));
36+
$I->see('page created'); // notice generated
37+
$I->see('Tree of Life Movie Review','h1'); // head of page of is our title
38+
$I->seeInCurrentAddress('pages/tree-of-life-mobie-review'); // slug is generated
39+
$I->seeInDatabase('pages', array('title' => 'Tree of Life Movie Review')); // data is stored in database
40+
41+
```
42+
43+
## About
44+
45+
TestGuy uses PHPUnit (http://http://www.phpunit.de/) as backend for testing framework. If you are familiar with PHPUnit you can your TestGuy installation with it's features.
46+
Also TestGuy uses Mink (http://mink.behat.org/) a powerful library that provides interface for browser emulators.
47+
TestGuy was developed as symfony1 plugin and now it's migrated to standalone version. You can test any project with it!
48+
49+
## Install
50+
51+
If you need stable standalone version download [https://github.com/downloads/DavertMik/TestGuy_Standalone/testguy.phar](phar package).
52+
53+
Put it wherever you expect to store your test suites.
54+
55+
Install TestGuy dependencies.
56+
57+
```
58+
php testguy.phar install
59+
```
60+
61+
Generate empty test suite
62+
63+
````
64+
php testguy.phar init
65+
````
66+
67+
That will create a 'tests' directory with a sample suite inside it.
68+
By default suite will be configured to test web sites with Mink.
69+
Configuration is stored in ```tests/testguy/suites.yml````.
70+
71+
72+
Build TestGuy class
73+
74+
````
75+
php testguy.phar build
76+
````
77+
78+
Then your suite is ready to run first test file.
79+
80+
````
81+
php testguy.phar run
82+
````
83+
84+
You will see the result:
85+
86+
````
87+
Starting app...
88+
TestGuy 0.7 running with modules: Cli, Filesystem.
89+
Powered by PHPUnit 3.5.5 by Sebastian Bergmann.
90+
91+
92+
# Trying to test some feature of my app (SampleSpec.php) - ok
93+
94+
Time: 0 seconds, Memory: 8.75Mb
95+
96+
OK (1 test, 0 assertions)
97+
````
98+
99+
## Writing tests
100+
101+
Each test belongs to suite. You can have several suites for different parts of your application.
102+
By default the 'app' test suite is crated and stored into ````tests/testguy/app````.
103+
Inside of it you will see a first test file: ````SampleSpec.php````
104+
105+
TestGuy tests should be placed in suite directory and should be ended with 'Spec.php'.
106+
107+
Tests should always start with this lines:
108+
109+
``` php
110+
<?php
111+
$I = new TestGuy($scenario);
112+
$I->wantTo('actions you are going to perform');
113+
```
114+
115+
$I - is a magical object. It stores all actions you can perform. Just type ```$I->``` in your IDE and you will see what actions you can execute.
116+
For instance, the Web module is connected and you can open browser on specific page and test the expected result.
117+
118+
``` php
119+
<?php
120+
$I = new TestGuy($scenario);
121+
$I->wantTo('see if registration page is here');
122+
$I->amOnPage('/register');
123+
$I->see('Registration');
124+
```
125+
126+
ALl methods of $I object are taken from TestGuy modules. There are not much of them, but you can write your own.
127+
The most powerful module is Web module, it allows you to test wep sites with headless browser.
128+
You can connect as many modules as you like and use all them together.
129+
130+
The detailed information on modules and configurations you can see [https://github.com/DavertMik/TestGuy_Modules](here)
131+
132+
## Testing Methods
133+
The method names in $I object are designed to be easy to understand their meaning.
134+
There are 3 types of methods:
135+
136+
* Conditions: start with ```am```. They specify the starting conditions. For example: ```$I->amOnPage('/login');```
137+
* Assertions: start with ```see``` or ```dontSee```. They define the expected result and makes a test fail if result is not see.
138+
* Actions: all other actions. They change current application state. For example: ```$I->click('Signin');``` moves user to sign in page.
139+
140+
## Sample tests
141+
You can look at sample tests here, in /tests/ dir.
142+
143+
### License
144+
MIT
145+
146+
(c) Michael Bodnarchuk "Davert"
147+
2011

src/Codeception/AbstractGuy.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
namespace Codeception;
3+
4+
abstract class AbstractGuy {
5+
public static $methods = array();
6+
7+
/**
8+
* @var \Codeception\Scenario
9+
*/
10+
protected $scenario;
11+
12+
public function __construct(\Codeception\Scenario $scenario) {
13+
$this->scenario = $scenario;
14+
15+
foreach (\Codeception\SuiteManager::$modules as $module) {
16+
$module->_cleanup();
17+
}
18+
}
19+
20+
public function wantToTest($text) {
21+
$this->scenario->setFeature(strtolower("test $text"));
22+
}
23+
24+
public function wantTo($text) {
25+
$this->scenario->setFeature(strtolower($text));
26+
}
27+
28+
public function amTestingClass($text) {
29+
$this->scenario->setFeature($text);
30+
}
31+
32+
public function amTestingMethod($method) {
33+
$this->testMethod($method);
34+
}
35+
36+
public function testMethod($signature) {
37+
if (!$this->scenario->getFeature()) {
38+
$this->scenario->setFeature("execute method $signature()");
39+
} else {
40+
$this->scenario->setFeature($this->scenario->getFeature() . " with [[$signature]]");
41+
}
42+
$this->scenario->when(array_merge(array('testMethod', $signature)));
43+
}
44+
45+
public function expectTo($prediction) {
46+
$this->scenario->comment(array('expect to '.$prediction));
47+
}
48+
49+
public function amGoingTo($argumentation) {
50+
$this->scenario->comment(array('am going to '.$argumentation));
51+
}
52+
53+
public function __call($method, $args) {
54+
// if (!in_array($method, array_keys(TestGuy::$methods))) throw new \RuntimeException("Action $method not defined");
55+
// foreach ($args as $k => $arg) {
56+
// if (is_object($arg)) $args[$k] = clone($arg);
57+
// }
58+
if (0 === strpos($method,'see')) {
59+
$this->scenario->then(array_merge(array($method) ,$args));
60+
} elseif (0 === strpos($method,'am')) {
61+
$this->scenario->given(array_merge(array($method) ,$args));
62+
} else {
63+
$this->scenario->when(array_merge(array($method),$args));
64+
}
65+
}
66+
67+
}

0 commit comments

Comments
 (0)