PHPUnit
In 4 parts
DjThossi/phpunit-in-four-parts

Source code for this talk. 

Feel free to follow along.
Who am I?
Sebastian Thoss
Chapter Lead Backend
Better ventures group
PHPUnit in 4 parts - ConFoo 2019
PHPUnit in 4 parts - ConFoo 2019
01 02 03 04
The four parts
Unit

Tests
Integration

Tests
Acceptance

Tests
Smoke

Tests
But first
the application to test
Quick setup
A quick setup
$ wget -O phpunit https://phar.phpunit.de/phpunit-8.phar

$ chmod +x phpunit

$ ./phpunit --version

PHPUnit 8.0.4 by Sebastian Bergmann and contributors.
Install PHPUnit
Source: https://phpunit.de/getting-started/phpunit-8.html
A quick setup
$ phpunit --generate-configuration

PHPUnit 8.0.4 by Sebastian Bergmann and contributors.

Generating phpunit.xml in /var/www

Bootstrap script (relative to path shown above; default: vendor/autoload.php): 

Tests directory (relative to path shown above; default: tests): 

Source directory (relative to path shown above; default: src): 

Generated phpunit.xml in /var/www

PHPUnit configuration file
A quick setup
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">

<testsuites>

<testsuite name="default">

<directory suffix="Test.php">tests</directory>

</testsuite>

</testsuites>

<filter>

<whitelist processUncoveredFilesFromWhitelist="true">

<directory suffix=".php">src</directory>

</whitelist>

</filter>

</phpunit>
A quick setup
<?php
declare(strict_types=1);

namespace ProjectPHPUnitTest;

use PHPUnitFrameworkTestCase;

class MyFirstTest extends TestCase

{

public function testMyFirstEntry(): void

{

$this->assertTrue(true);

}

}
Filename: MyFirstTest.php
Test methods: testMyFirstEntry
A quick setup
$ ./phpunit

PHPUnit 8.0.4 by Sebastian Bergmann and contributors.

Runtime: PHP 7.3.0 with Xdebug 2.7.0

Configuration: /var/www/phpunit.xml

. 1 / 1 (100%)

Time: 1.69 seconds, Memory: 6.00 MB

OK (1 test, 1 assertion)
Run PHPUnit
Test Pyramid
Test Pyramid
Am
ountofTests
Perform
anceofTests
Few
Many
Slow
Fast
Test Pyramid
UNIT TESTS
Sku
Color

Collection
Unit Tests
Card
Color
Mock
Mock
Source Code
PHPUnit in 4 parts - ConFoo 2019
Test Pyramid
INTEGRATION TESTS
UNIT TESTS
Sku Color
Integration Tests
Card
Color

Collection
Mock Mock
Source Code
Test Pyramid
100%
CODECOVERAGE INTEGRATION TESTS
UNIT TESTS
Sku
Color

Collection
Integration Tests
Card
Color
Mock
Mock
Test Pyramid
ACCEPTANCE TESTS
INTEGRATION TESTS
UNIT TESTS
Acceptance Tests
Card
Color

Collection
Sku Color
Source Code
Test Pyramid
ACCEPTANCE TESTS
INTEGRATION TESTS
UNIT TESTS
SMOKE
TESTS
How do SmokeTests work?
SmokeTest

Client
CI Server
Application

to test
Production Server
How do SmokeTests work?
SmokeTest

Client
CI Server
Application

to test
Production Server
https://www.confoo.ca/baz
https://www.confoo.ca/bar
https://www.confoo.ca/en
How do SmokeTests work?
https://www.confoo.ca/baz
https://www.confoo.ca/bar
https://www.confoo.ca/en
TTFB: 34ms
SmokeTest

Client
CI Server
Application

to test
Production Server
How do SmokeTests work?
https://www.confoo.ca/foobaz
https://www.confoo.ca/bar
https://www.confoo.ca/en
SmokeTest

Client
CI Server
Application

to test
Production Server
How do SmokeTests work?
TTFB: 65ms
https://www.confoo.ca/foobaz
https://www.confoo.ca/bar
https://www.confoo.ca/en
SmokeTest

Client
CI Server
Application

to test
Production Server
How do SmokeTests work?
https://www.confoo.ca/123
https://www.confoo.ca/foobaz
https://www.confoo.ca/bar
SmokeTest

Client
CI Server
Application

to test
Production Server
How do SmokeTests work?
TTFB: 620ms
https://www.confoo.ca/123
https://www.confoo.ca/foobaz
https://www.confoo.ca/bar
SmokeTest

Client
CI Server
Application

to test
Production Server
There is a library for it
DjThossi/smoke-testing-php
Github: DjThossi/smoke-testing-php
DataProvider
Single Test
Webserver
HTTP Requests
HTTP Responses
PHPUnit
Calls
Result[ ]
Result
Source Code
SmokeTests
The what, why and how
Friday @13:00 in Montréal 3
better ventures group
Blog post about faster code coverage
better__groupbetter.ventures.group
better.ventures
better.group/jobs

More Related Content

PPT
John's Top PECL Picks
PPTX
Getting started with PHPUnit
PDF
&lt;img src="../i/r_14.png" />
PPT
Mantis Installation for Windows Box
PDF
Z01 etano installation_guide
PDF
Zend Framework 1.8 workshop
ODP
Vagrant move over, here is Docker
PDF
Flask Introduction - Python Meetup
John's Top PECL Picks
Getting started with PHPUnit
&lt;img src="../i/r_14.png" />
Mantis Installation for Windows Box
Z01 etano installation_guide
Zend Framework 1.8 workshop
Vagrant move over, here is Docker
Flask Introduction - Python Meetup

What's hot (6)

PPTX
Vcpkg e vc td a ver
PPTX
Spl in the wild - zendcon2012
PPTX
Test Fest 2009
PDF
Laravel 4 package development
PPT
Learn flask in 90mins
PDF
deployer, deployment for TYPO3 CMS with ease and fun
Vcpkg e vc td a ver
Spl in the wild - zendcon2012
Test Fest 2009
Laravel 4 package development
Learn flask in 90mins
deployer, deployment for TYPO3 CMS with ease and fun
Ad

Similar to PHPUnit in 4 parts - ConFoo 2019 (20)

PPT
PHPUnit Automated Unit Testing Framework
PPTX
PPT
PDF
Fighting Fear-Driven-Development With PHPUnit
ODP
Running Symfony
PPTX
Setting up a debugging environment for Drupal
PDF
WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)
PPT
PPTX
An Introduction to Xdebug for WordPress
PDF
Behavior & Specification Driven Development in PHP - #OpenWest
PDF
How to install Open Atrium over LAMP stack
PPTX
Phalcon 2 - PHP Brazil Conference
PDF
Unit testing symfony plugins with php unit
PPT
Phpunit testing
PDF
All the Laravel things: up and running to making $$
ODP
PHP Quality Assurance Workshop PHPBenelux
PPTX
Getting started with WordPress development
PDF
Acceptance testing in php with Codeception - Techmeetup Edinburgh
PDF
Install laravel on openshift
PHPUnit Automated Unit Testing Framework
Fighting Fear-Driven-Development With PHPUnit
Running Symfony
Setting up a debugging environment for Drupal
WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)
An Introduction to Xdebug for WordPress
Behavior & Specification Driven Development in PHP - #OpenWest
How to install Open Atrium over LAMP stack
Phalcon 2 - PHP Brazil Conference
Unit testing symfony plugins with php unit
Phpunit testing
All the Laravel things: up and running to making $$
PHP Quality Assurance Workshop PHPBenelux
Getting started with WordPress development
Acceptance testing in php with Codeception - Techmeetup Edinburgh
Install laravel on openshift
Ad

More from tech.kartenmacherei (10)

PDF
Smoke tests - what why how - PHP Srbija
PDF
SmokeTests - What, Why & How - ConFoo 2019
PDF
An Ode To Boring Technology
PDF
Learning to Drive - A story about app development
PDF
Api Versioning with Docker and Nginx
PDF
PDF
Smoke Tests @ DevOps-Hamburg 06.02.2017
PDF
Don't fear the Walking Dead @ IPC 2016
PDF
99% is not enough
PDF
Don't Fear the Walking Dead @ PHPUGHH
Smoke tests - what why how - PHP Srbija
SmokeTests - What, Why & How - ConFoo 2019
An Ode To Boring Technology
Learning to Drive - A story about app development
Api Versioning with Docker and Nginx
Smoke Tests @ DevOps-Hamburg 06.02.2017
Don't fear the Walking Dead @ IPC 2016
99% is not enough
Don't Fear the Walking Dead @ PHPUGHH

Recently uploaded (20)

PDF
Alethe Consulting Corporate Profile and Solution Aproach
PDF
The Evolution of Traditional to New Media .pdf
PDF
Understand the Gitlab_presentation_task.pdf
PPTX
KSS ON CYBERSECURITY INCIDENT RESPONSE AND PLANNING MANAGEMENT.pptx
PPT
12 Things That Make People Trust a Website Instantly
PDF
Exploring The Internet Of Things(IOT).ppt
PPTX
AI_Cyberattack_Solutions AI AI AI AI .pptx
PPTX
Internet Safety for Seniors presentation
PDF
Slides: PDF The World Game (s) Eco Economic Epochs.pdf
DOCX
Powerful Ways AIRCONNECT INFOSYSTEMS Pvt Ltd Enhances IT Infrastructure in In...
PPTX
MY PRESENTATION66666666666666666666.pptx
PPTX
1402_iCSC_-_RESTful_Web_APIs_--_Josef_Hammer.pptx
PPTX
Artificial_Intelligence_Basics use in our daily life
PDF
Virtual Guard Technology Provider_ Remote Security Service Solutions.pdf
PPTX
在线订购名古屋艺术大学毕业证, buy NUA diploma学历认证失败怎么办
PDF
The_Decisive_Battle_of_Yarmuk,battle of yarmuk
PPTX
The-Importance-of-School-Sanitation.pptx
PPTX
COPD_Management_Exacerbation_Detailed_Placeholders.pptx
PDF
Paper The World Game (s) Great Redesign.pdf
PDF
KEY COB2 UNIT 1: The Business of businessĐH KInh tế TP.HCM
Alethe Consulting Corporate Profile and Solution Aproach
The Evolution of Traditional to New Media .pdf
Understand the Gitlab_presentation_task.pdf
KSS ON CYBERSECURITY INCIDENT RESPONSE AND PLANNING MANAGEMENT.pptx
12 Things That Make People Trust a Website Instantly
Exploring The Internet Of Things(IOT).ppt
AI_Cyberattack_Solutions AI AI AI AI .pptx
Internet Safety for Seniors presentation
Slides: PDF The World Game (s) Eco Economic Epochs.pdf
Powerful Ways AIRCONNECT INFOSYSTEMS Pvt Ltd Enhances IT Infrastructure in In...
MY PRESENTATION66666666666666666666.pptx
1402_iCSC_-_RESTful_Web_APIs_--_Josef_Hammer.pptx
Artificial_Intelligence_Basics use in our daily life
Virtual Guard Technology Provider_ Remote Security Service Solutions.pdf
在线订购名古屋艺术大学毕业证, buy NUA diploma学历认证失败怎么办
The_Decisive_Battle_of_Yarmuk,battle of yarmuk
The-Importance-of-School-Sanitation.pptx
COPD_Management_Exacerbation_Detailed_Placeholders.pptx
Paper The World Game (s) Great Redesign.pdf
KEY COB2 UNIT 1: The Business of businessĐH KInh tế TP.HCM

PHPUnit in 4 parts - ConFoo 2019