ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
BEHAT REVOLUTION
OR HOW WE CAME BACK FROM HELL
@mpzalewski
https://github.com/Zales0123
MATEUSZ ZALEWSKI
@mpzalewski
Zales0123
mpzalewski.com.pl
2
3
BDD is a process designed to aid the management and the delivery of software
development projects by improving communication between engineers and
business professionals.
BEHAVIOR DRIVEN
DEVELOPMENT
BDD is a process designed to aid the management and the delivery of software
development projects by improving communication between engineers and
business professionals.
BEHAVIOR DRIVEN
DEVELOPMENT
http://inviqa.com/insights/bdd-guide4
5
Given "PHP T-Shirt" is priced at €100.00
And the store has "VAT" tax rate of 23%
When I add product "PHP T-Shirt" to the cart
Then my cart taxes should be €23.00
6
7
/**
* @Given :product is priced at :price
*/
public function productIsPricedAt(ProductInterface $product, int $price): void
{
$product->setPrice($price);
}
/**
* @Then /^(my cart) taxes should be ("[^"]+")$/
*/
public function myCartTaxesShouldBe(CartInterface $cart, int $money): void
{
Assert::eq($cart->getTaxesTotal(), $money);
}
LESS AMBIGUITY
=
LESS MISUNDERSTANDINGS
8
9
10
BDD revolution - or how we came back from hell
12
13
14
15
16
https://www.theverge.com/2016/5/5/11592622/this-is-?ne-meme-comic
EXTREMIS MALIS
EXTREMA REMEDIA
17
18
19
20
21
GHERKIN STEP
PHP CODE
CONTEXT
22
/**
* @When I choose :countryName
*/
public function iChoose(string $countryName): void
{
$this->createPage->chooseName($countryName);
}
/**
* @When I save my changes
* @When I try to save changes
*/
public function iSaveMyChanges(): void
{
$this->updatePage->saveChanges();
}
/**
* @Then I should not be able to choose :name
*/
public function iShouldNotBeAbleToChoose(string $name): void
{
try {
$this->createPage->chooseName($name);
} catch (ElementNotFoundException $exception) {
return;
}
throw new Exception(sprintf('I should not be able to choose "%s".', $name));
}
23
VALUE
OBJECT
TRANSFORM
ER
24
/**
* @Transform /^coupon "([^"]+)"$/
* @Transform /^"([^"]+)" coupon$/
* @Transform :coupon
*/
public function getCouponByCode(string $couponCode): CouponInterface
{
$coupon = $this->couponRepository->findOneBy(['code' => $couponCode]);
Assert::notNull(
$coupon,
sprintf('Coupon with code "%s" does not exist', $couponCode)
);
return $coupon;
}
25
/**
* @var SharedStorageInterface
*/
private $sharedStorage;
public function __construct(SharedStorageInterface $sharedStorage)
{
$this->sharedStorage = $sharedStorage;
}
/**
* @Transform /^(it|its|theirs|them)$/
*/
public function getLatestResource()
{
return $this->sharedStorage->getLatestResource();
}
/**
* @Transform /^(?:this|that|the) ([^"]+)$/
*/
public function getResource($resource)
{
return $this->sharedStorage->get(StringInflector::nameToCode($resource));
}
26
When I add this product to the cart
When I browse that channel
Then this item should have name "T-shirt banana"
27
PHP CODE
API
PAGE
UI CLI
28
29
class SummaryPage extends SymfonyPage implements SummaryPageInterface
{
public function getRouteName(): string
{
return 'sylius_shop_cart_summary';
}
public function getGrandTotal(): string
{
$totalElement = $this->getElement('grand_total');
return $totalElement->getText();
}
public function removeProduct(string $productName): void
{
$itemElement = $this
->getElement('product_row', ['%name%' => $productName])
;
$itemElement
->find('css', ?button.sylius-cart-remove-button')
->press()
;
}
}
FRIENDS OF BEHAT
30
31
!
BUSINESS VALUE
CODE VALUE
32
Have no fear of perfection - you¡¯ll never reach it.
~ Salvador Dali
33
THANK YOU
@mpzalewskihttps://github.com/Zales0123

More Related Content

BDD revolution - or how we came back from hell

  • 1. BEHAT REVOLUTION OR HOW WE CAME BACK FROM HELL @mpzalewski https://github.com/Zales0123 MATEUSZ ZALEWSKI
  • 3. 3
  • 4. BDD is a process designed to aid the management and the delivery of software development projects by improving communication between engineers and business professionals. BEHAVIOR DRIVEN DEVELOPMENT BDD is a process designed to aid the management and the delivery of software development projects by improving communication between engineers and business professionals. BEHAVIOR DRIVEN DEVELOPMENT http://inviqa.com/insights/bdd-guide4
  • 5. 5
  • 6. Given "PHP T-Shirt" is priced at €100.00 And the store has "VAT" tax rate of 23% When I add product "PHP T-Shirt" to the cart Then my cart taxes should be €23.00 6
  • 7. 7 /** * @Given :product is priced at :price */ public function productIsPricedAt(ProductInterface $product, int $price): void { $product->setPrice($price); } /** * @Then /^(my cart) taxes should be ("[^"]+")$/ */ public function myCartTaxesShouldBe(CartInterface $cart, int $money): void { Assert::eq($cart->getTaxesTotal(), $money); }
  • 9. 9
  • 10. 10
  • 12. 12
  • 13. 13
  • 14. 14
  • 15. 15
  • 18. 18
  • 19. 19
  • 20. 20
  • 21. 21
  • 23. /** * @When I choose :countryName */ public function iChoose(string $countryName): void { $this->createPage->chooseName($countryName); } /** * @When I save my changes * @When I try to save changes */ public function iSaveMyChanges(): void { $this->updatePage->saveChanges(); } /** * @Then I should not be able to choose :name */ public function iShouldNotBeAbleToChoose(string $name): void { try { $this->createPage->chooseName($name); } catch (ElementNotFoundException $exception) { return; } throw new Exception(sprintf('I should not be able to choose "%s".', $name)); } 23
  • 25. /** * @Transform /^coupon "([^"]+)"$/ * @Transform /^"([^"]+)" coupon$/ * @Transform :coupon */ public function getCouponByCode(string $couponCode): CouponInterface { $coupon = $this->couponRepository->findOneBy(['code' => $couponCode]); Assert::notNull( $coupon, sprintf('Coupon with code "%s" does not exist', $couponCode) ); return $coupon; } 25
  • 26. /** * @var SharedStorageInterface */ private $sharedStorage; public function __construct(SharedStorageInterface $sharedStorage) { $this->sharedStorage = $sharedStorage; } /** * @Transform /^(it|its|theirs|them)$/ */ public function getLatestResource() { return $this->sharedStorage->getLatestResource(); } /** * @Transform /^(?:this|that|the) ([^"]+)$/ */ public function getResource($resource) { return $this->sharedStorage->get(StringInflector::nameToCode($resource)); } 26
  • 27. When I add this product to the cart When I browse that channel Then this item should have name "T-shirt banana" 27
  • 29. 29 class SummaryPage extends SymfonyPage implements SummaryPageInterface { public function getRouteName(): string { return 'sylius_shop_cart_summary'; } public function getGrandTotal(): string { $totalElement = $this->getElement('grand_total'); return $totalElement->getText(); } public function removeProduct(string $productName): void { $itemElement = $this ->getElement('product_row', ['%name%' => $productName]) ; $itemElement ->find('css', ?button.sylius-cart-remove-button') ->press() ; } }
  • 31. 31 !
  • 33. Have no fear of perfection - you¡¯ll never reach it. ~ Salvador Dali 33