PHP Meetup
Михайло Бондарчук
— Автор популярного фреймворку для PHP тестування - Codeception
— Веб-розробник PHP/Ruby/JS
— Спікер PHPKonf Стамбул (2015), RSConf Мінськ (2016), J&Beyond Барселони (2016), Голландська PHP Конференція 2016
Презентація про:
— реалізация плюмбусів на PHP
— як писати додатки в складній доменній області
— що таке BDD та як він пов'язаний із тестуванням
39. FEATURE FILE
Feature: Plumbus
In order to get a plumbus
As a plumbus factory manager
I need to create it via web interfce
Написано в языке Gherkin ↑
40. Scenario: Make Plumbus
Given first they take the dinglebop
And they smooth it out with a bunch of schleem
And the schleem is then repurposed for later batches
Then they take the dinglebop
And they push it through the grumbo where the fleeb is rubbed
against it
Given It is important that the fleeb is rubbed
because the fleeb has all of the fleeb juice
41.
42. Then a schlami shows up
And he rubs it
And spits on it
Then they cut the fleeb
Given there are several hizzards in the way
Then the blamfs rub against the chumbles
And the ploobis and grumbo are shaved away
Then that leaves you with a regular old plumbus
45. ВОПРОСЫ
сколько нужно дингельбопа?
откуда его взять?
сколько нужно шлима?
что делать, если шлим закончился?
что происходит, если флиб не разрублен?
что делать, если шлами заболел?
ЗАЧЕМ НУЖЕН ПЛЮМБУС???
46. СЦЕНАРИЙ
Scenario: make plumbus
Given we have a shalmi
And "30" pounds of dinglebop
And "2" pounds of shleem
...
When we smooth out dinglebop with a schleem
And we push it through the grumbo
And shlamy rubs and spits on it
...
Then we have regular old plumbus
53. /**
* @Given we have a shalmi
*/
public function haveShlami()
{
$this->shlami = new Shlami;
}
/**
* @When shlamy rubs and spits on it
*/
public function shlamyActions()
{
$this->shlami->spitOnDingleBop($this->product);
$this->shlami->rubDingleBop($this->product);
}
54. BDD И ТЕСТИРОВАНИЕ
Позволяет делать значимые тесты
Вся команда знает что делает тест
Заказчик видит текущую работоспособность
системы
56. ПЛОХО
Scenario: go through the service to button "Купить"
Given open mysite.com
When press button with text "Вход в кабинет"
And type to input with name "userName" and text "vasya"
And type to input with name "password" and text "1111"
And press element with value "Войти
57. BDD - ALL IN ONE
спецификация
разработка
тестирование
58. ИСТОРИЯ BDD
тесты привязываем к спецификации
названия тестов описывают поведение
str_replace('test', 'should', $testName);
Introducing BDD
61. МЫ АВТОМАТИЗИРУЕМ БИЗНЕС
Нам надо разобраться в предметной области
Точная реализация доменной модели
Важно, чтобы баги системы не ломали сам
бизнес
Риски: мы работаем с материальными вещами
Воспроизведение типичных бизнес-сценариев
62. МЫ СОЗДАЕМ БИЗНЕС
Предметная область изучается по ходу развития
Баги системы напрямую ломают бизнес
Риски: мы работаем с виртуальными вещами
Сценарии определяются возможностями системы
63. ЦЕНА ВНЕДРЕНИЯ
Запись всех спецификаций формальным языком
Разработка примеров работы системы
Участие заказчика в разработке системы
Автоматизация примеров (тестирование)
76. Feature: content
In order to manage content article in the web
As an owner
I need to create modify trash publish and Unpublish content article
Background:
When I Login into Joomla administrator with username "admin" and
And I see the administrator dashboard
Scenario: Create an Article
Given There is a add content link
When I create new content with field title as "Article One" and c
And I save an article
Then I should see the article "Article One" is created
Больше сценариев >
77. /**
* @When I Login into Joomla administrator with username :arg1 and pa
*/
public function loginIntoJoomlaAdministrator($username, $password)
{
$I = $this;
$I->amOnPage(ControlPanelPage::$url);
$I->fillField(LoginPage::$usernameField, $username);
$I->fillField(LoginPage::$passwordField, $password);
$I->click(LoginPage::$loginButton);
}
/**
* @Then I should see the administrator dashboard
* @When I see the administrator dashboard
*/
public function iShouldSeeTheAdministratorDashboard()
{
$I = $this;
$I->adminPage->waitForPageTitle(ControlPanelPage::$pageTitle);
$I->see(ControlPanelPage::$pageTitle, AdminPage::$pageTitle);
}
/**
* @Given There is a add content link
*/
public function thereIsAAddContentLink()
{
$I = $this;
$I->amOnPage(ArticleManagerPage::$url);
80. Feature: Adding a simple product to the cart
In order to select products for purchase
As a Visitor
I want to be able to add simple products to cart
Scenario: Adding a simple product to the cart
Given the store has a product "T-shirt banana" priced at "$12
When I add this product to the cart
Then I should be on my cart summary page
And I should be notified that the product has been successful
And there should be one item in my cart
And this item should have name "T-shirt banana"
пример взят из Sylius
82. ТИПЫ ТЕСТОВ
Functional - без UI, но с фреймворком
Unit - компоненты системы
Acceptance - UI + WebServer
ln -s $PWD/features ⇒ tests/functional
ln -s $PWD/features ⇒ tests/unit
ln -s $PWD/features ⇒ tests/acceptance
83. ТЕСТ != FEATURE
Не все тесты - часть спецификации
Баги не являются спецификацией
Описание всех возможных сценариев в Gherkin
добавляет информационный шум
84. FEATURES ∈ TESTS
Feature описывают предполагаемые сценарии
Regression test описывает проблемные сценарии
Regression test @depends on Feature