public function testAccept()
 {
     $this->assertTrue($this->instance->accept('test'), 'accepted by default');
     $collection = new MutableCollection([], new IsTypeOf('string'));
     $this->assertTrue($collection->accept('i am a string'));
     $this->assertFalse($collection->accept(123));
 }
Ejemplo n.º 2
0
<?php

namespace Rubicon\Collection;

use Rubicon\Collection\Constraint\IsInstanceOf;
require dirname(__DIR__) . '/vendor/autoload.php';
$validation = new IsInstanceOf([\ArrayObject::class, \stdClass::class]);
$collection = new MutableCollection([], $validation);
$collection->add(new \ArrayObject());
$collection->add(new \stdClass());
print_r($collection->toImmutable());
Ejemplo n.º 3
0
<?php

namespace Rubicon\Collection;

use Rubicon\Collection\Constraint\CompositeConstraint;
use Rubicon\Collection\Constraint\IsGreaterThan;
use Rubicon\Collection\Constraint\IsTypeOf;
use Rubicon\Collection\Constraint\Regex;
require dirname(__DIR__) . '/vendor/autoload.php';
$constraint = new CompositeConstraint([new IsTypeOf('integer'), new IsGreaterThan(2)], CompositeConstraint::CONSTRAINT_AND);
try {
    new MutableCollection([1, 2, 3], $constraint);
} catch (\Exception $exception) {
    echo $exception->getMessage() . PHP_EOL;
}
$collection = new MutableCollection([], new Regex('^api/.*$'));
$collection->add('api/result');