コード例 #1
0
ファイル: ClassTypeSpec.php プロジェクト: dkplus/reflections
 function it_allows_collections_if_the_collection_class_is_of_this_class(ClassReflection $reflection)
 {
     $sameClassReflection = ClassReflectionStubBuilder::build()->implement(Traversable::class)->withClassName('MyClass')->finish();
     $anotherClassReflection = ClassReflectionStubBuilder::build()->implement(Traversable::class)->finish();
     $this->allows(new CollectionType(new ClassType($sameClassReflection), new StringType()))->shouldBe(true);
     $this->allows(new CollectionType(new ClassType($anotherClassReflection), new StringType()))->shouldBe(false);
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 function it_allows_collections_instances_if_its_decorated_type_matches_the_generic_type()
 {
     $this->beConstructedWith(new StringType());
     $matchingType = new StringType();
     $notMatchingType = new MixedType();
     $classReflection = ClassReflectionStubBuilder::build()->implement(Traversable::class)->finish();
     $this->allows(new CollectionType(new ClassType($classReflection), $matchingType))->shouldBe(true);
     $this->allows(new CollectionType(new ClassType($classReflection), $notMatchingType))->shouldBe(false);
 }
コード例 #4
0
 function it_allows_invokable_classes()
 {
     $this->allows(new ClassType(ClassReflectionStubBuilder::build()->withInvokable(true)->finish()))->shouldBe(true);
     $this->allows(new ClassType(ClassReflectionStubBuilder::build()->withInvokable(false)->finish()))->shouldBe(false);
 }
コード例 #5
0
 function it_creates_a_collection_if_only_iterable_phpdoc_types_and_a_traversable_class_type_are_given(Reflector $reflector)
 {
     $traversableClass = ClassReflectionStubBuilder::build()->implement(Traversable::class)->finish();
     $nonTraversableClass = ClassReflectionStubBuilder::build()->finish();
     $reflector->reflectClass('Collection')->willReturn($traversableClass);
     $reflector->reflectClass('stdClass')->willReturn($nonTraversableClass);
     $this->create($reflector, new Mixed(), ['string[]', 'Collection'], false)->shouldBeACollectionOf(StringType::class);
     $this->create($reflector, new Mixed(), ['string[]', 'int[]', 'Collection'], false)->shouldBeACollectionOf(StringType::class, IntegerType::class);
     $this->create($reflector, new Mixed(), ['string[]', 'stdClass'], false)->shouldBeAnInstanceOf(ComposedType::class);
 }
コード例 #6
0
ファイル: ObjectTypeSpec.php プロジェクト: dkplus/reflections
 function it_allows_classes_to_be_passed()
 {
     $this->allows(new ClassType(ClassReflectionStubBuilder::build()->finish()));
 }