/** * Constructor * * @param string $interfaceName * @param MethodDataProviderFactory $methodDataProviderFactory * @param Reader $reader */ public function __construct($interfaceName, MethodDataProviderFactory $methodDataProviderFactory, Reader $reader) { Tebru\assertThat(interface_exists($interfaceName), '"%s" is not a valid interface', $interfaceName); $this->reflectionClass = new ReflectionClass($interfaceName); $this->methodDataProviderFactory = $methodDataProviderFactory; $this->reader = $reader; }
public function build() { Tebru\assertNotNull($this->getAmount(), 'Amount must not be null'); Tebru\assertThat(null !== $this->getSource() || null !== $this->getCustomerId(), 'Source or Customer must not be null'); if (null === $this->getCurrency()) { $this->setCurrency('usd'); } $charge = new Charge(); $charge->setAmount($this->getAmount()); $charge->setCurrency($this->getCurrency()); $charge->setCustomerId($this->getCustomerId()); $charge->setDescription($this->getDescription()); $charge->setMetadata($this->getMetadata()); $charge->setStatementDescriptor($this->getStatementDescriptor()); $charge->setReceiptEmail($this->getReceiptEmail()); $charge->setDestination($this->getDestination()); $charge->setApplicationFee($this->getApplicationFee()); $charge->setShipping($this->getShipping()); $chargeRequest = new ChargeRequest(); $chargeRequest->setCapture($this->isCapture()); $source = $this->getSource(); if (is_string($source)) { $chargeRequest->setSourceId($source); } elseif ($source instanceof Card) { $chargeRequest->setCardSource($source); } elseif (null === $source) { } else { throw new LogicException('Source must be a string or Card object'); } $charge->setRequest($chargeRequest); return $charge; }
/** * Constructor * * @param array $params * @throws LogicException if path is not set */ public function __construct(array $params) { Tebru\assertThat(isset($params['value']), 'Request method "%s" must have path', get_class($this)); $path = $params['value']; // check if url contains {} $matchesFound = preg_match_all('/{(.+?)}/', $path, $pathMatches); if ($matchesFound) { foreach ($pathMatches[0] as $key => $match) { $paramName = $pathMatches[1][$key]; $this->parameters[] = $paramName; // replace {variable} with $variable in path for each match found $path = str_replace($pathMatches[0][$key], '$' . $paramName, $path); } } // if url has query parameters, remove them $queryString = strstr($path, '?'); if (false !== $queryString) { // remove ? and everything after $path = substr($path, 0, -strlen($queryString)); // set $queryString to everything after the ? $queryString = substr($queryString, 1); // convert string to array and set to $stringAsArray parse_str($queryString, $stringAsArray); if (null !== $stringAsArray) { $this->queries = $stringAsArray; } } $this->path = $path; }
/** * Constructor * * @param array $params * @throws Exception */ public function __construct(array $params) { Tebru\assertThat(isset($params['value']), 'An argument was not passed to a "%s" annotation.', get_class($this)); $this->value = $params['value']; if (isset($params['var'])) { $this->var = $params['var']; } }
/** * Constructor * * @param array $params * @throws OutOfRangeException */ public function __construct(array $params) { Tebru\assertArrayKeyExists('value', $params, 'An argument was not passed to a "%s" annotation.', get_class($this)); // convert to array $params['value'] = (array) $params['value']; // loop through each string and break on ':' foreach ($params['value'] as $header) { $pos = strpos($header, ':'); Tebru\assertThat(false !== $pos, 'Header in an incorrect format. Expected "Name: value"'); $name = trim(substr($header, 0, $pos)); $value = trim(substr($header, $pos + 1)); $this->headers[$name] = $value; } }
public function build() { if (!$this->isManaged()) { Tebru\assertThat(null !== $this->getEmail(), 'If managed is false, email must be set'); } if (null === $this->getCountry()) { $this->setCountry('US'); } $account = new Account(); $account->setManaged($this->isManaged()); $account->setCountry($this->getCountry()); $account->setEmail($this->getEmail()); return $account; }
/** * Build the request body * * @param array $body * @return array */ private function createBody(array $body) { if (null === $this->body && empty($this->bodyParts)) { $body[] = '$body = null;'; return $body; } Tebru\assertThat(null === $this->body || empty($this->bodyParts), 'Cannot have both @Body and @Part annotations'); if ($this->bodyIsObject) { $body[] = sprintf('$context = \\JMS\\Serializer\\SerializationContext::create();'); $body = $this->createContext($body, $this->serializationContext); $body[] = sprintf('$body = $this->serializer->serialize(%s, "json", $context);', $this->body); if (false === $this->jsonEncode) { $body[] = sprintf('$body = json_decode($body, true);'); $body[] = sprintf('$body = http_build_query($body);'); } } elseif ($this->bodyIsArray) { $body[] = true === $this->jsonEncode ? sprintf('$body = json_encode(%s);', $this->body) : sprintf('$body = http_build_query(%s);', $this->body); } elseif (null !== $this->body) { $body[] = sprintf('$body = %s;', $this->body); } else { $body[] = true === $this->jsonEncode ? sprintf('$body = json_encode(%s);', $this->arrayToString($this->bodyParts)) : sprintf('$body = http_build_query(%s);', $this->arrayToString($this->bodyParts)); } return $body; }
/** * @expectedException \LogicException * @expectedExceptionMessage My test message */ public function testAssertThatConditionMessage() { Tebru\assertThat(false, 'My %s message', 'test'); }