コード例 #1
0
 public function test_create_with_valid_data_must_return_valid_customer_instance()
 {
     $customer = ["name" => "Juan Perez", "category" => "C", "seat" => 8];
     $newCustomer = CustomerFactory::create($customer);
     $this->assertInstanceOf('Tufesa\\Service\\Type\\Customer', $newCustomer);
     $this->assertEquals($customer["name"], $newCustomer->getName());
     $this->assertEquals($customer["category"], $newCustomer->getCategory());
     $this->assertEquals($customer["seat"], $newCustomer->getSeat());
 }
コード例 #2
0
ファイル: Address.php プロジェクト: aiesh/magento2
 /**
  * @return Customer
  */
 protected function _createCustomer()
 {
     return $this->_customerFactory->create();
 }
コード例 #3
0
ファイル: question_2.php プロジェクト: robbyc73/Tabcorp
        $firstChar = substr($id, 0, 1);
        if ($alphanumeric && $length > 0 && $length <= MAX_LENGTH_ID && ($firstChar == 'B' || $firstChar == 'S' || $firstChar == 'G')) {
            switch ($firstChar) {
                case 'B':
                    $cust = new Bronze_Customer($id);
                    break;
                case 'S':
                    $cust = new Silver_Customer($id);
                    break;
                case 'G':
                    $cust = new Gold_Customer($id);
                    break;
            }
        } else {
            throw new \InvalidArgumentException('Incorrect id passed in, please ensure id is 1 to 30 alphanumeric characters in length and starts with either a \'B\' or \'S\' or \'G\'.');
        }
        return $cust;
    }
}
/**
 * Q3 pass in id 
 */
$cust = CustomerFactory::get_instance('S234433');
$cust->deposit(45.3);
echo 'id is ' . $cust->get_id() . ' customer balance is  ' . $cust->get_balance() . '<br>';
/**
 * Q4 generate id 
 */
$cust = CustomerFactory::get_instance('G');
$cust->deposit(45.3);
echo 'id is ' . $cust->get_id() . ' customer balance is  ' . $cust->get_balance();
コード例 #4
0
 * @package SoftwareEngineerTest
 * based on give ID, then use factory method to initiate correct
 */
class CustomerFactory
{
    /**
     * @param $id
     * @return Bronze_Customer|Gold_Customer|Silver_Customer
     * @throws Exception
     */
    public static function get_instance($id)
    {
        $firstIdString = substr($id, 0, 1);
        switch ($firstIdString) {
            case 'B':
                return new Bronze_Customer($id);
                break;
            case 'S':
                return new Silver_Customer($id);
                break;
            case 'G':
                return new Gold_Customer($id);
                break;
            default:
                throw new Exception('InvalidArgument .');
                break;
        }
    }
}
CustomerFactory::get_instance('G123456');