Last active
August 29, 2015 14:02
-
-
Save liuggio/f59b57bceda6fdfb1ac4 to your computer and use it in GitHub Desktop.
draft of factotum
This file contains hidden or 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
Feature: Build | |
In order to build classes | |
As a feature developer | |
I need to have an ability to use the factory traits. | |
Scenario: Build a Class using private methods | |
Given a file named "Customer.php" with: | |
""" | |
<?php | |
class Customer | |
{ | |
private $validator; | |
private $name; | |
private $createdDate; | |
private function __construct($name, \stdClass $validator) { | |
$this->name = $name; | |
$this->validator = $validator; | |
} | |
public function doSomethingWithCustomerData() | |
{ | |
// ... | |
} | |
} | |
""" | |
And a file named "CustomerFactory.php" with: | |
""" | |
<?php | |
use Customer; | |
class CustomerFactory | |
{ | |
use Factotum; | |
public function __construct() | |
{ | |
$this->validator = new \stdClass; | |
} | |
public function register($name) | |
{ | |
$createdDate = new \DateTime(); | |
// .. some domain logic | |
return $this->buildInjectingVariable('\Customer', array($this->validator, $this->dispatcher, $name, $createdDate)); | |
/** or | |
return $this->buildUsingConstructor('\Customer', array($this->validator, $this->dispatcher, $name)); | |
or | |
return $this->buildUsing{PrivateOrPublicFunctionName}('\Customer', array($this->validator, $this->dispatcher, $name, $createdDate)); **/ | |
} | |
} | |
""" | |
When I execute a php snippet like: | |
""" | |
$customerFactory = new CustomerFactory(); | |
$customer = $customerFactory->register($name); | |
var_dump($customer); | |
""" | |
Then the output should be: | |
""" | |
todo: a vardump of customer with name and validator setted. | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment