Esempio n. 1
0
 public function endsWith($element)
 {
     $rep = Condition::stringOf($element);
     return $this->is(new Match(function ($value) use($element) {
         return sizeof($value) > 0 && Objects::equal($value[sizeof($value) - 1], $element);
     }, ['%s does not end with ' . $rep, '%s ends with ' . $rep]));
 }
 /**
  * Extracts a given key
  *
  * @param  string $key
  * @param  var
  * @throws lang.IndexOutOfBoundsException
  */
 public function extract($key)
 {
     foreach ([$key, 'get' . $key] as $variant) {
         if (method_exists($this->value, $variant)) {
             return $this->value->{$variant}();
         }
     }
     if (property_exists($this->value, $key)) {
         return $this->value->{$key};
     }
     throw new IndexOutOfBoundsException('Cannot extract "' . $key . '" from ' . Condition::stringOf($this->value));
 }
Esempio n. 3
0
 /**
  * Extract a given arg
  *
  * @param  string|string[]|function(var): var $arg
  * @return self
  */
 public function extracting($arg)
 {
     if ($arg instanceof \Closure) {
         return self::of($arg($this->value));
     } else {
         if (is_array($arg)) {
             $value = [];
             foreach ($arg as $key => $extract) {
                 $value[$key] = $this->extracting($extract)->value;
             }
             return self::of($value);
         } else {
             if (!array_key_exists($arg, $this->value)) {
                 throw new \lang\IndexOutOfBoundsException('Cannot extract "' . $arg . '" from ' . Condition::stringOf($this->value));
             }
             return self::of($this->value[$arg]);
         }
     }
 }
Esempio n. 4
0
 /**
  * Assert a given condition does not match this value
  * 
  * @param  unittest.assert.Condition $condition
  * @return self
  */
 public function isNot(Condition $condition)
 {
     $this->failed || Assertions::verify(function () use($condition) {
         if ($condition->matches($this->value)) {
             $this->failed = true;
             return new AssertionFailedError('Failed to verify that ' . $condition->describe($this->value, false));
         } else {
             return null;
         }
     });
     return $this;
 }