Installation
and Configuration of Codeception with PHAR file:
Codeception
is basically a PHP testing framework to perform unit,functional and
acceptance types of testings.It's installation is pretty simple and
only requires minimal steps. PHP needs to be installed on the machine
where we need to test our web application.
PHP
Dependencies: Codeception
2.0 and higher requires PHP 5.4 installed. Download latest version of
Codeception 1.8.x if you run PHP 5.3
We
can install PHP in our system by XAMP or WAMP.
Lets
start installing codeception in our system in order to run our first
acceptance test.
1.
We need to download the
codeception PHAR file and we need to put it under root of our web application.
We can also download it from console.simply fire
the below command in console.
wget
http://codeception.com/codecept.phar
2. Then
we need to install the PHAR file.
In
console navigate to the directory we have kept the PHAR file and fire
the below command:
php
codecept.phar bootstrap
This
will create a tests directory which will contain all type unit,
functional and acceptance tests and
codeception.yml file.
3.
Let's go ahead and create our
first Acceptance test.To generate our first acceptance test simply
fire the below command in console:
php
codecept.phar generate:cept acceptance Test
Cept:
cept
are generally codeception scenarios.
4. Now
is the time to write our first acceptance test.
Suppose
we need to test that we are currently in App's home page.
So
we need to write the test like below format:
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure
that frontpage works');
$I->amOnPage('/');
$I->see('Home');
?>
5.
Now time to configure our Acceptance test
Please
make sure your local dev server is running.
In
acceptance suite.yml file put the web app url.
class_name:
AcceptanceGuy
modules:
enabled:
[PhpBrowser, AcceptanceHelper]
config:
PhpBrowser:
url:
'{YOUR WEB APP'S URL}'
6.
Now time for running our first acceptance test.Just execute the run
command
php
codecept.phar run
This
command will execute test cept file with phpbrowser.
If
you have did everything correct and your web app has a home page then
you will see your test as passed in following format in console.
Suite
acceptance started
Trying
to ensure that frontpage works (WelcomeCept.php) - Ok
Suite
functional started
Suite
unit started
Time:
1 second, Memory: 7.00Mb
OK
(1 test, 1 assertions)