本文整理汇总了PHP中Webmozart\Assert\Assert类的典型用法代码示例。如果您正苦于以下问题:PHP Assert类的具体用法?PHP Assert怎么用?PHP Assert使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Assert类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* {@inheritdoc}
*/
public static function create($body, TypeResolver $typeResolver = null, DescriptionFactory $descriptionFactory = null, Context $context = null)
{
Assert::stringNotEmpty($body);
Assert::allNotNull([$typeResolver, $descriptionFactory]);
// 1. none or more whitespace
// 2. optionally the keyword "static" followed by whitespace
// 3. optionally a word with underscores followed by whitespace : as
// type for the return value
// 4. then optionally a word with underscores followed by () and
// whitespace : as method name as used by phpDocumentor
// 5. then a word with underscores, followed by ( and any character
// until a ) and whitespace : as method name with signature
// 6. any remaining text : as description
if (!preg_match('/^
# Static keyword
# Declares a static method ONLY if type is also present
(?:
(static)
\\s+
)?
# Return type
(?:
([\\w\\|_\\\\]+)
\\s+
)?
# Legacy method name (not captured)
(?:
[\\w_]+\\(\\)\\s+
)?
# Method name
([\\w\\|_\\\\]+)
# Arguments
\\(([^\\)]*)\\)
\\s*
# Description
(.*)
$/sux', $body, $matches)) {
return null;
}
list(, $static, $returnType, $methodName, $arguments, $description) = $matches;
$static = $static === 'static';
$returnType = $typeResolver->resolve($returnType, $context);
$description = $descriptionFactory->create($description, $context);
$arguments = explode(',', $arguments);
foreach ($arguments as &$argument) {
$argument = explode(' ', trim($argument));
if ($argument[0][0] === '$') {
$argumentName = substr($argument[0], 1);
$argumentType = new Void();
} else {
$argumentType = $typeResolver->resolve($argument[0], $context);
$argumentName = '';
if (isset($argument[1])) {
$argumentName = substr($argument[1], 1);
}
}
$argument = ['name' => $argumentName, 'type' => $argumentType];
}
return new static($methodName, $arguments, $returnType, $static, $description);
}
示例2: setPositionOfProduct
/**
* {@inheritdoc}
*/
public function setPositionOfProduct($productName, $position)
{
/** @var NodeElement $productsRow */
$productsRow = $this->getElement('table')->find('css', sprintf('tbody > tr:contains("%s")', $productName));
Assert::notNull($productsRow, 'There are no row with given product\'s name!');
$productsRow->find('css', '.sylius-product-taxon-position')->setValue($position);
}
示例3: addParticipation
/**
* Adds a participation to the data collector.
*
* @param string $testIdentifier It will look like "Qp0gahJ3RAO3DJ18b0XoUQ"
* @param int $variationIndex
* @throws InvalidArgumentException
*/
public function addParticipation($testIdentifier, $variationIndex)
{
Assert::string($testIdentifier, 'Test identifier must be a string');
Assert::integer($variationIndex, 'Variation index must be integer');
Assert::greaterThan($variationIndex, -1, 'Variation index must be integer >= 0');
$this->participations[$testIdentifier] = $variationIndex;
}
示例4: onCheckoutComplete
/**
* {@inheritdoc}
*/
public function onCheckoutComplete(GenericEvent $event)
{
/** @var OrderInterface $order */
$order = $event->getSubject();
Assert::isInstanceOf($order, OrderInterface::class);
$this->session->set('sylius_order_id', $order->getId());
}
示例5: iAmLoggedInAsAdministrator
/**
* @Given /^I am logged in as "([^"]+)" administrator$/
*/
public function iAmLoggedInAsAdministrator($email)
{
$user = $this->userRepository->findOneByEmail($email);
Assert::notNull($user);
$this->securityService->logIn($user);
$this->sharedStorage->set('admin', $user);
}
示例6: create
/**
* {@inheritdoc}
*/
public static function create($body, FqsenResolver $resolver = null, DescriptionFactory $descriptionFactory = null, TypeContext $context = null)
{
Assert::string($body);
Assert::allNotNull([$resolver, $descriptionFactory]);
$parts = preg_split('/\\s+/Su', $body, 2);
return new static($resolver->resolve($parts[0], $context), $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context));
}
示例7: create
/**
* Create the tag
*
* @param string $body Tag body
* @param DescriptionFactory $descriptionFactory The description factory
* @param Context|null $context The Context is used to resolve Types and FQSENs, although optional
* it is highly recommended to pass it. If you omit it then it is assumed that
* the DocBlock is in the global namespace and has no `use` statements.
*
* @return SleepTime
*/
public static function create($body, DescriptionFactory $descriptionFactory = null, Context $context = null)
{
Assert::integerish($body, self::MSG);
Assert::greaterThanEq($body, 0, self::MSG);
Assert::notNull($descriptionFactory);
return new static($descriptionFactory->create($body, $context));
}
示例8: getCountryByName
/**
* @Transform /^country "([^"]+)"$/
* @Transform /^"([^"]+)" country$/
* @Transform /^"([^"]+)" as shipping country$/
*/
public function getCountryByName($countryName)
{
$countryCode = $this->countryNameConverter->convertToCode($countryName);
$country = $this->countryRepository->findOneBy(['code' => $countryCode]);
Assert::notNull($country, sprintf('Country with name "%s" does not exist', $countryName));
return $country;
}
示例9: __construct
/**
* Creates the input.
*
* @param resource $stream A stream resource.
*/
public function __construct($stream)
{
Assert::resource($stream, 'stream');
$this->stream = $stream;
// Not all streams are seekable
@rewind($this->stream);
}
示例10: __construct
/**
* @param int $totalSales
* @param int $numberOfNewOrders
* @param int $numberOfNewCustomers
*/
public function __construct($totalSales, $numberOfNewOrders, $numberOfNewCustomers)
{
Assert::allInteger([$totalSales, $numberOfNewCustomers, $numberOfNewOrders]);
$this->totalSales = $totalSales;
$this->numberOfNewOrders = $numberOfNewOrders;
$this->numberOfNewCustomers = $numberOfNewCustomers;
}
示例11: format
/**
* {@inheritdoc}
*/
public function format($amount, $currency, $locale = 'en')
{
$formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
$result = $formatter->formatCurrency($amount / 100, $currency);
Assert::notSame(false, $result, sprintf('The amount "%s" of type %s cannot be formatted to currency "%s".', $amount, gettype($amount), $currency));
return $result;
}
示例12: iShouldBeViewingTheAdministrationPanelIn
/**
* @Then I should be viewing the administration panel in :localeCode
* @Then I should still be viewing the administration panel in :localeCode
* @Then they should be viewing the administration panel in :localeCode
*/
public function iShouldBeViewingTheAdministrationPanelIn($localeCode)
{
$this->dashboardPage->open();
$expectedSubHeader = $this->translate('sylius.ui.overview_of_your_store', $localeCode);
$actualSubHeader = $this->dashboardPage->getSubHeader();
Assert::same($actualSubHeader, $expectedSubHeader, sprintf('Dashboard header should say "%s", but says "%s" instead.', $expectedSubHeader, $actualSubHeader));
}
示例13: __construct
/**
* @param UniquenessCheckerInterface $uniquenessChecker
* @param int $pinLength
*
* @throws \InvalidArgumentException
*/
public function __construct(UniquenessCheckerInterface $uniquenessChecker, $pinLength)
{
Assert::integer($pinLength, 'The value of pin length has to be an integer.');
Assert::range($pinLength, 1, 9, 'The value of pin length has to be in range between 1 to 9.');
$this->pinLength = $pinLength;
$this->uniquenessChecker = $uniquenessChecker;
}
示例14: undefineType
/**
* {@inheritdoc}
*/
public function undefineType($typeName)
{
Assert::stringNotEmpty($typeName, 'The type name must be a non-empty string. Got: %s');
$this->removeBindingsByType($typeName);
unset($this->types[$typeName]);
unset($this->typeIndex[$typeName]);
}
示例15: getLastProvinceElement
/**
* @return Element
*/
private function getLastProvinceElement()
{
$provinces = $this->getElement('provinces');
$items = $provinces->findAll('css', 'div[data-form-collection="item"]');
Assert::notEmpty($items);
return end($items);
}