Last active
December 13, 2019 15:50
-
-
Save torreytsui/0b9831f5dfab22782711d061f38bd78c to your computer and use it in GitHub Desktop.
Alternative to MFTF Merging and beyond
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Below requirements summaries what needed to offer the same / better levels of customisation of "MFTF Merging" | |
* | |
* Requirements | |
* | |
* 1. Able to accept random arguments (offering extensible test case inputs) | |
* 2. Able to insert step in between two steps (offering module decoupling) | |
* 3. Able to communicate between steps | |
* 4. Able to overwrite / update / remove existing steps | |
* | |
* (optional) | |
* 5. Able to generate all boilerpate codes (if any) (offering better developer experience) | |
*/ | |
/** | |
* Approach A | |
* | |
* Passed: 1 | |
* Failed: 2, 3, 4 | |
*/ | |
class LoginFacade { | |
public function login($username, $password, ...$args) { | |
$this->pageObject->fill('username', $username); | |
$this->pageObject->fill('password', $password); | |
$this->pageObject->click('login'); | |
} | |
} | |
/** | |
* Approach B | |
* | |
* Passed: 1, 2, 4 (with decorator) | |
* Failed: 3 | |
*/ | |
class LoginComposite extends LoginFacade | |
{ | |
public function __construct($components = [new LoginFacadeFillingForm(), new LoginFacadeSubmittingForm()]) | |
{ | |
$this->components = $components; | |
} | |
public function login($username, $password, ...$args) { | |
foreach ($this->components as $component) { | |
$component->login($username, $password, ...$args); | |
} | |
} | |
} | |
class LoginFacadeFillingForm extends LoginFacade | |
{ | |
public function login($username, $password, ...$args) { | |
$this->pageObject->fill('username', $username); | |
$this->pageObject->fill('password', $password); | |
} | |
} | |
class LoginFacadeSubmittingForm extends LoginFacade | |
{ | |
public function login($username, $password, ...$args) { | |
$this->pageObject->click('login'); | |
} | |
} | |
/** | |
* Approach C | |
* | |
* Passed: 1, 2, 3, 4 (with decorator) | |
*/ | |
class LoginComposite extends LoginFacade | |
{ | |
public function __construct($subjects = [new LoginFacadeFillingForm(), new LoginFacadeSubmittingForm()]) | |
{ | |
$this->subjects = $subjects; | |
} | |
public function login($username, $password, FacadeContext $context) { | |
foreach ($this->subjects as $subject) { | |
$subject->login($username, $password, $context); | |
} | |
} | |
} | |
class LoginFacadeContext implements FacadeContext{ | |
} | |
interface FacadeContext { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment