Example #1
0
 /**
  * @param string $login
  * @param string $htmlUrl
  */
 public function __construct($login, $htmlUrl)
 {
     Assert\that($login)->string();
     Assert\that($htmlUrl)->string()->url();
     $this->login = $login;
     $this->htmlUrl = $htmlUrl;
 }
 private function __construct(EventId $eventId, Contract $eventContract, $eventPayload)
 {
     Assert\that($eventPayload)->string();
     $this->eventId = $eventId;
     $this->eventContract = $eventContract;
     $this->eventPayload = $eventPayload;
 }
Example #3
0
 /**
  * @param string $sha
  * @param string $message
  */
 public function __construct($sha, $message)
 {
     Assert\that($sha)->string()->regex('/^[0-9a-f]{40}$/i');
     Assert\that($message)->string();
     $this->sha = $sha;
     $this->message = $message;
 }
 /**
  * @param string $id
  * @param string $title
  */
 public function __construct($id, $title)
 {
     Assert\that($id)->integerish()->greaterThan(0);
     Assert\that($title)->string();
     $this->id = $id;
     $this->title = $title;
 }
Example #5
0
 /**
  * Sends a message
  *
  * @param integer             $number
  * @param string              $message
  * @param string|null         $sender
  * @param integer|string|null $reference
  * @param array|string|null   $callbackParams
  * @param string|null         $callback
  *
  * @return Receipt
  */
 public function send($number, $message, $sender = null, $reference = null, $callbackParams = null, $callback = null)
 {
     Assertion::integerish($number);
     Assert\that($message)->notEmpty()->string();
     Assertion::nullOrString($sender);
     Assertion::nullOrStringOrInteger($reference);
     Assertion::nullOrAllInRangeOrAll($callbackParams, 1, 10);
     Assertion::nullOrUrl($callback);
     $result = $this->call(compact('number', 'message', 'sender', 'reference', 'callbackParams', 'callback'));
     return Receipt::create($result);
 }
 private function validateConfig(array $config)
 {
     Assert\that($config)->keyExists('connections', 'Config \'connections\' array not set');
     Assert\that($config)->keyExists('ddl_dir', 'Config \'ddl_dir\' not set');
     Assert\that($config)->keyExists('ddls', 'Config \'ddls\' not set');
     Assert\that($config['connections'], 'Invalid \'connections\' config key')->isArray()->notEmpty();
     Assert\that($config['ddls'], 'Invalid \'ddls\' config key')->isArray()->notEmpty();
     Assert\that($config['ddl_dir'], 'Invalid \'ddl_dir\' config key. Not a string')->string();
     $ddl_dir = trim($config['ddl_dir']);
     Assert\that($ddl_dir, 'Invalid \'ddl_dir\' config key. Empty')->notEmpty();
 }
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $zfConfig = $serviceLocator->get('Config');
     Assert\that($zfConfig)->keyIsset('isDevMode');
     // TODO: Make this better?
     $entityDir = getcwd() . '/module/Application/src/Entities';
     $config = Setup::createAnnotationMetadataConfiguration([$entityDir], $zfConfig['isDevMode']);
     Assert\that($zfConfig)->keyIsset('db_conn');
     Assert\that($zfConfig['db_conn'])->keyIsset('driver');
     Assert\that($zfConfig['db_conn'])->keyIsset('path');
     return EntityManager::create($zfConfig['db_conn'], $config);
 }
 /**
  * @param XMLString $xml
  * @param string $type
  *
  * @throws InvalidArgumentException
  */
 public function __construct(XMLString $xml, $type = 'bibtex')
 {
     Assert\that($type)->string()->regex('#^(bibtex|ris)$#');
     $xsl = XSLString::fromString(file_get_contents(dirname(__FILE__) . '/../../../lib/xsl/jats-to-' . $type . '.xsl'));
     parent::__construct($xml, $xsl);
 }
Example #9
0
 /**
  * Sets the reason
  *
  * @param string|null $reason
  */
 public function setReason($reason)
 {
     Assert\that($reason)->nullOr()->string();
     $this->reason = $reason;
 }
Example #10
0
 /**
  * Make a contract with a given name, for when you have string representation of a contract.
  * @param string $name
  * @return Contract
  */
 public static function with($name)
 {
     Assert\that($name)->string()->betweenLength(1, 255);
     return new Contract($name);
 }
Example #11
0
 /**
  * @param string $value
  */
 private function __construct($value)
 {
     $value = is_string($value) ? trim($value) : $value;
     Assert\that($value)->string()->notBlank();
     $this->value = $value;
 }
Example #12
0
 /**
  * Sets the list
  *
  * @param string $list
  */
 public function setList($list)
 {
     Assert\that($list)->notEmpty()->choice(['ips', 'players']);
     $this->list = $list;
 }
Example #13
0
<?php

require_once __DIR__ . '/../../../../vendor/autoload.php';
use function Terah\Assert\Assert;
use Assert as Beberlei;
$assert = new Assert('');
Assert::that('');
Beberlei\that('');
echo "Benchmarking static Terah\\Assert";
$start = microtime(true);
for ($i = 0; $i < 100000; $i++) {
    Assert::that(true)->true();
}
$time = microtime(true) - $start;
echo "Taken: {$time}" . PHP_EOL;
echo "Benchmarking new Terah\\Assert";
$start = microtime(true);
for ($i = 0; $i < 100000; $i++) {
    Assert(true)->true();
}
$time = microtime(true) - $start;
echo "Taken: {$time}" . PHP_EOL;
echo "Benchmarking fluent Beberlei";
$start = microtime(true);
for ($i = 0; $i < 100000; $i++) {
    Beberlei\that(true)->true();
}
$time = microtime(true) - $start;
echo "Taken: {$time}" . PHP_EOL;
Example #14
0
 /**
  * Sets the customer phone
  *
  * @param string $customerPhone
  */
 public function setCustomerPhone($customerPhone)
 {
     Assert\that($customerPhone)->notEmpty()->string();
     $this->customerPhone = $customerPhone;
 }
Example #15
0
 /**
  * Sets the player
  *
  * @param string $player
  */
 public function setPlayer($player)
 {
     Assert\that($player)->notEmpty()->string();
     $this->player = $player;
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function setQuantity($quantity)
 {
     Assert\that($quantity)->integer('Quantity must be an integer')->min(1, 'Quantity must greater than zero');
     $this->quantity = $quantity;
 }
 /**
  * @dataProvider \Refinery29\Test\Util\DataProvider\InvalidUuidNotNull::data()
  *
  * @param mixed $value
  */
 public function testIsNotAUuid($value)
 {
     $this->expectException(\InvalidArgumentException::class);
     Assert\that($value)->string()->uuid();
 }
Example #18
0
 /**
  * @dataProvider \Refinery29\Test\Util\DataProvider\InvalidUrl::data()
  *
  * @param mixed $value
  */
 public function testIsNotAUrl($value)
 {
     $this->expectException(\InvalidArgumentException::class);
     Assert\that($value)->url();
 }
 /**
  * @dataProvider \Refinery29\Test\Util\DataProvider\InvalidIntegerishNotNull::data()
  *
  * @param mixed $value
  */
 public function testIsNotIntegerish($value)
 {
     $this->expectException(\InvalidArgumentException::class);
     Assert\that($value)->integerish();
 }
Example #20
0
 private function setSenderTo($senderTo)
 {
     that($senderTo)->integerish()->min(1);
     $this->senderTo = $senderTo;
     return $this;
 }
 /**
  * @dataProvider \Refinery29\Test\Util\DataProvider\InvalidIsoDateNotNull::data()
  *
  * @param mixed $value
  */
 public function testIsNotAnIsoDate($value)
 {
     $this->expectException(\InvalidArgumentException::class);
     Assert\that($value)->string()->date(DATE_ATOM);
 }
Example #22
0
 /**
  * Sets the comment
  *
  * @param string $comment
  */
 public function setComment($comment)
 {
     Assert\that($comment)->notEmpty()->string();
     $this->comment = $comment;
 }
Example #23
0
 /**
  * @param HttpAdapterInterface $adapter
  * @param string               $apiKey
  */
 public function __construct(HttpAdapterInterface $adapter, $apiKey)
 {
     Assert\that($apiKey, 'Invalid API key')->notEmpty()->string();
     $this->adapter = $adapter;
     $this->apiKey = $apiKey;
 }
Example #24
0
 /**
  * @param array $config
  *
  * @return string
  */
 protected function extractManipulatorNameFromConfig(array $config) : string
 {
     that($config)->notEmptyKey('type');
     return (string) $config['type'];
 }