Пример #1
0
 public function join($delimiter = ' ')
 {
     if (!is_a_string($delimiter)) {
         $delimiter = var_export($delimiter, true);
         throw new \InvalidArgumentException("Invalid delimiter given: {$delimiter}");
     }
     $strings = $this->map(function ($v) {
         return strval($v);
     });
     return S(join($delimiter, $strings->to_array()));
 }
Пример #2
0
function ensure($name, $value, $fn, $class = null, $method = null)
{
    if (!is_callable($fn)) {
        throw new InvalidArgumentException("#ensure: Given callback is not callable: " . sdump($fn));
    }
    if (!is_a_string($name)) {
        throw new InvalidArgumentException("#ensure: Given argument name is not a string: " . sdump($fn));
    }
    // TODO: Contract for $value
    if (is_not_null($class) && is_null($method)) {
        $method = $class;
        $class = null;
    }
    if (!$fn($value)) {
        throw new InvalidArgumentException("{$class}#{$method}: {$name} does not comply argument contract " . sdump($fn) . ": " . sdump($value) . ')');
    }
}
Пример #3
0
 protected function is_a_string_tests()
 {
     $this->should->assert('is_a_string() should return false on passing an integer', '', function () {
         return false === is_a_string(0);
     });
     $this->should->assert('is_a_string() should return false on passing an array', '', function () {
         return false === is_a_string([]);
     });
     $this->should->assert('is_a_string() should return false on passing an object of type other than \\Sauce\\String', '', function () {
         return false === is_a_string(A());
     });
     $this->should->assert('is_a_string() should return true on passing an object of type \\Sauce\\String', '', function () {
         return true === is_a_string(S());
     });
     $this->should->assert('is_a_string() should return true on passing a string', '', function () {
         return true === is_a_string('abc');
     });
 }