2. Agenda
Presentation of Speaker/ Company
Presentation of Codeception
Presentation of Tests Types
Demonstration & Hands-on
Best Practices
References
Q & A
@phpcon_kansai
3. Who the hell am I ?
Batard Florent (28 years old)(Shenril)
Twitter: @shenril
Facebook: Florent Btd
Security Engineer (Ethical Hacker)
French Globe Trotter
Lived in France,UK,Switzerland,U.S,Japan
Fan of Japan and especially Kansai area and people
Style learning Japanese….
4. Who the hell am I ?
Batard Florent (28 years old)(Shenril)
Twitter: @shenril
Facebook: Florent Btd
Security Engineer (Ethical Hacker)
French Globe Trotter
Lived in France,UK,Switzerland,U.S,Japan
Fan of Japan and especially Kansai area and people
Style learning Japanese….
5. Who the hell am I ?
Batard Florent (28 years old)(Shenril)
Twitter: @shenril
Facebook: Florent Btd
Security Engineer (Ethical Hacker)
French Globe Trotter
Lived in France,UK,Switzerland,U.S,Japan
Fan of Japan and especially Kansai area and people
Style learning Japanese….
6. Who the hell am I ?
Batard Florent (28 years old)(Shenril)
Twitter: @shenril
Facebook: Florent Btd
Security Engineer (Ethical Hacker)
French Globe Trotter
Lived in France,UK,Switzerland,U.S,Japan
Fan of Japan and especially Kansai area and people
Style learning Japanese….
7. Who the hell am I ?
Batard Florent (28 years old)(Shenril)
Twitter: @shenril
Facebook: Florent Btd
Security Engineer (Ethical Hacker)
French Globe Trotter
Lived in France,UK,Switzerland,U.S,Japan
Fan of Japan and especially Kansai area and people
Style learning Japanese….
8. Who the hell am I ?
Batard Florent (28 years old)(Shenril)
Twitter: @shenril
Facebook: Florent Btd
Security Engineer (Ethical Hacker)
French Globe Trotter
Lived in France,UK,Switzerland,U.S,Japan
Fan of Japan and especially Kansai area and people
Style learning Japanese….
9. Who the hell am I ?
Batard Florent (28 years old)(Shenril)
Twitter: @shenril
Facebook: Florent Btd
Security Engineer (Ethical Hacker)
French Globe Trotter
Lived in France,UK,Switzerland,U.S,Japan
Fan of Japan and especially Kansai area and people
Style learning Japanese….
10. Why do i speak here?
Worked for:
W3C in Sophia Antipolis
U.N (Security Consultant)
Private Banking
Television
Did conferences in Europe
Mainly Security (Youtube) (sorry french and english only)
Active Member of OWASP (Web Security Project)
Web Developer for the past 10 years
Interested in DevOps ,Servers, Infrastructure, Artificial Intelligence
Learning Animal
11. Why do i speak here?
Worked for:
W3C in Sophia Antipolis
U.N (Security Consultant)
Private Banking
Television
Did conferences in Europe
Mainly Security (Youtube) (sorry french and english only)
Active Member of OWASP (Web Security Project)
Web Developer for the past 10 years
Interested in DevOps ,Servers, Infrastructure, Artificial Intelligence
Learning Animal
12. Why do i speak here?
Worked for:
W3C in Sophia Antipolis
U.N (Security Consultant)
Private Banking
Television
Did conferences in Europe
Mainly Security (Youtube) (sorry french and english only)
Active Member of OWASP (Web Security Project)
Web Developer for the past 10 years
Interested in DevOps ,Servers, Infrastructure, Artificial Intelligence
Learning Animal
13. Why do i speak here?
Worked for:
W3C in Sophia Antipolis
U.N (Security Consultant)
Private Banking
Television
Did conferences in Europe
Mainly Security (Youtube) (sorry french and english only)
Active Member of OWASP (Web Security Project)
Web Developer for the past 10 years
Interested in DevOps ,Servers, Infrastructure, Artificial Intelligence
Learning Animal
14. Who do I work for?
Cook+biz
Awesome Team
Awesome Challenges
15. Who do I work for?
Cook+biz
Awesome Team
Awesome Challenges
16. Who do I work for?
Cook+biz
Awesome Team
Awesome Challenges
17. Why Testing?
Why should I test my code ?
Reduce False assumptions -> If you rely on assumptions it will surely fail…
Validate that there is no regression
Make sure the code runs as expected
Test limit values (security,big data)
Automate repetitive tasks -> Good developers are lazy developers!!!
It makes debugging/correction so much easier
But…
Often developers finds it hard to write
Too long too run
Doesn’t correspond to business logic/behaviour/user scenario
19. CodeCeption(2)
BDD-style scenario-driver tests
WebServices tests (SOAP/REST/XML-RPC)
Generates reports(HTML/XML/JSON)
Laravel/Zend/Phalcon/Yii2/Symfony/Composer modules -
> No excuse!
Integration with continuous deployment (Jenkins/Bamboo)
Can be used along with Selenium2 and PhantomJS for
advanced tests
20. What does it look like?
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('create wiki page');
$I->amOnPage('/');
$I->click('Pages');
$I->click('New');
$I->see('New Page');
$I->fillField('title', 'Hobbit');
$I->fillField('body', 'By Peter Jackson');
$I->click('Save');
$I->see('page created'); // notice generated
$I->see('Hobbit','h1'); // head of page of is our title
$I->seeInCurrentUrl('pages/hobbit');
$I->seeInDatabase('pages', array('title' => ‘Hobbit'));
?>
29. Acceptance Tests
Enable to do request and interact with the DOM
Use a fake browser to perform the queries
Can click and fill forms
Can be plugged with Selenium/PhantomJS to interact
with JavaScript and screenshots
Slowest tests to run
30. Functional Tests
Same as Acceptance test but does not use a browser
engine
Can be plugged with the framework to access internal
functions and properties (Models, validation)
Use $_REQUEST, $_POST and $_GET
Faster
No DOM interaction (JS/Ajax/Events)
31. Unit Tests
Used to test functions
Can be plugged with the framework to access internal functions and properties (Models, Validation)
Fastest
Difficult to use in MVC
Not readable by Humans
public function testValidation()
{
$user = User::create();
$user->username = null;
$this->assertFalse($user->validate(['username']));
$user->username = 'toolooooongnaaaaaaameeee';
$this->assertFalse($user->validate(['username']));
$user->username = 'davert';
$this->assertTrue($user->validate(['username']));
}
32. Install on all platforms
Mac OSX:
brew update && brew install homebrew/php/codeception
Linux:
wget http://codeception.com/codecept.phar .
php codecept.phar bootstrap
Windows:
php composer.phar global require “codeception/codeception:*”
Composer/ PhpStorm:
php composer.phar require “codeception/codeception:*”
34. Let’s get the party started
>codecept run
>codecept run —debug
Bonus
>codecept generate:scenarios acceptance //English version
>codecept console acceptance //Interactive console
>codecept run —debug —env test
36. Best practices
1. Run tests on your vagrant -> GIT push ONLY when tests pass
2. Deploy on test server -> Validate tests on test server
3. Deploy on production ONLY if tests pass on test server
4. NEVER run on production ! NEVER!!!
1. It creates new entries and change Database
2. Add load on the production server
3. Need new set of tests/monitoring on production