SlideShare a Scribd company logo
Text
Introducing Codeception
(TDD)—>Test Driven Development
Agenda
Presentation of Speaker/ Company
Presentation of Codeception
Presentation of Tests Types
Demonstration & Hands-on
Best Practices
References
Q & A
@phpcon_kansai
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….
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….
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….
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….
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….
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….
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….
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
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
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
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
Who do I work for?
Cook+biz
Awesome Team
Awesome Challenges
Who do I work for?
Cook+biz
Awesome Team
Awesome Challenges
Who do I work for?
Cook+biz
Awesome Team
Awesome Challenges
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
CodeCeption(1)
http://codeception.com/ (English)
Test Framework
Acceptance Tests
Functional Tests
Unit Tests
Easy
To read
To write
To debug
Natively handles PHPUnit -> standard
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
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'));
?>
Codeception Testing Framework -- English #phpkansai
Different tests types
Acceptance
Tests
Functional
Tests
Unit Tests
Yii2 BackendFrontend
Browser
Selenium
PhantomJS
HTML
HTML
$_GET,$_POST,
$_REQUEST
Yii2 Module Backend
Different tests types
Acceptance
Tests
Functional
Tests
Unit Tests
Yii2 BackendFrontend
Browser
Selenium
PhantomJS
HTML
HTML
$_GET,$_POST,
$_REQUEST
Yii2 Module Backend
Different tests types
Acceptance
Tests
Functional
Tests
Unit Tests
Yii2 BackendFrontend
Browser
Selenium
PhantomJS
HTML
HTML
$_GET,$_POST,
$_REQUEST
Yii2 Module Backend
User Scenario
Different tests types
Acceptance
Tests
Functional
Tests
Unit Tests
Yii2 BackendFrontend
Browser
Selenium
PhantomJS
HTML
HTML
$_GET,$_POST,
$_REQUEST
Yii2 Module Backend
User Scenario
Different tests types
Acceptance
Tests
Functional
Tests
Unit Tests
Yii2 BackendFrontend
Browser
Selenium
PhantomJS
HTML
HTML
$_GET,$_POST,
$_REQUEST
Yii2 Module Backend
User Scenario
Developer Scenario
Different tests types
Acceptance
Tests
Functional
Tests
Unit Tests
Yii2 BackendFrontend
Browser
Selenium
PhantomJS
HTML
HTML
$_GET,$_POST,
$_REQUEST
Yii2 Module Backend
User Scenario
Developer Scenario
Different tests types
Acceptance
Tests
Functional
Tests
Unit Tests
Yii2 BackendFrontend
Browser
Selenium
PhantomJS
HTML
HTML
$_GET,$_POST,
$_REQUEST
Yii2 Module Backend
User Scenario
Developer Scenario
Function Testing
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
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)
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']));
}
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:*”
Getting ready
BootStrap
>codecept bootstrap
>codecept generate:cept acceptance Validation
Edit the configuration file : tests/acceptance.suite.yml
class_name: AcceptanceTester
modules:
enabled:
- PhpBrowser
- AcceptanceHelper
config:
PhpBrowser:
url: ‘http://conference.kphpug.jp/2015/’
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
Demo Time !!!!!
> Let’s test PHP conference Kansai website !
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
References
Installation : http://codeception.com/install
Acceptance Tests : http://codeception.com/docs/04-AcceptanceTests
Yii2 module : http://codeception.com/docs/modules/Yii2
WebDriver : http://codeception.com/docs/modules/WebDriver
Yii2 Database Faker : http://qiita.com/tanakahisateru/items/
c4d39cc77a71067ed658
Other tools
PHPUnit Framework(Difficult)
phpspec (Specification & Unit Testing)
Pure Selenium/PhantomJS (Harder integration)
Mink (Browser Controlling, slow,harder integration)
Questions & Answers
Do you have any questions?

More Related Content

What's hot (20)

PDF
Test Driven iOS Development (TDD)
Babul Mirdha
 
PPTX
PHPUnit - Unit testing
Nguyễn Đào Thiên Thư
 
PDF
Codeception
Jonathan Lau
 
PDF
Test driven development
Sharafat Ibn Mollah Mosharraf
 
PDF
Test Driven Development (TDD)
David Ehringer
 
PDF
Dependency Injection in iOS
Pablo Villar
 
PPTX
Test driven development
Nascenia IT
 
PDF
When develpment met test(shift left testing)
SangIn Choung
 
PPTX
Automation and Technical Debt
IBM UrbanCode Products
 
PDF
Keyword Driven Testing
Maveryx
 
PPTX
TDD - Agile
harinderpisces
 
PDF
Behavior Driven Development with SpecFlow
Rachid Kherrazi
 
PPTX
Test-Driven Development (TDD)
Brian Rasmussen
 
PPTX
Test-Driven Development
John Blum
 
PDF
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
PDF
Test Driven Development
Mireia Sangalo
 
PDF
TDD and BDD and ATDD
Anuar Nurmakanov
 
PPTX
Test Driven Development (TDD) Preso 360|Flex 2010
guest5639fa9
 
ODP
Tdd in php a brief example
Jeremy Kendall
 
PDF
A Not-So-Serious Introduction to Test Driven Development (TDD)
CodeOps Technologies LLP
 
Test Driven iOS Development (TDD)
Babul Mirdha
 
PHPUnit - Unit testing
Nguyễn Đào Thiên Thư
 
Codeception
Jonathan Lau
 
Test driven development
Sharafat Ibn Mollah Mosharraf
 
Test Driven Development (TDD)
David Ehringer
 
Dependency Injection in iOS
Pablo Villar
 
Test driven development
Nascenia IT
 
When develpment met test(shift left testing)
SangIn Choung
 
Automation and Technical Debt
IBM UrbanCode Products
 
Keyword Driven Testing
Maveryx
 
TDD - Agile
harinderpisces
 
Behavior Driven Development with SpecFlow
Rachid Kherrazi
 
Test-Driven Development (TDD)
Brian Rasmussen
 
Test-Driven Development
John Blum
 
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
Test Driven Development
Mireia Sangalo
 
TDD and BDD and ATDD
Anuar Nurmakanov
 
Test Driven Development (TDD) Preso 360|Flex 2010
guest5639fa9
 
Tdd in php a brief example
Jeremy Kendall
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
CodeOps Technologies LLP
 

Viewers also liked (20)

PDF
Rocks on Rocks
Ryan James Tutak
 
PDF
Microsoft H1B Violations
H1B
 
PPTX
Evolution of Software Engineering in NCTR Projects
Mohammed Abbas
 
PDF
Afrika Tikkun Annual Review
Afrika Tikkun USA
 
PDF
33 Essential Social Recruiting Stats - 2011
Steven Duque
 
PPTX
Patient matching in FHIR
Grahame Grieve
 
DOC
Assignment brief
Christopher Lucas
 
PPT
Canadian Healthcare Codes and Terminology Standards
Intelliware Development Inc.
 
PPT
Power Pointless How To Make An Amazing Presentation
Joan Shi
 
DOC
Hong kong
Sonya Fay McKenzie
 
DOCX
City of deception
Dr Saim Ali soomro
 
PDF
I2 Argentina Unitech
UNITECH S.A.
 
PDF
Why Nortel Went Bankrupt
Chris Sandström
 
PDF
Agile Testing
Intelliware Development Inc.
 
PDF
Environmental Law for Road Builders
DSaxe
 
PDF
Quelle gouvernance pour le numérique?
Antoine Vigneron
 
PPTX
Master of deception (mod)
Shane Alex Perez
 
PDF
Clinical development, contract & outsourcing in mena & asia pac webinar-l aju...
Larry Ajuwon
 
PDF
Enterprise Wearables: Wearing Our Parts On Our Sleeves - How Wearable Technol...
Intelliware Development Inc.
 
ODP
Add 2009 10
RUAULT
 
Rocks on Rocks
Ryan James Tutak
 
Microsoft H1B Violations
H1B
 
Evolution of Software Engineering in NCTR Projects
Mohammed Abbas
 
Afrika Tikkun Annual Review
Afrika Tikkun USA
 
33 Essential Social Recruiting Stats - 2011
Steven Duque
 
Patient matching in FHIR
Grahame Grieve
 
Assignment brief
Christopher Lucas
 
Canadian Healthcare Codes and Terminology Standards
Intelliware Development Inc.
 
Power Pointless How To Make An Amazing Presentation
Joan Shi
 
City of deception
Dr Saim Ali soomro
 
I2 Argentina Unitech
UNITECH S.A.
 
Why Nortel Went Bankrupt
Chris Sandström
 
Environmental Law for Road Builders
DSaxe
 
Quelle gouvernance pour le numérique?
Antoine Vigneron
 
Master of deception (mod)
Shane Alex Perez
 
Clinical development, contract & outsourcing in mena & asia pac webinar-l aju...
Larry Ajuwon
 
Enterprise Wearables: Wearing Our Parts On Our Sleeves - How Wearable Technol...
Intelliware Development Inc.
 
Add 2009 10
RUAULT
 
Ad

Similar to Codeception Testing Framework -- English #phpkansai (20)

PPTX
Codeception
少東 張
 
PDF
Testing mit Codeception: Full-stack testing PHP framework
SusannSgorzaly
 
PDF
From Good to Great: Functional and Acceptance Testing in WordPress.
David Aguilera
 
PDF
Codeception presentation
Andrei Burian
 
PDF
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Joe Ferguson
 
PDF
Codeception introduction and use in Yii
IlPeach
 
PDF
Acceptance & Functional Testing with Codeception - Devspace 2015
Joe Ferguson
 
ODP
2014 11 20 Drupal 7 -> 8 test migratie
hcderaad
 
PDF
Quality Assurance for PHP projects - ZendCon 2012
Michelangelo van Dam
 
KEY
Workshop quality assurance for php projects tek12
Michelangelo van Dam
 
PDF
Acceptance testing in php with Codeception - Techmeetup Edinburgh
Engineor
 
PDF
Codeception: introduction to php testing
Engineor
 
PPTX
DevSecCon Tel Aviv 2018 - Integrated Security Testing by Morgan Roman
DevSecCon
 
PDF
Code Coverage for Total Security in Application Migrations
Dana Luther
 
PPTX
Automation testing with Drupal 8
nagpalprachi
 
PDF
Mykhailo Bodnarchuk "The history of the Codeception project"
Fwdays
 
PPTX
Automated tests
Damian Sromek
 
PPTX
Test automation with php codeception
buddhieash
 
PPTX
Automated Testing
Speed FC
 
KEY
ATDD in Practice
Steven Mak
 
Codeception
少東 張
 
Testing mit Codeception: Full-stack testing PHP framework
SusannSgorzaly
 
From Good to Great: Functional and Acceptance Testing in WordPress.
David Aguilera
 
Codeception presentation
Andrei Burian
 
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Joe Ferguson
 
Codeception introduction and use in Yii
IlPeach
 
Acceptance & Functional Testing with Codeception - Devspace 2015
Joe Ferguson
 
2014 11 20 Drupal 7 -> 8 test migratie
hcderaad
 
Quality Assurance for PHP projects - ZendCon 2012
Michelangelo van Dam
 
Workshop quality assurance for php projects tek12
Michelangelo van Dam
 
Acceptance testing in php with Codeception - Techmeetup Edinburgh
Engineor
 
Codeception: introduction to php testing
Engineor
 
DevSecCon Tel Aviv 2018 - Integrated Security Testing by Morgan Roman
DevSecCon
 
Code Coverage for Total Security in Application Migrations
Dana Luther
 
Automation testing with Drupal 8
nagpalprachi
 
Mykhailo Bodnarchuk "The history of the Codeception project"
Fwdays
 
Automated tests
Damian Sromek
 
Test automation with php codeception
buddhieash
 
Automated Testing
Speed FC
 
ATDD in Practice
Steven Mak
 
Ad

Recently uploaded (20)

PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PDF
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
PDF
Executive Business Intelligence Dashboards
vandeslie24
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
Letasoft Sound Booster 1.12.0.538 Crack Download+ Product Key [Latest]
HyperPc soft
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PPTX
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
Executive Business Intelligence Dashboards
vandeslie24
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Letasoft Sound Booster 1.12.0.538 Crack Download+ Product Key [Latest]
HyperPc soft
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Tally software_Introduction_Presentation
AditiBansal54083
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 

Codeception Testing Framework -- English #phpkansai

  • 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
  • 18. CodeCeption(1) http://codeception.com/ (English) Test Framework Acceptance Tests Functional Tests Unit Tests Easy To read To write To debug Natively handles PHPUnit -> standard
  • 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')); ?>
  • 22. Different tests types Acceptance Tests Functional Tests Unit Tests Yii2 BackendFrontend Browser Selenium PhantomJS HTML HTML $_GET,$_POST, $_REQUEST Yii2 Module Backend
  • 23. Different tests types Acceptance Tests Functional Tests Unit Tests Yii2 BackendFrontend Browser Selenium PhantomJS HTML HTML $_GET,$_POST, $_REQUEST Yii2 Module Backend
  • 24. Different tests types Acceptance Tests Functional Tests Unit Tests Yii2 BackendFrontend Browser Selenium PhantomJS HTML HTML $_GET,$_POST, $_REQUEST Yii2 Module Backend User Scenario
  • 25. Different tests types Acceptance Tests Functional Tests Unit Tests Yii2 BackendFrontend Browser Selenium PhantomJS HTML HTML $_GET,$_POST, $_REQUEST Yii2 Module Backend User Scenario
  • 26. Different tests types Acceptance Tests Functional Tests Unit Tests Yii2 BackendFrontend Browser Selenium PhantomJS HTML HTML $_GET,$_POST, $_REQUEST Yii2 Module Backend User Scenario Developer Scenario
  • 27. Different tests types Acceptance Tests Functional Tests Unit Tests Yii2 BackendFrontend Browser Selenium PhantomJS HTML HTML $_GET,$_POST, $_REQUEST Yii2 Module Backend User Scenario Developer Scenario
  • 28. Different tests types Acceptance Tests Functional Tests Unit Tests Yii2 BackendFrontend Browser Selenium PhantomJS HTML HTML $_GET,$_POST, $_REQUEST Yii2 Module Backend User Scenario Developer Scenario Function Testing
  • 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:*”
  • 33. Getting ready BootStrap >codecept bootstrap >codecept generate:cept acceptance Validation Edit the configuration file : tests/acceptance.suite.yml class_name: AcceptanceTester modules: enabled: - PhpBrowser - AcceptanceHelper config: PhpBrowser: url: ‘http://conference.kphpug.jp/2015/’
  • 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
  • 35. Demo Time !!!!! > Let’s test PHP conference Kansai website !
  • 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
  • 37. References Installation : http://codeception.com/install Acceptance Tests : http://codeception.com/docs/04-AcceptanceTests Yii2 module : http://codeception.com/docs/modules/Yii2 WebDriver : http://codeception.com/docs/modules/WebDriver Yii2 Database Faker : http://qiita.com/tanakahisateru/items/ c4d39cc77a71067ed658 Other tools PHPUnit Framework(Difficult) phpspec (Specification & Unit Testing) Pure Selenium/PhantomJS (Harder integration) Mink (Browser Controlling, slow,harder integration)
  • 38. Questions & Answers Do you have any questions?