function it_might_allow_types_to_be_passed(Type $type, Type $anotherType) { $type->allows($anotherType)->willReturn(false); $this->allows($anotherType)->shouldBe(false); $type->allows($anotherType)->willReturn(true); $this->allows($anotherType)->shouldBe(true); }
function it_may_allow_a_type(Type $type, Type $anotherType) { $type->allows($anotherType)->willReturn(true); $this->allows($anotherType)->shouldBe(true); $type->allows($anotherType)->willReturn(false); $this->allows($anotherType)->shouldBe(false); }
function it_does_not_allow_collections_of_other_generics(ClassType $collection, Type $generic) { $allowedCollectionClass = new ClassType(ClassReflectionStubBuilder::build()->implement(Traversable::class)->finish()); $notAllowedGeneric = new StringType(); $collection->allows($allowedCollectionClass)->willReturn(true); $generic->allows($notAllowedGeneric)->willReturn(false); $this->allows(new CollectionType($allowedCollectionClass, $notAllowedGeneric))->shouldBe(false); }
public function allows(Type $type) : bool { if ($type instanceof ComposedType) { return !in_array(false, array_map([$this, 'allows'], $type->decoratedTypes())); } if ($this->type instanceof MixedType && $type instanceof ClassType) { return $type->reflection()->implementsInterface(Traversable::class); } if ($type instanceof self || $type instanceof ArrayType || $type instanceof CollectionType) { return $this->decoratedType()->allows($type->decoratedType()); } return false; }
public function allows(Type $type) : bool { return $this->type->allows($type); }
function it_allows_composed_types_if_all_types_are_allowed(Type $decorated) { $decorated->allows(Argument::type(StringType::class))->willReturn(false); $this->allows(new ComposedType(new NullType(), new NullType()))->shouldBe(true); $this->allows(new ComposedType(new NullType(), new StringType()))->shouldBe(false); }