本文整理汇总了PHP中Assert\Assertion::same方法的典型用法代码示例。如果您正苦于以下问题:PHP Assertion::same方法的具体用法?PHP Assertion::same怎么用?PHP Assertion::same使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Assert\Assertion
的用法示例。
在下文中一共展示了Assertion::same方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: withTypes
/**
* @param array $types
*
* @throws \InvalidArgumentException
*
* @return static
*/
public function withTypes(array $types)
{
$choices = [PlatformInterface::TYPE_MOBILE, PlatformInterface::TYPE_TV, PlatformInterface::TYPE_WEB];
Assertion::allChoice($types, $choices);
Assertion::same($types, array_unique($types));
$instance = clone $this;
$instance->types = $types;
return $instance;
}
示例2: deserialize
public function deserialize($rawData, $format)
{
Assertion::same('json', $format, 'No other format is supported');
$coupons = json_decode($rawData, true);
$dto = new Coupons();
foreach ($coupons as $couponArray) {
$dto->addCoupon($this->createCouponFromArray($couponArray));
}
return $dto;
}
示例3: deserialize
public function deserialize($rawData, $format)
{
Assertion::same('json', $format, 'No other format is supported');
$purchases = json_decode($rawData, true);
$dto = new IndividualPurchases();
foreach ($purchases as $purchaseArray) {
$dto->addPurchase($this->createPurchaseFromArray($purchaseArray));
}
return $dto;
}
示例4: retrieveExchangeRateFor
/**
* Retrieves exchange rates from http://fixer.io
*
* @param Currency $currency
*/
private function retrieveExchangeRateFor(Currency $currency)
{
$response = $this->client->request('GET', self::EXCHANGE_RATE_API_URL . '/latest', ['query' => ['base' => $this->baseCurrency->getName()]]);
Assert::same($response->getStatusCode(), 200);
$rawExchangeRates = $response->getBody();
$exchangeRates = json_decode($rawExchangeRates, true);
Assert::isArray($exchangeRates);
Assert::keyExists($exchangeRates, 'rates');
Assert::keyExists($exchangeRates['rates'], $currency->getName());
Assert::numeric($exchangeRates['rates'][$currency->getName()]);
$this->exchangeRates[$currency->getName()] = $exchangeRates['rates'][$currency->getName()];
}
示例5: heShouldSeeTheFollowingData
/**
* @Then he should see the following data:
*
* @param TableNode $table
*/
public function heShouldSeeTheFollowingData(TableNode $table)
{
$hash = $table->getHash();
$em = $this->getEntityManager();
Assertion::count($this->response, count($hash));
foreach ($hash as $row) {
$username = $row['username'];
$isOnline = $row['is_online'] === 'true';
$userId = $em->getRepository('Account:User')->findOneBy(['username' => $username])->getId();
Assertion::keyExists($this->response, $userId);
Assertion::same($isOnline, $this->response[$userId]);
}
}
示例6: retrieveExchangeRateFor
/**
* Retrieves exchange rates from http://free.currencyconverterapi.com
*
* @param Currency $currency
*/
private function retrieveExchangeRateFor(Currency $currency)
{
$conversion = sprintf('%s_%s', $currency->getName(), $this->baseCurrency->getName());
$response = $this->client->request('GET', self::EXCHANGE_RATE_API_URL . '/api/v3/convert', ['query' => ['q' => $conversion]]);
Assert::same($response->getStatusCode(), 200);
$rawExchangeRates = $response->getBody();
$exchangeRates = json_decode($rawExchangeRates, true);
Assert::isArray($exchangeRates);
Assert::keyExists($exchangeRates, 'results');
Assert::keyExists($exchangeRates['results'], $conversion);
Assert::keyExists($exchangeRates['results'][$conversion], 'val');
Assert::numeric($exchangeRates['results'][$conversion]['val']);
$this->exchangeRates[$currency->getName()] = (double) $exchangeRates['results'][$conversion]['val'];
}
示例7: __construct
/**
* @param int|null $userId
* @param int $rightId
* @param null|string $forObjectGroup
* @param null|string $withId
*/
public function __construct($userId, $rightId, $forObjectGroup, $withId)
{
Assertion::nullOrInteger($userId);
Assertion::integer($rightId);
Assertion::nullOrString($forObjectGroup);
//If there is no object group, there can not be an id
if ($forObjectGroup === null) {
Assertion::same($withId, null);
} else {
Assertion::nullOrString($withId);
}
$this->userId = $userId;
$this->rightId = $rightId;
$this->forObjectGroup = $forObjectGroup;
$this->withId = $withId;
}
示例8: evaluate
public function evaluate($expected, $message)
{
switch ($this->strategy) {
case 0:
$message = sprintf($message, $this->value, $expected);
Assertion::same($this->value, $expected, $message);
break;
case 1:
$message = sprintf('Expected `%s` to match regex `%s`, but it didn\'t`', $expected, $this->value);
Assertion::regex($expected, $this->value, $message);
break;
case 2:
$message = sprintf($message, $this->value, gettype($expected));
Assertion::same($this->value, gettype($expected), $message);
break;
}
}
示例9: existsUserRight
public function existsUserRight($userId, $rightId, $forObject, $withId)
{
Assertion::nullOrInteger($userId);
Assertion::integer($rightId);
Assertion::nullOrString($forObject);
//If there is no forObject, there can not be an withId
if ($forObject === null) {
Assertion::same($withId, null);
} else {
Assertion::nullOrString($withId);
}
if ($userId !== null && !$this->userService->existsUserById($userId)) {
throw new UserDoesNotExistException();
}
if (!$this->rightService->existsRightById($rightId)) {
throw new RightNotFoundException();
}
return $this->getORMUserRight($userId, $rightId, $forObject, $withId) !== null;
}
示例10: theCommandHasFinishedSuccessfully
/**
* @Then /^the command has finished successfully$/
*/
public function theCommandHasFinishedSuccessfully()
{
Assertion::same($this->tester->getStatusCode(), 0);
}
示例11: getValue
/**
* @return mixed
*/
public function getValue()
{
Assertion::same(null, $this->formErrorSequence, 'Value can only be retrieved when bind result was successful');
return $this->value;
}
示例12: testSame
public function testSame()
{
Assertion::same(1, 1);
Assertion::same("foo", "foo");
Assertion::same($obj = new \stdClass(), $obj);
$this->setExpectedException('Assert\\AssertionFailedException', null, Assertion::INVALID_SAME);
Assertion::same(new \stdClass(), new \stdClass());
}
示例13: theResponseCodeShouldBe
/**
* @Then the response code should be :code
*/
public function theResponseCodeShouldBe($code)
{
$expected = intval($code);
$actual = intval($this->client->getResponse()->getStatusCode());
Assertion::same($expected, $actual);
}
示例14: performRequest
/**
* Performs a request to the symfony application and returns the response.
*
* @param string $method
* @param string $uri
* @param mixed[] $parameters
* @param bool $expectSuccess
* @param string[] $headers
* @param mixed[] $files
* @param int $expectedStatus
* @param bool $toJson
* @param string $apiKey
* @param bool $disableAssertions
*
* @throws \Exception If the json decode did not work
*
* @return string[]
*/
protected function performRequest($method, $uri, array $parameters = [], $expectSuccess = true, array $headers = [], array $files = [], $expectedStatus = 200, $toJson = true, $apiKey = null, $disableAssertions = false)
{
if (null !== $apiKey || null !== AppContext::$apiKey) {
$headers[ApiKeyAuthenticator::API_KEY_HEADER] = $apiKey ?: AppContext::$apiKey;
}
$headers = array_combine(array_map(function ($headerName) {
return sprintf('HTTP_%s', $headerName);
}, array_keys($headers)), array_values($headers));
/** @var \Symfony\Bundle\FrameworkBundle\Client $client */
$client = $this->getContainer()->get('test.client');
$client->enableProfiler();
$client->request($method, $uri, $parameters, $files, $headers);
$response = $client->getResponse();
if (!$disableAssertions) {
$status = $response->getStatusCode();
if ($expectSuccess) {
Assertion::greaterOrEqualThan($status, 200);
Assertion::lessOrEqualThan($status, 399);
} else {
Assertion::greaterOrEqualThan($status, 400);
Assertion::lessOrEqualThan($status, 599);
}
Assertion::same($expectedStatus, $status);
}
$this->recentClient = $client;
if ($toJson) {
$content = $response->getContent();
if (empty($content)) {
$raw = null;
} else {
$raw = json_decode($content, true);
Assertion::same(JSON_ERROR_NONE, json_last_error());
}
return $raw;
}
return $response;
}
示例15: withPriority
/**
* @param float $priority
*
* @throws \InvalidArgumentException
*
* @return static
*/
public function withPriority($priority)
{
Assertion::float($priority);
Assertion::greaterOrEqualThan($priority, UrlInterface::PRIORITY_MIN);
Assertion::lessOrEqualThan($priority, UrlInterface::PRIORITY_MAX);
Assertion::same($priority, round($priority, 1));
$instance = clone $this;
$instance->priority = $priority;
return $instance;
}