concurrent test frameworks
TRANSCRIPT
![Page 1: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/1.jpg)
CONCURRENT TEST FRAMEWORKSAndrea Giuliano@bit_shark
![Page 2: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/2.jpg)
Andrea Giuliano@bit_sharkandreagiuliano.it
$WHOAMI
![Page 3: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/3.jpg)
PHP TEST FRAMEWORKS
![Page 4: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/4.jpg)
WHICH ONE SHOULD I USE?
CONCENTRATE AND ASK AGAIN
![Page 5: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/5.jpg)
WHO SAID “ONE”?
![Page 6: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/6.jpg)
IS THE TOOL THE PROBLEM?
![Page 7: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/7.jpg)
LET’S START FROM THE BEGINNING
![Page 8: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/8.jpg)
TEST DRIVEN DEVELOPMENT
Red
GreenRefactor
![Page 9: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/9.jpg)
EMERGENT DESIGN
![Page 10: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/10.jpg)
TDD AS A PROBLEM
![Page 11: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/11.jpg)
TDD AS A PROBLEM
class VideoGalleryTest extends \PHPUnit_Framework_TestCase { public function testUploadVideo() { $videoGallery = new VideoGallery(); $videoGallery->upload('path/on/my/awesome/file.mp4');
$this->assertTrue(is_array($videoGallery->getVideos())); $this->assertCount(1, $videoGallery->getVideos()); $this->assertInstanceOf( Video::class, $videoGallery->getFirstVideo()); } }
![Page 12: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/12.jpg)
TDD AS A PROBLEM
class VideoGalleryTest extends \PHPUnit_Framework_TestCase { public function testUploadVideo() { $videoGallery = new VideoGallery(); $videoGallery->upload('path/on/my/awesome/file.mp4');
$this->assertTrue(is_array($videoGallery->getVideos())); $this->assertCount(1, $videoGallery->getVideos()); $this->assertInstanceOf( Video::class, $videoGallery->getFirstVideo()); } }
testing internals
![Page 13: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/13.jpg)
IS VERSUS DOES
![Page 14: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/14.jpg)
IT’S ALL ABOUT BEHAVIOUR
![Page 15: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/15.jpg)
DESCRIBING A STORY
Feature: As a [role] I want [feature] So that [benefit]
Scenario: scenario description Given [context] When [event] Then [outcome]
![Page 16: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/16.jpg)
A DIFFERENT CYCLE
Write an acceptance test (Given/When/Then)
Discover ‘verbs’, ‘nouns’ and write a failing step
definition
![Page 17: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/17.jpg)
A DIFFERENT CYCLE
Describe the behaviours for ‘verbs’ and ‘nouns’
Write an acceptance test (Given/When/Then)
Discover ‘verbs’, ‘nouns’ and write a failing step
definition
![Page 18: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/18.jpg)
A DIFFERENT CYCLE
Describe the behaviours for ‘verbs’ and ‘nouns’
Write an acceptance test (Given/When/Then)
Discover ‘verbs’, ‘nouns’ and write a failing step
definition
Create object and the behavioural methods
![Page 19: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/19.jpg)
A DIFFERENT CYCLE
Describe the behaviours for ‘verbs’ and ‘nouns’
Write an acceptance test (Given/When/Then)
Discover ‘verbs’, ‘nouns’ and write a failing step
definition
Create object and the behavioural methods
![Page 20: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/20.jpg)
THE TOOL
composer require behat/behat --dev
![Page 21: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/21.jpg)
DESCRIBING A STORY
Scenario: Getting the total amount for a conference ticket Given a ticket for the "PHP Day" conference priced EUR100 was added to the marketplace When a user adds the "PHP Day" ticket from the marketplace to the user's shopping cart Then the overall cart price should be EUR122
![Page 22: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/22.jpg)
RUN THE STORY
$ bin/behat --append-snippets
![Page 23: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/23.jpg)
VERBS, NOUNS, BEHAVIOUR DISCOVERING
/** * @Given a ticket for the :conference conference priced EUR:price * was added to the marketplace */ public function aTicketForTheConferencePriced($conference, $price) { $money = Money::EUR((int) $price); $ticket = Ticket::forConferencePriced($conference, $money); $this->marketPlace->add($ticket); }
![Page 24: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/24.jpg)
/** * @When a user adds the ":conference" ticket * from the marketplace to the shopping cart */ public function aUserAddTheTicketToTheShoppingCart($conference) { $this->user->addTicketToCart($conference, $this->marketPlace); }
VERBS, NOUNS, BEHAVIOUR DISCOVERING
![Page 25: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/25.jpg)
/** * @Then the overall cart price should be EUR:price */ public function theOverallCartPriceShouldBe($price) { $money = Money::EUR((int) $price); $amount = $this->user->shoppingCart()->total();
if (!$amount->equals($money)) { throw new \Exception("Cart amount is not " . $price); } }
VERBS, NOUNS, BEHAVIOUR DISCOVERING
![Page 26: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/26.jpg)
DESCRIBE THE BEHAVIOUR
Describe the behaviours for ‘verbs’ and ‘nouns’
Write an acceptance test (Given/When/Then)
Discover ‘verbs’, ‘nouns’ and write a failing step
definition
Create object and the behavioural methods
![Page 27: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/27.jpg)
THE TOOLS
![Page 28: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/28.jpg)
DESCRIBING TICKET CREATION
class TicketTest extends \PHPUnit_Framework_TestCase { /** * @test */ function should_create_a_ticket_for_conference_priced() { $price = Money::EUR(1000); $ticket = Ticket::forConferencePriced( 'An awesome conference', $price );
$this->assertInstanceOf(Ticket::class, $ticket); } }
![Page 29: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/29.jpg)
OBJECT CREATION
Describe the behaviours for ‘verbs’ and ‘nouns’
Write an acceptance test (Given/When/Then)
Discover ‘verbs’, ‘nouns’ and write a failing step
definition
Create object and the behavioural methods
![Page 30: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/30.jpg)
THE TICKET OBJECT
class Ticket implements TicketInterface { private $event; private $price;
private function __construct($event, Money $price) { $this->event = $event; $this->price = $price; }
public static function forConferencePriced($conference, Money $price) { return new Ticket($conference, $price); } }
![Page 31: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/31.jpg)
GOING UP
Describe the behaviours for ‘verbs’ and ‘nouns’
Write an acceptance test (Given/When/Then)
Discover ‘verbs’, ‘nouns’ and write a failing step
definition
Create object and the behavioural methods
![Page 32: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/32.jpg)
SHOPPING CART SPECIFICATION
class ShoppingCartSpec extends ObjectBehavior { function it_should_return_the_amount_with_vat(TicketInterface $ticket) { $ticket->price()->willReturn(Money::EUR(100.00)); $this->addTicket($ticket);
$expectedMoney = Money::EUR(122.00);
$this->total()->shouldBeLike($expectedMoney); } }
![Page 33: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/33.jpg)
THE SHOPPING CART OBJECTclass ShoppingCart { public function total() { $total = Money::EUR(0); foreach ($this->tickets as $ticket) {
$ticketPriceWithVat = Money::multiply( $ticket->price(), self::VAT );
$total = Money::add($total, $ticketPriceWithVat->amount()); }
return $total; } }
![Page 34: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/34.jpg)
GOING UP
Describe the behaviours for ‘verbs’ and ‘nouns’
Write an acceptance test (Given/When/Then)
Discover ‘verbs’, ‘nouns’ and write a failing step
definition
Create object and the behavioural methods
![Page 35: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/35.jpg)
THE GREEN SATISFACTION
![Page 36: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/36.jpg)
MOVING OUTWARDLY
Domain
Application
Presentation
![Page 37: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/37.jpg)
THE FORTRESS
![Page 38: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/38.jpg)
joind.in/14553Please rate the talk
![Page 39: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/39.jpg)
joind.in/14553Please rate the talk
![Page 40: Concurrent test frameworks](https://reader030.vdocument.in/reader030/viewer/2022032619/55c40198bb61eb6b078b45b1/html5/thumbnails/40.jpg)
REFERENCES
Assets:https://www.flickr.com/photos/levork/4966756896https://www.flickr.com/photos/jenny-pics/7960912752https://www.flickr.com/photos/joel_baker/12484614505https://www.flickr.com/photos/mike-f/8628898387https://www.flickr.com/photos/mike-f/8628898387https://www.flickr.com/photos/michaeljzealot/6485009571
The RSpec book, Behaviour Driven Development with RSpec, Cucumber, and Friends - D. ChelimskyKonstantin Kudryashov aka Everzet - Introducing modeling by example everzet.com/post/99045129766/introducing-modelling-by-examplea special thanks to Giulio De Donato aka liuggio