4. Découvrir des bugs
Permettre de réfactorer
Documenter
Réfléchir à l’interface du système
Détecter des problèmes de design
Photo by Brooke Lark on Unsplash
5. Découvrir des bugs
Permettre de réfactorer
Documenter
Réfléchir à l’interface du système
Détecter des problèmes de design
Photo by Brooke Lark on Unsplash
6. Découvrir des bugs
Permettre de réfactorer
Documenter
Réfléchir à l’interface du système
Détecter des problèmes de design
Photo by Brooke Lark on Unsplash
7. Découvrir des bugs
Permettre de réfactorer
Documenter
Réfléchir à l’interface du système
Détecter des problèmes de design
Photo by Brooke Lark on Unsplash
8. Découvrir des bugs
Permettre de réfactorer
Documenter
Réfléchir à l’interface du système
Détecter des problèmes de design
Photo by Brooke Lark on Unsplash
9. Indépendants de l’implémentation
Décrire le comportement du système
Avoir un résultat prédictible
Rapides
Indépendants les uns des autres
Simple à mettre en place
Photo by Brooke Lark on Unsplash
10. Indépendants de l’implémentation
Décrire le comportement du système
Avoir un résultat prédictible
Rapides
Indépendants les uns des autres
Simple à mettre en place
Photo by Brooke Lark on Unsplash
11. Indépendants de l’implémentation
Décrire le comportement du système
Avoir un résultat prédictible
Rapides
Indépendants les uns des autres
Simple à mettre en place
Photo by Brooke Lark on Unsplash
12. Indépendants de l’implémentation
Décrire le comportement du système
Avoir un résultat prédictible
Rapides
Indépendants les uns des autres
Simple à mettre en place
Photo by Brooke Lark on Unsplash
13. Indépendants de l’implémentation
Décrire le comportement du système
Avoir un résultat prédictible
Rapides
Indépendants les uns des autres
Simple à mettre en place
Photo by Brooke Lark on Unsplash
14. Indépendants de l’implémentation
Décrire le comportement du système
Avoir un résultat prédictible
Rapides
Indépendants les uns des autres
Simple à mettre en place
Photo by Brooke Lark on Unsplash
17. class ServeurTest extends PHPUnit_Framework_TestCase {
public function test_il_annonce_le_plat_du_jour()
{
$cuisine = $this->prophesize(Cuisine::class);
$cuisine
->quelEstLePlatDuJour()
->willReturn('Gencives de porc !');
$serveur = new Serveur($cuisine->reveal());
$annonce = $serveur->annonceLePlatDuJour();
$this->assertEquals(
'Le chef vous propose aujourd'hui des gencives de porc',
$annonce
);
}
}
18. class ServeurTest extends PHPUnit_Framework_TestCase {
public function test_il_annonce_le_plat_du_jour()
{
$cuisine = $this->prophesize(Cuisine::class);
$cuisine
->quelEstLePlatDuJour()
->willReturn('Gencives de porc !');
$serveur = new Serveur($cuisine->reveal());
$annonce = $serveur->annonceLePlatDuJour();
$this->assertEquals(
'Le chef vous propose aujourd'hui des gencives de porc',
$annonce
);
}
}
19. public function testIlAnnonceLePlatDuJour()
public function test_il_annonce_le_plat_du_jour()
/**
* @test
*/
public function il_annonce_le_plat_du_jour()
/**
* @test
*/
public function il annonce le plat du jour()
22. class ServeurTest extends PHPUnit_Framework_TestCase {
public function test_il_annonce_le_plat_du_jour()
{
$cuisine = $this->prophesize(Cuisine::class);
$cuisine
->quelEstLePlatDuJour()
->willReturn('Gencives de porc !');
$serveur = new Serveur($cuisine->reveal());
$annonce = $serveur->annonceLePlatDuJour();
$this->assertEquals(
'Le chef vous propose aujourd'hui des gencives de porc',
$annonce
);
}
}
23. ➜ recettes phpunit --testdox tests/ServeurTest.php
PHPUnit 4.7.6 by Sebastian Bergmann and contributors.
Serveur
[x] il annonce le plat du jour
[x] il transmet une commande pour le plat du jour a la cuisine
24. ➜ recettes phpunit --testdox tests/ServeurTest.php
PHPUnit 4.7.6 by Sebastian Bergmann and contributors.
Serveur
[x] il annonce le plat du jour
[x] il transmet une commande pour le plat du jour a la cuisine
25. class ServeurTest extends PHPUnit_Framework_TestCase {
public function test_il_annonce_le_plat_du_jour()
{
$cuisine = $this->prophesize(Cuisine::class);
$cuisine
->quelEstLePlatDuJour()
->willReturn('Gencives de porc !');
$serveur = new Serveur($cuisine->reveal());
$annonce = $serveur->annonceLePlatDuJour();
$this->assertEquals(
'Le chef vous propose aujourd'hui des gencives de porc',
$annonce
);
}
}
26. class ServeurTest extends PHPUnit_Framework_TestCase {
public function test_il_annonce_le_plat_du_jour()
{
$cuisine = $this->prophesize(Cuisine::class);
$cuisine
->quelEstLePlatDuJour()
->willReturn('Gencives de porc !');
$serveur = new Serveur($cuisine->reveal());
$annonce = $serveur->annonceLePlatDuJour();
$this->assertEquals(
'Le chef vous propose aujourd'hui des gencives de porc',
$annonce
);
}
}
28. class ServeurTest extends PHPUnit_Framework_TestCase {
public function test_il_annonce_le_plat_du_jour()
{
$cuisine = $this->prophesize(Cuisine::class);
$cuisine
->quelEstLePlatDuJour()
->willReturn('Gencives de porc !');
$serveur = new Serveur($cuisine->reveal());
$annonce = $serveur->annonceLePlatDuJour();
$this->assertEquals(
'Le chef vous propose aujourd'hui des
gencives de porc',
$annonce
);
}
}
29. class ServeurTest extends PHPUnit_Framework_TestCase {
public function test_il_annonce_le_plat_du_jour()
{
$cuisine = $this->prophesize(Cuisine::class);
$cuisine
->quelEstLePlatDuJour()
->willReturn('Gencives de porc !');
$serveur = new Serveur($cuisine->reveal());
$annonce = $serveur->annonceLePlatDuJour();
$this->assertEquals(
'Le chef vous propose aujourd'hui des
gencives de porc',
$annonce
);
}
}
Arrange
30. class ServeurTest extends PHPUnit_Framework_TestCase {
public function test_il_annonce_le_plat_du_jour()
{
$cuisine = $this->prophesize(Cuisine::class);
$cuisine
->quelEstLePlatDuJour()
->willReturn('Gencives de porc !');
$serveur = new Serveur($cuisine->reveal());
$annonce = $serveur->annonceLePlatDuJour();
$this->assertEquals(
'Le chef vous propose aujourd'hui des
gencives de porc',
$annonce
);
}
}
Act
31. class ServeurTest extends PHPUnit_Framework_TestCase {
public function test_il_annonce_le_plat_du_jour()
{
$cuisine = $this->prophesize(Cuisine::class);
$cuisine
->quelEstLePlatDuJour()
->willReturn('Gencives de porc !');
$serveur = new Serveur($cuisine->reveal());
$annonce = $serveur->annonceLePlatDuJour();
$this->assertEquals(
'Le chef vous propose aujourd'hui des
gencives de porc',
$annonce
);
}
}
Assert
33. public function test_annonce_le_plat_du_jour()
{
$cuisine = $this->prophesize(Cuisine::class);
$cuisine
->quelEstLePlat()
->willReturn('Gencives de porc !')
->shouldBeCalledTimes(1);
$serveur = new Serveur($cuisine->reveal());
$annonce = $serveur->annonceLePlatDuJour();
$this->assertEquals(
'Le chef vous propose aujourd'hui des gencives de porc',
$annonce
);
}
34. class Serveur {
public function annonceLeMenu() {
$plat = $this->cuisine->quelEstLePlatDuJour();
// fait autre chose, oublie le menu
$plat = $this->cuisine->quelEstLePlatDuJour();
return sprintf(
'Le chef vous propose aujourd'hui %s',
$this->transformeNomDuPlat($plat)
);
}
}
35. class Serveur {
public function annonceLeMenu() {
$plat = 'Gencives de porc !';
return sprintf(
'Le chef vous propose aujourd'hui %s',
$this->transformeNomDuPlat($plat)
);
}
}
36. public function test_annonce_le_plat_du_jour()
{
$cuisine = $this->prophesize(Cuisine::class);
$cuisine
->quelEstLePlat()
->willReturn('Gencives de porc !')
->shouldBeCalledTimes(1);
$serveur = new Serveur($cuisine->reveal());
$annonce = $serveur->annonceLePlatDuJour();
$this->assertEquals(
'Le chef vous propose aujourd'hui des gencives de porc',
$annonce
);
}
37. public function test_annonce_le_plat_du_jour()
{
$cuisine = $this->prophesize(Cuisine::class);
$cuisine
->quelEstLePlatDuJour()
->willReturn('Gencives de porc !');
$serveur = new Serveur($cuisine->reveal());
$annonce = $serveur->annonceLePlatDuJour();
$this->assertEquals(
'Le chef vous propose aujourd'hui des gencives de porc',
$annonce
);
}
38. class ServeurTest extends PHPUnit_Framework_TestCase {
public function test_transmet_une_commande_pour_le_plat_du_jour_a_la_cuisine()
{
$cuisine = $this->prophesize(Cuisine::class);
$serveur = new Serveur($cuisine->reveal());
$serveur->recoitUneCommandePourUnPlatDuJour();
$cuisine
->ilFautUnPlatDuJour()
->shouldHaveBeenCalledTimes(1);
}
}
39. class ServeurTest extends PHPUnit_Framework_TestCase {
public function test_transmet_une_commande_pour_le_plat_du_jour_a_la_cuisine()
{
$cuisine = $this->prophesize(Cuisine::class);
$serveur = new Serveur($cuisine->reveal());
$serveur->recoitUneCommandePourUnPlatDuJour();
$cuisine
->ilFautUnPlatDuJour()
->shouldHaveBeenCalledTimes(1);
}
}
Arrange
40. class ServeurTest extends PHPUnit_Framework_TestCase {
public function test_transmet_une_commande_pour_le_plat_du_jour_a_la_cuisine()
{
$cuisine = $this->prophesize(Cuisine::class);
$serveur = new Serveur($cuisine->reveal());
$serveur->recoitUneCommandePourUnPlatDuJour();
$cuisine
->ilFautUnPlatDuJour()
->shouldHaveBeenCalledTimes(1);
}
}
Act
41. class ServeurTest extends PHPUnit_Framework_TestCase {
public function test_transmet_une_commande_pour_le_plat_du_jour_a_la_cuisine()
{
$cuisine = $this->prophesize(Cuisine::class);
$serveur = new Serveur($cuisine->reveal());
$serveur->recoitUneCommandePourUnPlatDuJour();
$cuisine
->ilFautUnPlatDuJour()
->shouldHaveBeenCalledTimes(1);
}
}
Assert
42. class ServeurTest extends PHPUnit_Framework_TestCase {
public function test_transmet_une_commande_pour_le_plat_du_jour_a_la_cuisine()
{
$cuisine = $this->prophesize(Cuisine::class);
$serveur = new Serveur($cuisine->reveal());
$serveur->recoitUneCommandePourUnPlatDuJour();
$cuisine
->ilFautUnPlatDuJour()
->shouldHaveBeenCalledTimes(1);
}
}
50. class PizzaioloTest extends PHPUnit_Framework_TestCase {
public function test_prepare_une_pizza_margherita_maison()
{
$pizzaiolo = new Pizzaiolo();
$pizza = $pizzaiolo->preparePizzaMargheritaMaison();
$this->assertEquals(
['pate', 'sauce tomate', 'basilic', 'mozzarella'],
$pizza->ingredients()
);
}
}
51. class PizzaSurgelee {
public function __construct($ingredients)
{
$this->ingredients = $ingredients;
}
public function ingredients()
{
return $this->ingredients;
}
}
52. class Pizzaiolo {
public function preparePizzaMargheritaMaison(){
$pizzaSurgelee = $this->acheteUnePizzaMargheritaSurgelee();
return $this->rechauffeLaPizza($pizzaSurgelee);
}
}
56. class Pizzaiolo {
public function preparePizzaMargheritaMaison() {
$pateAPizza = new PateAPizza();
$this->etaleLaPate($pateAPizza);
$this->enduitDeSauceTomate($pateAPizza);
$this->disposeLaMozzarella($pateAPizza);
$this->placeLeBasilic($pateAPizza);
return $this->cuire($pateAPizza);
}
}
58. class PizzaMaison {
public function __construct($ingredients)
{
$this->ingredients = $ingredients;
}
public function ingredients()
{
return $this->ingredients;
}
}
59. class PizzaMaison {
public function __construct($ingredients)
{
$this->ingredients = $ingredients;
}
public function ingredients()
{
return $this->ingredients;
}
}
61. class EndiveTest extends PHPUnit_Framework_TestCase {
public function test_une_endive_de_base_est_crue() {
$endive = new Endive();
$this->assertTrue($endive->crue());
}
public function test_une_endive_de_base_est_bonne() {
$endive = new Endive();
$this->assertTrue($endive->bonne());
}
public function test_une_endive_cuite_nest_pas_crue() {
$endive = new Endive();
$endive->cuire();
$this->assertFalse($endive->crue());
}
public function test_une_endive_cuite_nest_pas_bonne() {
$endive = new Endive();
$endive->cuire();
$this->assertFalse($endive->bonne());
}
}
62. public function test_une_endive_de_base_est_crue() {
$endive = new Endive();
$this->assertTrue($endive->crue());
}
public function test_une_endive_de_base_est_bonne() {
$endive = new Endive();
$this->assertTrue($endive->bonne());
}
63. public function test_une_endive_cuite_nest_pas_crue(){
$endive = new Endive();
$endive->cuire();
$this->assertFalse($endive->crue());
}
public function test_une_endive_cuite_nest_pas_bonne() {
$endive = new Endive();
$endive->cuire();
$this->assertFalse($endive->bonne());
}
64. class UneEndiveDeBaseTest extends PHPUnit_Framework_TestCase {
public function setUp()
{
$this->endive = new Endive();
}
public function test_est_crue()
{
$this->assertTrue($this->endive->crue());
}
public function test_est_bonne()
{
$this->assertTrue($this->endive->bonne());
}
}
65. class UneEndiveCuiteTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->endive = new Endive();
$this->endive->cuire();
}
public function test_nest_pas_crue()
{
$this->assertFalse($this->endive->crue());
}
public function test_nest_pas_bonne()
{
$this->assertFalse($this->endive->bonne());
}
}
66. class UneEndiveDeBaseTest extends PHPUnit_Framework_TestCase {
public function setUp()
{
$this->endive = new Endive();
}
public function test_est_crue()
{
$this->assertTrue($this->endive->crue());
}
public function test_est_bonne()
{
$this->assertTrue($this->endive->bonne());
}
}
67. class UneEndiveCuiteTest extends PHPUnit_Framework_TestCase {
public function setUp()
{
$this->endive = new Endive();
$this->endive->cuire();
}
public function test_nest_pas_crue()
{
$this->assertFalse($this->endive->crue());
}
public function test_nest_pas_bonne()
{
$this->assertFalse($this->endive->bonne());
}
}
68. class UneEndiveDeBaseTest extends PHPUnit_Framework_TestCase {
public function setUp()
{
$this->endive = new Endive();
}
public function test_est_crue()
{
$this->assertTrue($this->endive->crue());
}
public function test_est_bonne()
{
$this->assertTrue($this->endive->bonne());
}
}
69. // UneEndiveDeBaseTest.php
public function setUp()
{
$this->endive = new Endive();
}
// UneEndiveCuiteTest.php
public function setUp()
{
$this->endive = new Endive();
$this->endive->cuire();
}
79. class Realistisk {
public function laga($tallrik, $varaktighet) {
sleep($duree);
return $this->fårEnKallTallrik(get_class($tallrik), $varaktighet);
}
}
85. public function test_cuit_au_four_donne_un_gratin_croustillant()
{
$gratin = new Gratin();
$four = $this->prophesize(Four::class);
$four->cuire($gratin, self::50_MINUTES)
->willReturn(new GratinCroustillant());
$plat = $gratin->cuireAvec($four->reveal());
$this->assertEquals(new GratinCroustillant(), $plat);
}
86. public function test_cuit_au_four_donne_un_gratin_croustillant()
{
$gratin = new Gratin();
$four = $this->prophesize(Four::class);
$four->cuire($gratin, self::50_MINUTES)
->willReturn(new GratinCroustillant());
$plat = $gratin->cuireAvec($four->reveal());
$this->assertEquals(new GratinCroustillant(), $plat);
}
87. class LeFourDeLaCuisine implements Four {
public function __construct(Realistisk $realistisk)
{
$this->realistisk = $realistisk;
}
public function cuire($plat, $duree)
{
$tallrik = $this->realistisk->laga($plat, $duree);
return $tallrik->fåTallrik();
}
}
88. class Gratin {
public function cuireAvec(Realistisk $realistisk, $duree) {
$tallrik = $realistisk->laga($this, $duree);
return $tallrik->fåTallrik();
}
}
89. class Gratin {
public function cuireAvec(Four $four, $duree) {
return $four->cuire($this, $duree);
}
}
90. class LeFourDeLaCuisineTest extends PHPUnit_Framework_TestCase {
public function test_cuit_un_fromage_de_chevre_en_chevre_chaud() {
$four = new FourDeLaCuisine(new Realistisk());
$plat = $four->cuire(new FromageDeChevre(), self::10_MINUTES);
$this->assertEquals(new ChevreChaud(), $plat);
}
}
91. class LeFourDeLaCuisineTest extends PHPUnit_Framework_TestCase {
public function test_cuit_un_fromage_de_chevre_en_chevre_chaud() {
$four = new FourDeLaCuisine(new Realistisk());
$plat = $four->cuire(new FromageDeChevre(), self::10_MINUTES);
$this->assertEquals(new ChevreChaud(), $plat);
}
}
94. class Quiche {
public function __construct(Datetime $dateCuisson) {
$this->dateCuisson = $dateCuisson;
}
public function peutEtreConsommee()
{
return $this->dateCuisson->modify('+2 day') < new Datetime();
}
}
98. class Quiche {
public function __construct(Datetime $cuisineeLe) {
$this->cuisineeLe = $cuisineeLe;
}
public function peutEtreConsommee(Horloge $horloge)
{
return $this->cuisineeLe->modify('+2 day') < $horloge->maintenant();
}
}
105. class PlatDePatesTest extends PHPUnit_Framework_TestCase {
public function test_est_bon_sil_contient_de_la_viande_du_fromage_et_de_la_sauce()
{
$platDePates = new PlatDePates([
new Ingredient('fromage', 'parmesan'),
new Ingredient('viande', 'lardons'),
new Ingredient('sauce', 'creme fraiche'),
new Ingredient('legume', 'oignon'),
]);
$this->assertTrue($platDePates->estBon());
}
}
106. class Ingredient {
public function __construct($type, $nom)
{
$this->type = $type;
$this->nom = $nom;
}
}
107. class Ingredient {
public function __construct($type, $nom, $DLC)
{
$this->type = $type;
$this->nom = $nom;
$this->DLC = $DLC;
}
}
109. class IngredientMother {
public static function viande()
{
return new Ingredient('viande', 'boeuf hache', new Datetime());
}
public static function legume()
{
return new Ingredient('legume', 'salsifi', new Datetime());
}
public static function fromage()
{
return new Ingredient('fromage', 'coulommier', new Datetime());
}
public static function sauce()
{
return new Ingredient('sauce', 'soja', new Datetime());
}
}
115. class PlatDePatesTest extends PHPUnit_Framework_TestCase {
public function test_nest_pas_consommable_sil_contient_un_ingredient_avec_une_DLC_depassee()
{
$platDePates = new PlatDePates([
new Ingredient('parmesan', new DateTime('2017-10-30')),
new Ingredient('lardons', new DateTime('2017-10-15')),
]);
$this->assertFalse(
$platDePates->estConsommableLe(new DateTime('2017-10-20'))
);
}
}
116. class PlatDePatesTest extends PHPUnit_Framework_TestCase {
public function test_nest_pas_consommable_sil_contient_un_ingredient_avec_une_DLC_depassee()
{
$platDePates = new PlatDePates([
new Ingredient('parmesan', new DateTime('2017-10-30')),
new Ingredient('lardons', new DateTime('2017-10-15')),
]);
$this->assertFalse(
$platDePates->estConsommableLe(new DateTime('2017-10-20'))
);
}
}
117. class IngredientBuilder {
private $nom;
private $dlc;
public function __construct() {
$this->nom = "pomme de terre";
$this->dlc = new Datetime();
}
public function nomme($nom)
{
$this->nom = $nom;
return $this;
}
public function avecUneDLCLe($dlc)
{
$this->dlc = $dlc;
return $this;
}
public function build()
{
return new Ingredient($this->nom, $this->dlc);
}
}
119. class IngredientBuilder {
public function nomme($nom)
{
$this->nom = $nom;
return $this;
}
public function avecUneDLCLe($dlc)
{
$this->dlc = $dlc;
return $this;
}
}
120. class IngredientBuilder {
public function nomme($nom)
{
$this->nom = $nom;
return $this;
}
public function avecUneDLCLe($dlc)
{
$this->dlc = $dlc;
return $this;
}
}
126. class PlatTest extends PHPUnit_Framework_TestCase {
public function test_est_vegetarien_sil_ne_contient_que_de_la_salade(){
$plat = new Plat(['salade']);
$this->assertTrue($plat->estVegetarien());
}
public function test_est_vegetarien_sil_ne_contient_que_du_fromage()
{
$plat = new Plat(['fromage']);
$this->assertTrue($plat->estVegetarien());
}
public function test_nest_pas_vegetarien_sil_contient_de_la_viande()
{
$plat = new Plat(['salade', 'viande']);
$this->assertFalse($plat->estVegetarien());
}
}
127. class PlatTest extends PHPUnit_Framework_TestCase {
public function test_est_vegetarien_sil_ne_contient_que_de_la_salade(){
$plat = new Plat(['salade']);
$this->assertTrue($plat->estVegetarien());
}
public function test_est_vegetarien_sil_ne_contient_que_du_fromage()
{
$plat = new Plat(['fromage']);
$this->assertTrue($plat->estVegetarien());
}
public function test_nest_pas_vegetarien_sil_contient_de_la_viande()
{
$plat = new Plat(['salade', 'viande']);
$this->assertFalse($plat->estVegetarien());
}
}
128. class PlatTest extends PHPUnit_Framework_TestCase {
public function test_est_vegetarien_sil_ne_contient_que_de_la_salade(){
$plat = new Plat(['salade']);
$this->assertTrue($plat->estVegetarien());
}
public function test_est_vegetarien_sil_ne_contient_que_du_fromage()
{
$plat = new Plat(['fromage']);
$this->assertTrue($plat->estVegetarien());
}
public function test_nest_pas_vegetarien_sil_contient_de_la_viande()
{
$plat = new Plat(['salade', 'viande']);
$this->assertFalse($plat->estVegetarien());
}
}
129. class PlatTest extends PHPUnit_Framework_TestCase {
public function test_est_vegetarien_sil_ne_contient_que_de_la_salade(){
$plat = new Plat(['salade']);
$this->assertTrue($plat->estVegetarien());
}
public function test_est_vegetarien_sil_ne_contient_que_du_fromage()
{
$plat = new Plat(['fromage']);
$this->assertTrue($plat->estVegetarien());
}
public function test_nest_pas_vegetarien_sil_contient_de_la_viande()
{
$plat = new Plat(['salade', 'viande']);
$this->assertFalse($plat->estVegetarien());
}
}
131. public function plats()
{
return [
'Un plat qui ne contient que la salade est vegetarien' => [
new Plat(['salade']), self::EST_VEGETARIEN
],
'Un plat avec du fromage est vegetarien' => [
new Plat(['fromage']), self::EST_VEGETARIEN
],
'Un plat avec de la viande n'est pas vegetarien' => [
new Plat(['viande']), self::NEST_PAS_VEGETARIEN
],
];
}
132. public function plats()
{
return [
'Un plat qui ne contient que la salade est vegetarien' => [
new Plat(['salade']), self::EST_VEGETARIEN
],
'Un plat avec du fromage est vegetarien' => [
new Plat(['fromage']), self::EST_VEGETARIEN
],
'Un plat avec de la viande n'est pas vegetarien' => [
new Plat(['viande']), self::NEST_PAS_VEGETARIEN
],
];
}
133. public function plats()
{
return [
'Un plat qui ne contient que la salade est vegetarien' => [
new Plat(['salade']), self::EST_VEGETARIEN
],
'Un plat avec du fromage est vegetarien' => [
new Plat(['fromage']), self::EST_VEGETARIEN
],
'Un plat avec de la viande n'est pas vegetarien' => [
new Plat(['viande']), self::NEST_PAS_VEGETARIEN
],
];
}
134. public function plats()
{
return [
'Un plat qui ne contient que la salade est vegetarien' => [
new Plat(['salade']), self::EST_VEGETARIEN
],
'Un plat avec du fromage est vegetarien' => [
new Plat(['fromage']), self::EST_VEGETARIEN
],
'Un plat avec de la viande n'est pas vegetarien' => [
new Plat(['viande']), self::NEST_PAS_VEGETARIEN
],
];
}
135. /**
* @dataProvider plats
*/
public function test_est_vegetarien_sil_ne_contient_que_des_ingredients_vegetariens
($plat, $estVegetarien)
{
$this->assertEquals($estVegetarien, $plat->estVegetarien());
}
136. class PlatTest extends PHPUnit_Framework_TestCase {
public function test_est_vegetarien_sil_ne_contient_que_de_la_salade(){
$plat = new Plat(['salade']);
$this->assertTrue($plat->estVegetarien());
}
public function test_est_vegetarien_sil_ne_contient_que_du_fromage()
{
$plat = new Plat(['fromage']);
$this->assertTrue($plat->estVegetarien());
}
public function test_nest_pas_vegetarien_sil_contient_de_la_viande()
{
$plat = new Plat(['salade', 'viande']);
$this->assertFalse($plat->estVegetarien());
}
}
137. class PlatTest extends PHPUnit_Framework_TestCase {
const EST_VEGETARIEN = true;
const NEST_PAS_VEGETARIEN = false;
/**
* @dataProvider plats
*/
public function test_est_vegetarien_sil_ne_contient_que_des_ingredients_vegetariens
($plat, $estVegetarien)
{
$this->assertEquals($estVegetarien, $plat->estVegetarien());
}
public function plats()
{
return [
'Un plat qui ne contient que la salade est vegetarien' => [
new Plat(['salade']), self::EST_VEGETARIEN
],
'Un plat avec du fromage est vegetarien' => [
new Plat(['fromage']), self::EST_VEGETARIEN
],
'Un plat avec de la viande n'est pas vegetarien' => [
new Plat(['viande']), self::NEST_PAS_VEGETARIEN
],
];
}
}
138. Assurez vous que vous
testez ce que vous
voulez tester.
Photo by rawpixel.com on Unsplash