SlideShare une entreprise Scribd logo
1  sur  68
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

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 OldRoss Tuck
 
Object Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHPObject Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHPChad Gray
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design PatternsHugo Hamon
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistenceHugo 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 PimpleHugo Hamon
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsSam 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 VersionIan Barber
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersIan 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 needKacper 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 & RESTHugo Hamon
 
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 2016Kacper Gunia
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using CodeceptionJeroen van Dijk
 
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 trialbrian d foy
 

Tendances (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
 

En vedette

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 ItWriteBrain
 
Revisão - Biologia celular
Revisão - Biologia celularRevisão - Biologia celular
Revisão - Biologia celularRaphael Spessoto
 
Environment Week Campaign 2009
Environment Week Campaign 2009Environment Week Campaign 2009
Environment Week Campaign 2009robertocardoso
 
ABC\'S OF A HAPPY MARRIAGE
ABC\'S OF A HAPPY MARRIAGEABC\'S OF A HAPPY MARRIAGE
ABC\'S OF A HAPPY MARRIAGEglennpease
 
Como escalar aplicações PHP
Como escalar aplicações PHPComo escalar aplicações PHP
Como escalar aplicações PHPAugusto 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 MasteryLen 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 PHPAugusto Pascutti
 
Apresentação Agência Mint
Apresentação Agência MintApresentação Agência Mint
Apresentação Agência MintVictor Macedo
 

En vedette (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
 

Similaire à 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 CodeAwesome Ars Academia
 
PHPUnit your bug exterminator
PHPUnit your bug exterminatorPHPUnit your bug exterminator
PHPUnit your bug exterminatorrjsmelo
 
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żykPROIDEA
 
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 2014Eric Hogue
 
Groovy And Grails JUG Padova
Groovy And Grails JUG PadovaGroovy And Grails JUG Padova
Groovy And Grails JUG PadovaJohn Leach
 
Ciconf 2012 - Better than Ad-hoc
Ciconf 2012 - Better than Ad-hocCiconf 2012 - Better than Ad-hoc
Ciconf 2012 - Better than Ad-hocCalvin Froedge
 
Eclipse Democamp Zurich
Eclipse Democamp ZurichEclipse Democamp Zurich
Eclipse Democamp ZurichMarcel Bruch
 
Modernising Legacy Code
Modernising Legacy CodeModernising Legacy Code
Modernising Legacy CodeSamThePHPDev
 
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 mockingKonstantin Kudryashov
 
Scalable JavaScript
Scalable JavaScriptScalable JavaScript
Scalable JavaScriptYnon Perek
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitMichelangelo van Dam
 

Similaire à 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
 

Plus de 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 escalabilidadeAugusto Pascutti
 
PHP - O que, porquê e como
PHP - O que, porquê e comoPHP - O que, porquê e como
PHP - O que, porquê e comoAugusto Pascutti
 
Testar é bom, integrar é ainda melhor
Testar é bom, integrar é ainda melhorTestar é bom, integrar é ainda melhor
Testar é bom, integrar é ainda melhorAugusto 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
 
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
 
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áticaAugusto Pascutti
 

Plus de 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
 

Dernier

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Dernier (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

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