SlideShare a Scribd company logo
Test Driven Development
Saturday, June 23, 2012
@AUGUSTOHP

                           @ALGANET




Saturday, June 23, 2012
•   Evolução dos testes


                     AGENDA   •   Motivações

                              •   TDD (interativo)




Saturday, June 23, 2012
EVOLUÇÃO DOS TESTES




Saturday, June 23, 2012
var_dump($coisa);




Saturday, June 23, 2012
//var_dump($coisa);




Saturday, June 23, 2012
Breakpoints e Watchers!




Saturday, June 23, 2012
Breakpoints e Watchers!




Saturday, June 23, 2012
Testes automatizados




Saturday, June 23, 2012
Testes automatizados




Saturday, June 23, 2012
ão
                                açautomatizados
                              fic
                            Testes
                            ri
                          Ve




Saturday, June 23, 2012
Test Driven Development




Saturday, June 23, 2012
MOTIVAÇÃO

Saturday, June 23, 2012
CÓDIGO LIMPO QUE
                        FUNCIONA

Saturday, June 23, 2012
Esse é o código




                     CÓDIGO LIMPO QUE
                        FUNCIONA

Saturday, June 23, 2012
Esse “somos nozes”




                     CÓDIGO LIMPO QUE
                        FUNCIONA

Saturday, June 23, 2012
Objetivo do TDD




                     CÓDIGO LIMPO QUE
                        FUNCIONA

Saturday, June 23, 2012
2 REGRAS

Saturday, June 23, 2012
CÓDIGO NOVO = TESTE

Saturday, June 23, 2012
REFATORE

Saturday, June 23, 2012
O MANTRA DO TDD




Saturday, June 23, 2012
Saturday, June 23, 2012
•   Vermelho : Escreva um teste (ele vai falhar)




Saturday, June 23, 2012
•   Vermelho : Escreva um teste (ele vai falhar)

     •   Verde            : Faça o teste funcionar




Saturday, June 23, 2012
•   Vermelho : Escreva um teste (ele vai falhar)

     •   Verde            : Faça o teste funcionar

     •   Refatore




Saturday, June 23, 2012
SESSÃO INTERATIVA DE TDD




Saturday, June 23, 2012
Saturday, June 23, 2012
O que faremos?



Saturday, June 23, 2012
•     Lista de tarefas




Saturday, June 23, 2012
•     Lista de tarefas

                          •   Título




Saturday, June 23, 2012
1     <?php
    2     class TaskTest extends PHPUnit_Framework_TestCase
    3     {
    4         public function testTitle()
    5         {
    6             $task = new SfConTask;
    7             $title = 'Teste';
    8             $task->setTitle($title);
    9             $this->assertEquals($title, $task->getTitle());
   10             $this->assertEquals($title, (string) $task);
   11         }
   12     }




Saturday, June 23, 2012
1 PHPUnit 3.6.10 by Sebastian Bergmann.
   2
   3
   4 Fatal error: Class 'SfConTask' not found in /Users/
augustopascutti/Desktop/tdd/TaskTest.php on line 6




Saturday, June 23, 2012
1     <?php
    2     namespace SfCon;
    3
    4     class Task
    5     {
    6         protected $title;
    7
    8              public function setTitle($string)
    9              {
   10                  $this->title = $string;
   11                  return $this;
   12              }
   13
   14              public function getTitle()
   15              {
   16                  return $this->title;
   17              }
   18
   19              public function __toString()
   20              {
   21                  return (string) $this->getTitle();
   22              }
   23     }
Saturday, June 23, 2012
1   PHPUnit 3.6.10 by Sebastian Bergmann.
      2
      3   .
      4
      5   Time: 0 seconds, Memory: 2.75Mb
      6
      7   OK (1 test, 2 assertions)




Saturday, June 23, 2012
•     Lista de tarefas

                          •   Título

                          •   ID




Saturday, June 23, 2012
1     <?php
    2     require 'SfCon/Task.php';
    4     class TaskTest extends PHPUnit_Framework_TestCase
    5     {
    6         // ...
    7         public function testId()
    8         {
    9             $task = new SfConTask();
   10             $id   = 1;
   11             $task->setId($id);
   12             $this->assertEquals($id, $task->getId());
   13         }
   14     }




Saturday, June 23, 2012
1 PHPUnit 3.6.10 by Sebastian Bergmann.
   2
   3 .
   4 Fatal error: Call to undefined method SfConTask::setId
() in /Users/augustopascutti/Desktop/tdd/TaskTest.php on
line 19




Saturday, June 23, 2012
1     <?php
    2     require 'SfCon/Task.php';
    3
    4     class TaskTest extends PHPUnit_Framework_TestCase
    5     {
    6         // ...
    7         public function testId()
    8         {
    9             $task = new SfConTask();
   10             $id   = 1;
   11             $task->setId($id);
   12             $this->assertEquals($id, $task->getId());
   13         }
   14     }




Saturday, June 23, 2012
•     Lista de tarefas

                          •   Título

                          •   ID

                          •   Completa?




Saturday, June 23, 2012
1     <?php
    2     require 'SfCon/Task.php';
    3
    4     class TaskTest extends PHPUnit_Framework_TestCase
    5     {
    6         // ...
    7         public function testDone()
    8         {
    9             $task = new SfConTask();
   10             $this->assertFalse($task->isDone());
   11             $task->setDone(); // Default: true
   12             $this->assertTrue($task->isDone());
   13             $task->setDone(false);
   14             $this->assertFalse($task->isDone());
   15         }
   16     }




Saturday, June 23, 2012
1 PHPUnit 3.6.10 by Sebastian Bergmann.
   2
   3 ..
   4 Fatal error: Call to undefined method SfCon
Task::isDone() in /Users/augustopascutti/Desktop/tdd/
TaskTest.php on line 26




Saturday, June 23, 2012
1     <?php
    2     namespace SfCon;
    3
    4     class Task
    5     {
    6         // ...
    7         protected $done = false;
    8
    9              // ...
   10              public function setDone($bool=true)
   11              {
   12                  $this->done = (boolean) $bool;
   13                  return $this;
   14              }
   15
   16              public function isDone()
   17              {
   18                  return $this->done;
   19              }
   20     }


Saturday, June 23, 2012
1   PHPUnit 3.6.10 by Sebastian Bergmann.
      2
      3   ...
      4
      5   Time: 0 seconds, Memory: 2.75Mb
      6
      7   OK (3 tests, 6 assertions)




Saturday, June 23, 2012
•     Lista de tarefas

                          •   Título

                          •   ID

                          •   Completa?

                    •     Salvar tarefa




Saturday, June 23, 2012
1     <?php
    2     require 'SfCon/Task.php';
    3
    4     class TaskTest extends PHPUnit_Framework_TestCase
    5     {
    6         // ...
    7         public function testInsert()
    8         {
    9             $pdo = new Pdo('sqlite::memory:');
   10             $pdo->exec('CREATE TABLE tasks (
   11                  id INTEGER PRIMARY KEY,
   12                  title TEXT,
   13                  done INTEGER
   14             )');
   15             $task = new SfConTask($pdo);
   16             $expectId = 1;
   17             $task->setTitle('Test');
   18             $task->insert(); // Insert defines ID
   19             $this->assertEquals($expectId, $task->getId());
   20         }
   21     }

Saturday, June 23, 2012
1 <?php
   2 namespace SfCon;
   3
   4 class Task
   5 {
   6     // ...
   7     protected $pdo;
   8
   9     public function __construct(Pdo $pdo=null)
  10     {
  11         if (!is_null($pdo))
  12             $this->pdo = $pdo;
  13     }
  14     // ...
  15     public function insert()
  16     {
  17         $sql = 'INSERT INTO tasks (id, title, done) VALUES (?, ?, ?)';
  18         $st = $this->pdo->prepare($sql);
  19         $st->bindValue(1, $this->getId());
  20         $st->bindValue(2, $this->getTitle());
  21         $st->bindValue(3, $this->isDone());
  22         $result = $st->execute();
  23         $this->setId($this->pdo->lastInsertId());
  24         return $result;
  25     }
  26 }



Saturday, June 23, 2012
1   PHPUnit 3.6.10 by Sebastian Bergmann.
      2
      3   ....
      4
      5   Time: 0 seconds, Memory: 2.75Mb
      6
      7   OK (4 tests, 9 assertions)




Saturday, June 23, 2012
1 PHPUnit 3.6.10 by Sebastian Bergmann.
      2
      3 Task
      4 [x] Title
      5 [x] Id
      6 [x] Done
      7 [x] Insert




Saturday, June 23, 2012
1     <?php
    2     require 'SfCon/Task.php';
    3
    4     class TaskTest extends PHPUnit_Framework_TestCase
    5     {
    6         public function testSetterGetterForTitle()
    7         {
    8             // ...
    9         }
   10
   11              public function testSetterGetterForId()
   12              {
   13                  // ...
   14              }
   15
   16              public function testSetterGetterForDone()
   17              {
   18                  // ...
   19              }
   20     }


Saturday, June 23, 2012
1 PHPUnit 3.6.10 by Sebastian Bergmann.
      2
      3 Task
      4 [x] Setter getter for title
      5 [x] Setter getter for id
      6 [x] Setter getter for done
      7 [x] Insert




Saturday, June 23, 2012
Saturday, June 23, 2012
Saturday, June 23, 2012
Saturday, June 23, 2012
•     Lista de tarefas   •   Cobrir variações

                          •   Título

                          •   ID

                          •   Completa?

                    •     Salvar tarefa




Saturday, June 23, 2012
1    <?php
    2    require 'SfCon/Task.php';
    3
    4    class TaskTest extends PHPUnit_Framework_TestCase
    5    {
    6        // ...
    7        public function provideValidTitles()
    8        {
    9            return array(
   10                array('This is a valid title'),
   11                array('This is also a valid title ...'),
   12                array('Hello World'),
   13                array('Hakuna Matata'),
   14                array('Do some more tests')
   15            );
   16        }
   17
   18            /**
   19              * @dataProvider provideValidTitles
   20              */
   21            public function testSetterGetterForTitle($title)
   22            {
   23                 $this->fixture->setTitle($title);
   24                 $this->assertEquals($title, $this->fixture->getTitle());
   25                 $this->assertEquals($title, (string) $this->fixture);
   26            }
   27            // ...
Saturday, June 23, 2012
1    <?php
    2    require 'SfCon/Task.php';
    3
    4    class TaskTest extends PHPUnit_Framework_TestCase
    5    {
    6        protected $fixture;
    7        protected $pdo;
    8
    9             public function setUp()
   10             {
   11                 $this->pdo       = new Pdo('sqlite::memory:');
   12                 $this->fixture = new SfConTask($this->pdo);
   13                 $this->pdo->exec('CREATE TABLE IF NOT EXISTS tasks (
   14                      id INTEGER PRIMARY KEY,
   15                      title TEXT,
   16                      done INTEGER
   17                 )');
   18             }
   19
   20             public function tearDown()
   21             {
   22                 $this->pdo->exec('DROP TABLE tasks');
   23             }
   24             // ...
   25    }
Saturday, June 23, 2012
1   PHPUnit 3.6.10 by Sebastian Bergmann.
      2
      3   ..............
      4
      5   Time: 0 seconds, Memory: 2.75Mb
      6
      7   OK (14 tests, 45 assertions)




Saturday, June 23, 2012
Saturday, June 23, 2012
CUIDADO COM O 100% DE
              COVERAGE



Saturday, June 23, 2012
Linhas não testadas




Saturday, June 23, 2012
1     <?php
    2     require 'SfCon/Task.php';
    3
    4     class TaskTest extends PHPUnit_Framework_TestCase
    5     {
    6         /**
    7           * @dataProvider provideValidTitles
    8           */
    9         public function testSetterGetterForTitle($title)
   10         {
   11              $instance = $task->setTitle($title);
   12              $this->assertEquals($task, $instance);
   13              $this->assertEquals($title, $task->getTitle());
   14              $this->assertEquals($title, (string) $task);
   15         }
   16     }




Saturday, June 23, 2012
•     Lista de tarefas   •   Cobrir variações

                          •   Título         •   Mocks / Stubs

                          •   ID

                          •   Completa?

                    •     Salvar tarefa




Saturday, June 23, 2012
1    <?php
 2    require 'SfCon/Task.php';
 3
 4    class TaskTest extends PHPUnit_Framework_TestCase
 5    {
 6        public function testInsert()
 7        {
 8            $con = array('sqlite::memory:');
 9            $met = array('prepare', 'lastInsertId');
10            // ...
11            $this->pdo = $this->getMock('Pdo', $met, $con);
12            $this->pdo->expects($this->once())
13                      ->method('prepare')
14                      ->with($this->equalTo(SfConTask::SQL_INSE
15                      ->will($this->returnValue($mockIns));
16        }
17    }




Saturday, June 23, 2012
1     <?php
 2     require 'SfCon/Task.php';
 3
 4     class TaskTest extends PHPUnit_Framework_TestCase
 5     {
 6         public function testInsert()
 7         {
 8             // ...
 9             $met     = array('bindValue', 'execute');
10             $mockIns = $this->getMock('PdoStatement', $met);
11             $mockIns->expects($this->exactly(3))
12                     ->method('bindValue')
13                     ->with($this->greaterThan(0),
14                            $this->anything());
15             // ...
16         }
17     }



Saturday, June 23, 2012
1     <?php
 2     require 'SfCon/Task.php';
 3
 4     class TaskTest extends PHPUnit_Framework_TestCase
 5     {
 6         public function testInsert()
 7         {
 8             // ...
 9             $mockIns->expects($this->once())
10                     ->method('execute')
11                     ->will($this->returnValue(true));
12             // ...
13         }
14     }




Saturday, June 23, 2012
1     <?php
 2     require 'SfCon/Task.php';
 3
 4     class TaskTest extends PHPUnit_Framework_TestCase
 5     {
 6         public function testInsert()
 7         {
 8             // ...
 9             $this->pdo->expects($this->once())
10                       ->method('lastInsertId')
11                       ->will($this->returnValue(1));
12
13                        $task = new SfConTask($this->pdo);
14                        $task->setTitle($title);
15                        $task->insert();
16                        $this->assertEquals($expectId, $task->getId());
17              }
18     }



Saturday, June 23, 2012
1    PHPUnit 3.6.10 by Sebastian Bergmann.
  2
  3    ...............
  4
  5    Time: 0 seconds, Memory: 3.25Mb
  6
  7    OK (15 tests, 45 assertions)




Saturday, June 23, 2012
•     Lista de tarefas       •   Cobrir variações

                          •   Título             •   Mocks / Stubs

                          •   ID                 •
                                                  tas?
                                                     Bugs regressivos

                                            u   n
                          •   Completa?
                                        e rg
                    •     Salvar tarefa
                                       p


Saturday, June 23, 2012

More Related Content

What's hot

Things I Believe Now That I'm Old
Things I Believe Now That I'm OldThings I Believe Now That I'm Old
Things I Believe Now That I'm Old
Ross Tuck
 
Object Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHPObject Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHP
Chad Gray
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design Patterns
Hugo Hamon
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
Hugo Hamon
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
Hugo Hamon
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
Sam Hennessy
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
Ian Barber
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
Ian Barber
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Kacper Gunia
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)
brian d foy
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
Hugo Hamon
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
brian d foy
 
The road to continuous deployment (PHPCon Poland 2016)
The road to continuous deployment (PHPCon Poland 2016)The road to continuous deployment (PHPCon Poland 2016)
The road to continuous deployment (PHPCon Poland 2016)
Michiel Rook
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
Kacper Gunia
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using Codeception
Jeroen van Dijk
 
The IoC Hydra
The IoC HydraThe IoC Hydra
The IoC Hydra
Kacper Gunia
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
brian d foy
 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trial
brian d foy
 

What's hot (20)

Things I Believe Now That I'm Old
Things I Believe Now That I'm OldThings I Believe Now That I'm Old
Things I Believe Now That I'm Old
 
Object Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHPObject Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHP
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design Patterns
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
Php 101: PDO
Php 101: PDOPhp 101: PDO
Php 101: PDO
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
 
Shell.php
Shell.phpShell.php
Shell.php
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
The road to continuous deployment (PHPCon Poland 2016)
The road to continuous deployment (PHPCon Poland 2016)The road to continuous deployment (PHPCon Poland 2016)
The road to continuous deployment (PHPCon Poland 2016)
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using Codeception
 
The IoC Hydra
The IoC HydraThe IoC Hydra
The IoC Hydra
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trial
 

Viewers also liked

Metallica’s Top 10 Solos
Metallica’s Top 10 SolosMetallica’s Top 10 Solos
Metallica’s Top 10 Solosklaf
 
012809a The Case For Greening It
012809a The Case For Greening It012809a The Case For Greening It
012809a The Case For Greening It
WriteBrain
 
Revisão - Biologia celular
Revisão - Biologia celularRevisão - Biologia celular
Revisão - Biologia celular
Raphael Spessoto
 
Environment Week Campaign 2009
Environment Week Campaign 2009Environment Week Campaign 2009
Environment Week Campaign 2009
robertocardoso
 
ABC\'S OF A HAPPY MARRIAGE
ABC\'S OF A HAPPY MARRIAGEABC\'S OF A HAPPY MARRIAGE
ABC\'S OF A HAPPY MARRIAGE
glennpease
 
Como escalar aplicações PHP
Como escalar aplicações PHPComo escalar aplicações PHP
Como escalar aplicações PHP
Augusto Pascutti
 
Podcast Your Passion: 12 Steps to Mastery
Podcast Your Passion: 12 Steps to MasteryPodcast Your Passion: 12 Steps to Mastery
Podcast Your Passion: 12 Steps to Mastery
Len Edgerly
 
경영과정보기술 M-commerce, telemetry, 상황인식기술
경영과정보기술 M-commerce, telemetry, 상황인식기술경영과정보기술 M-commerce, telemetry, 상황인식기술
경영과정보기술 M-commerce, telemetry, 상황인식기술
gokisung
 
Falhando miseralvelmente com PHP
Falhando miseralvelmente com PHPFalhando miseralvelmente com PHP
Falhando miseralvelmente com PHP
Augusto Pascutti
 
Orientação a objetos v2
Orientação a objetos v2Orientação a objetos v2
Orientação a objetos v2
Augusto Pascutti
 
Apresentação Agência Mint
Apresentação Agência MintApresentação Agência Mint
Apresentação Agência MintVictor Macedo
 

Viewers also liked (16)

The small things
The small thingsThe small things
The small things
 
Metallica’s Top 10 Solos
Metallica’s Top 10 SolosMetallica’s Top 10 Solos
Metallica’s Top 10 Solos
 
Childsoldiers
ChildsoldiersChildsoldiers
Childsoldiers
 
Genocide
GenocideGenocide
Genocide
 
012809a The Case For Greening It
012809a The Case For Greening It012809a The Case For Greening It
012809a The Case For Greening It
 
Revisão - Biologia celular
Revisão - Biologia celularRevisão - Biologia celular
Revisão - Biologia celular
 
Environment Week Campaign 2009
Environment Week Campaign 2009Environment Week Campaign 2009
Environment Week Campaign 2009
 
ABC\'S OF A HAPPY MARRIAGE
ABC\'S OF A HAPPY MARRIAGEABC\'S OF A HAPPY MARRIAGE
ABC\'S OF A HAPPY MARRIAGE
 
Como escalar aplicações PHP
Como escalar aplicações PHPComo escalar aplicações PHP
Como escalar aplicações PHP
 
Podcast Your Passion: 12 Steps to Mastery
Podcast Your Passion: 12 Steps to MasteryPodcast Your Passion: 12 Steps to Mastery
Podcast Your Passion: 12 Steps to Mastery
 
Sol2009
Sol2009Sol2009
Sol2009
 
경영과정보기술 M-commerce, telemetry, 상황인식기술
경영과정보기술 M-commerce, telemetry, 상황인식기술경영과정보기술 M-commerce, telemetry, 상황인식기술
경영과정보기술 M-commerce, telemetry, 상황인식기술
 
Rise Spread Islam
Rise Spread IslamRise Spread Islam
Rise Spread Islam
 
Falhando miseralvelmente com PHP
Falhando miseralvelmente com PHPFalhando miseralvelmente com PHP
Falhando miseralvelmente com PHP
 
Orientação a objetos v2
Orientação a objetos v2Orientação a objetos v2
Orientação a objetos v2
 
Apresentação Agência Mint
Apresentação Agência MintApresentação Agência Mint
Apresentação Agência Mint
 

Similar to SfCon: Test Driven Development

Node Access in Drupal 7 (and Drupal 8)
Node Access in Drupal 7 (and Drupal 8)Node Access in Drupal 7 (and Drupal 8)
Node Access in Drupal 7 (and Drupal 8)
nyccamp
 
Jeremiah Caballero - Introduction of Clean Code
Jeremiah Caballero - Introduction of Clean CodeJeremiah Caballero - Introduction of Clean Code
Jeremiah Caballero - Introduction of Clean Code
Awesome Ars Academia
 
PHPUnit your bug exterminator
PHPUnit your bug exterminatorPHPUnit your bug exterminator
PHPUnit your bug exterminator
rjsmelo
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
Lorna Mitchell
 
3 reasons to contribute to drupal florian loretan (eng)
3 reasons to contribute to drupal florian loretan (eng)3 reasons to contribute to drupal florian loretan (eng)
3 reasons to contribute to drupal florian loretan (eng)drupalconf
 
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
PROIDEA
 
Be pragmatic, be SOLID
Be pragmatic, be SOLIDBe pragmatic, be SOLID
Be pragmatic, be SOLID
Krzysztof Menżyk
 
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Krzysztof Menżyk
 
Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014
Eric Hogue
 
PHPSpec BDD Framework
PHPSpec BDD FrameworkPHPSpec BDD Framework
PHPSpec BDD Framework
Marcello Duarte
 
Groovy And Grails JUG Padova
Groovy And Grails JUG PadovaGroovy And Grails JUG Padova
Groovy And Grails JUG Padova
John Leach
 
Ciconf 2012 - Better than Ad-hoc
Ciconf 2012 - Better than Ad-hocCiconf 2012 - Better than Ad-hoc
Ciconf 2012 - Better than Ad-hoc
Calvin Froedge
 
Eclipse Democamp Zurich
Eclipse Democamp ZurichEclipse Democamp Zurich
Eclipse Democamp Zurich
Marcel Bruch
 
Modernising Legacy Code
Modernising Legacy CodeModernising Legacy Code
Modernising Legacy Code
SamThePHPDev
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
Roman Pichlík
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
Daniel Waligóra
 
Design how your objects talk through mocking
Design how your objects talk through mockingDesign how your objects talk through mocking
Design how your objects talk through mocking
Konstantin Kudryashov
 
Scalable JavaScript
Scalable JavaScriptScalable JavaScript
Scalable JavaScript
Ynon Perek
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
Michelangelo van Dam
 

Similar to SfCon: Test Driven Development (20)

Node Access in Drupal 7 (and Drupal 8)
Node Access in Drupal 7 (and Drupal 8)Node Access in Drupal 7 (and Drupal 8)
Node Access in Drupal 7 (and Drupal 8)
 
Jeremiah Caballero - Introduction of Clean Code
Jeremiah Caballero - Introduction of Clean CodeJeremiah Caballero - Introduction of Clean Code
Jeremiah Caballero - Introduction of Clean Code
 
PHPUnit your bug exterminator
PHPUnit your bug exterminatorPHPUnit your bug exterminator
PHPUnit your bug exterminator
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
3 reasons to contribute to drupal florian loretan (eng)
3 reasons to contribute to drupal florian loretan (eng)3 reasons to contribute to drupal florian loretan (eng)
3 reasons to contribute to drupal florian loretan (eng)
 
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
 
Be pragmatic, be SOLID
Be pragmatic, be SOLIDBe pragmatic, be SOLID
Be pragmatic, be SOLID
 
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
 
Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014
 
PHPSpec BDD Framework
PHPSpec BDD FrameworkPHPSpec BDD Framework
PHPSpec BDD Framework
 
Groovy And Grails JUG Padova
Groovy And Grails JUG PadovaGroovy And Grails JUG Padova
Groovy And Grails JUG Padova
 
Ciconf 2012 - Better than Ad-hoc
Ciconf 2012 - Better than Ad-hocCiconf 2012 - Better than Ad-hoc
Ciconf 2012 - Better than Ad-hoc
 
Eclipse Democamp Zurich
Eclipse Democamp ZurichEclipse Democamp Zurich
Eclipse Democamp Zurich
 
Modernising Legacy Code
Modernising Legacy CodeModernising Legacy Code
Modernising Legacy Code
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
 
Design how your objects talk through mocking
Design how your objects talk through mockingDesign how your objects talk through mocking
Design how your objects talk through mocking
 
Scalable JavaScript
Scalable JavaScriptScalable JavaScript
Scalable JavaScript
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
 

More from Augusto Pascutti

Errors
ErrorsErrors
Porque VIM?
Porque VIM?Porque VIM?
Porque VIM?
Augusto Pascutti
 
Logs: O que comem, onde vivem e como se reproduzem.
Logs: O que comem, onde vivem e como se reproduzem.Logs: O que comem, onde vivem e como se reproduzem.
Logs: O que comem, onde vivem e como se reproduzem.
Augusto Pascutti
 
TDD - Test Driven Development (em PHP)
TDD - Test Driven Development (em PHP)TDD - Test Driven Development (em PHP)
TDD - Test Driven Development (em PHP)
Augusto Pascutti
 
Guia do mochileiro para escalabilidade
Guia do mochileiro para escalabilidadeGuia do mochileiro para escalabilidade
Guia do mochileiro para escalabilidade
Augusto Pascutti
 
Somos jardineiros
Somos jardineirosSomos jardineiros
Somos jardineiros
Augusto Pascutti
 
PHP - O que, porquê e como
PHP - O que, porquê e comoPHP - O que, porquê e como
PHP - O que, porquê e como
Augusto Pascutti
 
Frameworks PHP
Frameworks PHPFrameworks PHP
Frameworks PHP
Augusto Pascutti
 
Testar é bom, integrar é ainda melhor
Testar é bom, integrar é ainda melhorTestar é bom, integrar é ainda melhor
Testar é bom, integrar é ainda melhor
Augusto Pascutti
 
PHPSC Conference 2010 - Testar é bom, integrar é melhor ainda!
PHPSC Conference 2010 - Testar é bom, integrar é melhor ainda!PHPSC Conference 2010 - Testar é bom, integrar é melhor ainda!
PHPSC Conference 2010 - Testar é bom, integrar é melhor ainda!
Augusto Pascutti
 
Segurança em PHP
Segurança em PHPSegurança em PHP
Segurança em PHP
Augusto Pascutti
 
Orientação a Objetos com PHP
Orientação a Objetos com PHPOrientação a Objetos com PHP
Orientação a Objetos com PHPAugusto Pascutti
 
Boas Práticas, Práticas !
Boas Práticas, Práticas !Boas Práticas, Práticas !
Boas Práticas, Práticas !
Augusto Pascutti
 
Mitos do PHP
Mitos do PHPMitos do PHP
Mitos do PHP
Augusto Pascutti
 
Mão na Massa: Orientação a Objetos na Prática
Mão na Massa: Orientação a Objetos na PráticaMão na Massa: Orientação a Objetos na Prática
Mão na Massa: Orientação a Objetos na Prática
Augusto Pascutti
 

More from Augusto Pascutti (16)

Errors
ErrorsErrors
Errors
 
Porque VIM?
Porque VIM?Porque VIM?
Porque VIM?
 
Logs: O que comem, onde vivem e como se reproduzem.
Logs: O que comem, onde vivem e como se reproduzem.Logs: O que comem, onde vivem e como se reproduzem.
Logs: O que comem, onde vivem e como se reproduzem.
 
TDD - Test Driven Development (em PHP)
TDD - Test Driven Development (em PHP)TDD - Test Driven Development (em PHP)
TDD - Test Driven Development (em PHP)
 
Guia do mochileiro para escalabilidade
Guia do mochileiro para escalabilidadeGuia do mochileiro para escalabilidade
Guia do mochileiro para escalabilidade
 
Under engineer
Under engineerUnder engineer
Under engineer
 
Somos jardineiros
Somos jardineirosSomos jardineiros
Somos jardineiros
 
PHP - O que, porquê e como
PHP - O que, porquê e comoPHP - O que, porquê e como
PHP - O que, porquê e como
 
Frameworks PHP
Frameworks PHPFrameworks PHP
Frameworks PHP
 
Testar é bom, integrar é ainda melhor
Testar é bom, integrar é ainda melhorTestar é bom, integrar é ainda melhor
Testar é bom, integrar é ainda melhor
 
PHPSC Conference 2010 - Testar é bom, integrar é melhor ainda!
PHPSC Conference 2010 - Testar é bom, integrar é melhor ainda!PHPSC Conference 2010 - Testar é bom, integrar é melhor ainda!
PHPSC Conference 2010 - Testar é bom, integrar é melhor ainda!
 
Segurança em PHP
Segurança em PHPSegurança em PHP
Segurança em PHP
 
Orientação a Objetos com PHP
Orientação a Objetos com PHPOrientação a Objetos com PHP
Orientação a Objetos com PHP
 
Boas Práticas, Práticas !
Boas Práticas, Práticas !Boas Práticas, Práticas !
Boas Práticas, Práticas !
 
Mitos do PHP
Mitos do PHPMitos do PHP
Mitos do PHP
 
Mão na Massa: Orientação a Objetos na Prática
Mão na Massa: Orientação a Objetos na PráticaMão na Massa: Orientação a Objetos na Prática
Mão na Massa: Orientação a Objetos na Prática
 

Recently uploaded

GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 

Recently uploaded (20)

GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 

SfCon: Test Driven Development

  • 2. @AUGUSTOHP @ALGANET Saturday, June 23, 2012
  • 3. Evolução dos testes AGENDA • Motivações • TDD (interativo) Saturday, June 23, 2012
  • 11. ão açautomatizados fic Testes ri Ve Saturday, June 23, 2012
  • 14. CÓDIGO LIMPO QUE FUNCIONA Saturday, June 23, 2012
  • 15. Esse é o código CÓDIGO LIMPO QUE FUNCIONA Saturday, June 23, 2012
  • 16. Esse “somos nozes” CÓDIGO LIMPO QUE FUNCIONA Saturday, June 23, 2012
  • 17. Objetivo do TDD CÓDIGO LIMPO QUE FUNCIONA Saturday, June 23, 2012
  • 19. CÓDIGO NOVO = TESTE Saturday, June 23, 2012
  • 21. O MANTRA DO TDD Saturday, June 23, 2012
  • 23. Vermelho : Escreva um teste (ele vai falhar) Saturday, June 23, 2012
  • 24. Vermelho : Escreva um teste (ele vai falhar) • Verde : Faça o teste funcionar Saturday, June 23, 2012
  • 25. Vermelho : Escreva um teste (ele vai falhar) • Verde : Faça o teste funcionar • Refatore Saturday, June 23, 2012
  • 26. SESSÃO INTERATIVA DE TDD Saturday, June 23, 2012
  • 28. O que faremos? Saturday, June 23, 2012
  • 29. Lista de tarefas Saturday, June 23, 2012
  • 30. Lista de tarefas • Título Saturday, June 23, 2012
  • 31. 1 <?php 2 class TaskTest extends PHPUnit_Framework_TestCase 3 { 4 public function testTitle() 5 { 6 $task = new SfConTask; 7 $title = 'Teste'; 8 $task->setTitle($title); 9 $this->assertEquals($title, $task->getTitle()); 10 $this->assertEquals($title, (string) $task); 11 } 12 } Saturday, June 23, 2012
  • 32. 1 PHPUnit 3.6.10 by Sebastian Bergmann. 2 3 4 Fatal error: Class 'SfConTask' not found in /Users/ augustopascutti/Desktop/tdd/TaskTest.php on line 6 Saturday, June 23, 2012
  • 33. 1 <?php 2 namespace SfCon; 3 4 class Task 5 { 6 protected $title; 7 8 public function setTitle($string) 9 { 10 $this->title = $string; 11 return $this; 12 } 13 14 public function getTitle() 15 { 16 return $this->title; 17 } 18 19 public function __toString() 20 { 21 return (string) $this->getTitle(); 22 } 23 } Saturday, June 23, 2012
  • 34. 1 PHPUnit 3.6.10 by Sebastian Bergmann. 2 3 . 4 5 Time: 0 seconds, Memory: 2.75Mb 6 7 OK (1 test, 2 assertions) Saturday, June 23, 2012
  • 35. Lista de tarefas • Título • ID Saturday, June 23, 2012
  • 36. 1 <?php 2 require 'SfCon/Task.php'; 4 class TaskTest extends PHPUnit_Framework_TestCase 5 { 6 // ... 7 public function testId() 8 { 9 $task = new SfConTask(); 10 $id = 1; 11 $task->setId($id); 12 $this->assertEquals($id, $task->getId()); 13 } 14 } Saturday, June 23, 2012
  • 37. 1 PHPUnit 3.6.10 by Sebastian Bergmann. 2 3 . 4 Fatal error: Call to undefined method SfConTask::setId () in /Users/augustopascutti/Desktop/tdd/TaskTest.php on line 19 Saturday, June 23, 2012
  • 38. 1 <?php 2 require 'SfCon/Task.php'; 3 4 class TaskTest extends PHPUnit_Framework_TestCase 5 { 6 // ... 7 public function testId() 8 { 9 $task = new SfConTask(); 10 $id = 1; 11 $task->setId($id); 12 $this->assertEquals($id, $task->getId()); 13 } 14 } Saturday, June 23, 2012
  • 39. Lista de tarefas • Título • ID • Completa? Saturday, June 23, 2012
  • 40. 1 <?php 2 require 'SfCon/Task.php'; 3 4 class TaskTest extends PHPUnit_Framework_TestCase 5 { 6 // ... 7 public function testDone() 8 { 9 $task = new SfConTask(); 10 $this->assertFalse($task->isDone()); 11 $task->setDone(); // Default: true 12 $this->assertTrue($task->isDone()); 13 $task->setDone(false); 14 $this->assertFalse($task->isDone()); 15 } 16 } Saturday, June 23, 2012
  • 41. 1 PHPUnit 3.6.10 by Sebastian Bergmann. 2 3 .. 4 Fatal error: Call to undefined method SfCon Task::isDone() in /Users/augustopascutti/Desktop/tdd/ TaskTest.php on line 26 Saturday, June 23, 2012
  • 42. 1 <?php 2 namespace SfCon; 3 4 class Task 5 { 6 // ... 7 protected $done = false; 8 9 // ... 10 public function setDone($bool=true) 11 { 12 $this->done = (boolean) $bool; 13 return $this; 14 } 15 16 public function isDone() 17 { 18 return $this->done; 19 } 20 } Saturday, June 23, 2012
  • 43. 1 PHPUnit 3.6.10 by Sebastian Bergmann. 2 3 ... 4 5 Time: 0 seconds, Memory: 2.75Mb 6 7 OK (3 tests, 6 assertions) Saturday, June 23, 2012
  • 44. Lista de tarefas • Título • ID • Completa? • Salvar tarefa Saturday, June 23, 2012
  • 45. 1 <?php 2 require 'SfCon/Task.php'; 3 4 class TaskTest extends PHPUnit_Framework_TestCase 5 { 6 // ... 7 public function testInsert() 8 { 9 $pdo = new Pdo('sqlite::memory:'); 10 $pdo->exec('CREATE TABLE tasks ( 11 id INTEGER PRIMARY KEY, 12 title TEXT, 13 done INTEGER 14 )'); 15 $task = new SfConTask($pdo); 16 $expectId = 1; 17 $task->setTitle('Test'); 18 $task->insert(); // Insert defines ID 19 $this->assertEquals($expectId, $task->getId()); 20 } 21 } Saturday, June 23, 2012
  • 46. 1 <?php 2 namespace SfCon; 3 4 class Task 5 { 6 // ... 7 protected $pdo; 8 9 public function __construct(Pdo $pdo=null) 10 { 11 if (!is_null($pdo)) 12 $this->pdo = $pdo; 13 } 14 // ... 15 public function insert() 16 { 17 $sql = 'INSERT INTO tasks (id, title, done) VALUES (?, ?, ?)'; 18 $st = $this->pdo->prepare($sql); 19 $st->bindValue(1, $this->getId()); 20 $st->bindValue(2, $this->getTitle()); 21 $st->bindValue(3, $this->isDone()); 22 $result = $st->execute(); 23 $this->setId($this->pdo->lastInsertId()); 24 return $result; 25 } 26 } Saturday, June 23, 2012
  • 47. 1 PHPUnit 3.6.10 by Sebastian Bergmann. 2 3 .... 4 5 Time: 0 seconds, Memory: 2.75Mb 6 7 OK (4 tests, 9 assertions) Saturday, June 23, 2012
  • 48. 1 PHPUnit 3.6.10 by Sebastian Bergmann. 2 3 Task 4 [x] Title 5 [x] Id 6 [x] Done 7 [x] Insert Saturday, June 23, 2012
  • 49. 1 <?php 2 require 'SfCon/Task.php'; 3 4 class TaskTest extends PHPUnit_Framework_TestCase 5 { 6 public function testSetterGetterForTitle() 7 { 8 // ... 9 } 10 11 public function testSetterGetterForId() 12 { 13 // ... 14 } 15 16 public function testSetterGetterForDone() 17 { 18 // ... 19 } 20 } Saturday, June 23, 2012
  • 50. 1 PHPUnit 3.6.10 by Sebastian Bergmann. 2 3 Task 4 [x] Setter getter for title 5 [x] Setter getter for id 6 [x] Setter getter for done 7 [x] Insert Saturday, June 23, 2012
  • 54. Lista de tarefas • Cobrir variações • Título • ID • Completa? • Salvar tarefa Saturday, June 23, 2012
  • 55. 1 <?php 2 require 'SfCon/Task.php'; 3 4 class TaskTest extends PHPUnit_Framework_TestCase 5 { 6 // ... 7 public function provideValidTitles() 8 { 9 return array( 10 array('This is a valid title'), 11 array('This is also a valid title ...'), 12 array('Hello World'), 13 array('Hakuna Matata'), 14 array('Do some more tests') 15 ); 16 } 17 18 /** 19 * @dataProvider provideValidTitles 20 */ 21 public function testSetterGetterForTitle($title) 22 { 23 $this->fixture->setTitle($title); 24 $this->assertEquals($title, $this->fixture->getTitle()); 25 $this->assertEquals($title, (string) $this->fixture); 26 } 27 // ... Saturday, June 23, 2012
  • 56. 1 <?php 2 require 'SfCon/Task.php'; 3 4 class TaskTest extends PHPUnit_Framework_TestCase 5 { 6 protected $fixture; 7 protected $pdo; 8 9 public function setUp() 10 { 11 $this->pdo = new Pdo('sqlite::memory:'); 12 $this->fixture = new SfConTask($this->pdo); 13 $this->pdo->exec('CREATE TABLE IF NOT EXISTS tasks ( 14 id INTEGER PRIMARY KEY, 15 title TEXT, 16 done INTEGER 17 )'); 18 } 19 20 public function tearDown() 21 { 22 $this->pdo->exec('DROP TABLE tasks'); 23 } 24 // ... 25 } Saturday, June 23, 2012
  • 57. 1 PHPUnit 3.6.10 by Sebastian Bergmann. 2 3 .............. 4 5 Time: 0 seconds, Memory: 2.75Mb 6 7 OK (14 tests, 45 assertions) Saturday, June 23, 2012
  • 59. CUIDADO COM O 100% DE COVERAGE Saturday, June 23, 2012
  • 61. 1 <?php 2 require 'SfCon/Task.php'; 3 4 class TaskTest extends PHPUnit_Framework_TestCase 5 { 6 /** 7 * @dataProvider provideValidTitles 8 */ 9 public function testSetterGetterForTitle($title) 10 { 11 $instance = $task->setTitle($title); 12 $this->assertEquals($task, $instance); 13 $this->assertEquals($title, $task->getTitle()); 14 $this->assertEquals($title, (string) $task); 15 } 16 } Saturday, June 23, 2012
  • 62. Lista de tarefas • Cobrir variações • Título • Mocks / Stubs • ID • Completa? • Salvar tarefa Saturday, June 23, 2012
  • 63. 1 <?php 2 require 'SfCon/Task.php'; 3 4 class TaskTest extends PHPUnit_Framework_TestCase 5 { 6 public function testInsert() 7 { 8 $con = array('sqlite::memory:'); 9 $met = array('prepare', 'lastInsertId'); 10 // ... 11 $this->pdo = $this->getMock('Pdo', $met, $con); 12 $this->pdo->expects($this->once()) 13 ->method('prepare') 14 ->with($this->equalTo(SfConTask::SQL_INSE 15 ->will($this->returnValue($mockIns)); 16 } 17 } Saturday, June 23, 2012
  • 64. 1 <?php 2 require 'SfCon/Task.php'; 3 4 class TaskTest extends PHPUnit_Framework_TestCase 5 { 6 public function testInsert() 7 { 8 // ... 9 $met = array('bindValue', 'execute'); 10 $mockIns = $this->getMock('PdoStatement', $met); 11 $mockIns->expects($this->exactly(3)) 12 ->method('bindValue') 13 ->with($this->greaterThan(0), 14 $this->anything()); 15 // ... 16 } 17 } Saturday, June 23, 2012
  • 65. 1 <?php 2 require 'SfCon/Task.php'; 3 4 class TaskTest extends PHPUnit_Framework_TestCase 5 { 6 public function testInsert() 7 { 8 // ... 9 $mockIns->expects($this->once()) 10 ->method('execute') 11 ->will($this->returnValue(true)); 12 // ... 13 } 14 } Saturday, June 23, 2012
  • 66. 1 <?php 2 require 'SfCon/Task.php'; 3 4 class TaskTest extends PHPUnit_Framework_TestCase 5 { 6 public function testInsert() 7 { 8 // ... 9 $this->pdo->expects($this->once()) 10 ->method('lastInsertId') 11 ->will($this->returnValue(1)); 12 13 $task = new SfConTask($this->pdo); 14 $task->setTitle($title); 15 $task->insert(); 16 $this->assertEquals($expectId, $task->getId()); 17 } 18 } Saturday, June 23, 2012
  • 67. 1 PHPUnit 3.6.10 by Sebastian Bergmann. 2 3 ............... 4 5 Time: 0 seconds, Memory: 3.25Mb 6 7 OK (15 tests, 45 assertions) Saturday, June 23, 2012
  • 68. Lista de tarefas • Cobrir variações • Título • Mocks / Stubs • ID • tas? Bugs regressivos u n • Completa? e rg • Salvar tarefa p Saturday, June 23, 2012