예제 #1
0
파일: Vector.php 프로젝트: brainsware/sauce
 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
파일: String.php 프로젝트: brainsware/sauce
 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');
     });
 }