same() public static method

Assert that two values are the same (using ===).
public static same ( mixed $value, mixed $value2, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$value2 mixed
$message string | null
$propertyPath string | null
return boolean
Exemplo n.º 1
0
 /**
  * @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;
 }
 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;
 }
 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;
 }
 /**
  * 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()];
 }
 /**
  * @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]);
     }
 }
 /**
  * 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'];
 }
Exemplo n.º 7
0
 /**
  * @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;
 }
Exemplo n.º 8
0
 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;
     }
 }
 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;
 }
Exemplo n.º 10
0
 /**
  * @Then /^the command has finished successfully$/
  */
 public function theCommandHasFinishedSuccessfully()
 {
     Assertion::same($this->tester->getStatusCode(), 0);
 }
Exemplo n.º 11
0
 /**
  * @return mixed
  */
 public function getValue()
 {
     Assertion::same(null, $this->formErrorSequence, 'Value can only be retrieved when bind result was successful');
     return $this->value;
 }
Exemplo n.º 12
0
 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());
 }
Exemplo n.º 13
0
 /**
  * @Then the response code should be :code
  */
 public function theResponseCodeShouldBe($code)
 {
     $expected = intval($code);
     $actual = intval($this->client->getResponse()->getStatusCode());
     Assertion::same($expected, $actual);
 }
Exemplo n.º 14
0
 /**
  * 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;
 }
Exemplo n.º 15
0
 /**
  * @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;
 }
 /**
  * @param CreateCoupon $createCoupon
  * @return string
  */
 public function serialize(DtoInterface $createCoupon, $format)
 {
     Assertion::same($format, 'json');
     Assertion::isInstanceOf($createCoupon, 'Matthias\\LeanpubApi\\Dto\\CreateCoupon');
     return json_encode(array('coupon_code' => $createCoupon->getCouponCode(), 'package_discounts_attributes' => array_map(array($this, 'serializePackageDiscount'), $createCoupon->getPackageDiscounts()), 'start_date' => CouponDate::fromDateTime($createCoupon->getStartDate()), 'end_date' => CouponDate::fromDateTime($createCoupon->getEndDate()), 'max_uses' => $createCoupon->getMaxUses(), 'note' => $createCoupon->getNote(), 'suspended' => $createCoupon->isSuspended()));
 }
Exemplo n.º 17
0
 /**
  * @Then /^I should get a response with "([^"]*)"$/
  */
 public function assertResponseStatus($status)
 {
     $response = $this->getLastResponse();
     $actual = $response->getStatusCode() . ' ' . $response->getReasonPhrase();
     Assertion::same($actual, $status);
 }
Exemplo n.º 18
0
 /**
  * @param string $familyFriendly
  *
  * @throws \InvalidArgumentException
  *
  * @return static
  */
 public function withFamilyFriendly($familyFriendly)
 {
     Assertion::same($familyFriendly, VideoInterface::FAMILY_FRIENDLY_NO);
     $instance = clone $this;
     $instance->familyFriendly = $familyFriendly;
     return $instance;
 }
Exemplo n.º 19
0
 /**
  * @param array $genres
  *
  * @throws \InvalidArgumentException
  *
  * @return static
  */
 public function withGenres(array $genres)
 {
     $choices = [NewsInterface::GENRE_BLOG, NewsInterface::GENRE_OP_ED, NewsInterface::GENRE_OPINION, NewsInterface::GENRE_SATIRE, NewsInterface::GENRE_USER_GENERATED];
     Assertion::allChoice($genres, $choices);
     Assertion::same($genres, array_unique($genres));
     $instance = clone $this;
     $instance->genres = $genres;
     return $instance;
 }