File tree Expand file tree Collapse file tree 3 files changed +66
-20
lines changed
tests/Type/WebMozartAssert Expand file tree Collapse file tree 3 files changed +66
-20
lines changed Original file line number Diff line number Diff line change @@ -754,18 +754,62 @@ private function getExpressionResolvers(): array
754
754
)
755
755
);
756
756
},
757
+ 'contains ' => static function (Scope $ scope , Arg $ value , Arg $ subString ): array {
758
+ return new BooleanAnd (
759
+ new FuncCall (
760
+ new Name ('is_string ' ),
761
+ [$ value ]
762
+ ),
763
+ new GreaterOrEqual (
764
+ new FuncCall (
765
+ new Name ('strpos ' ),
766
+ [$ value ]
767
+ ),
768
+ 0
769
+ )
770
+ );
771
+ },
772
+ 'startsWith ' => static function (Scope $ scope , Arg $ value , Arg $ subString ): array {
773
+ return new BooleanAnd (
774
+ new FuncCall (
775
+ new Name ('is_string ' ),
776
+ [$ value ]
777
+ ),
778
+ new Identical (
779
+ new FuncCall (
780
+ new Name ('strpos ' ),
781
+ [$ value , $ subString ]
782
+ ),
783
+ 0
784
+ )
785
+ );
786
+ },
787
+ 'endsWith ' => static function (Scope $ scope , Arg $ value , Arg $ subString ): array {
788
+ return new BooleanAnd (
789
+ new FuncCall (
790
+ new Name ('is_string ' ),
791
+ [$ value ]
792
+ ),
793
+ new Identical (
794
+ new FuncCall (
795
+ new Name ('strpos ' ),
796
+ [$ value , $ subString ]
797
+ ),
798
+ new BinaryOp \Minus (
799
+ new FuncCall (
800
+ new Name ('strlen ' ),
801
+ [$ value ]
802
+ ),
803
+ new FuncCall (
804
+ new Name ('strlen ' ),
805
+ [$ subString ]
806
+ )
807
+ )
808
+ )
809
+ );
810
+ },
757
811
];
758
812
759
- foreach (['contains ' , 'startsWith ' , 'endsWith ' ] as $ name ) {
760
- $ this ->resolvers [$ name ] = function (Scope $ scope , Arg $ value , Arg $ subString ) use ($ name ): array {
761
- if ($ scope ->getType ($ subString ->value )->isNonEmptyString ()->yes ()) {
762
- return self ::createIsNonEmptyStringAndSomethingExprPair ($ name , [$ value , $ subString ]);
763
- }
764
-
765
- return [$ this ->resolvers ['string ' ]($ scope , $ value ), null ];
766
- };
767
- }
768
-
769
813
$ assertionsResultingAtLeastInNonEmptyString = [
770
814
'startsWithLetter ' ,
771
815
'unicodeLetters ' ,
Original file line number Diff line number Diff line change @@ -12,17 +12,17 @@ class AssertTypeSpecifyingExtensionTest extends TypeInferenceTestCase
12
12
*/
13
13
public function dataFileAsserts (): iterable
14
14
{
15
- yield from $ this ->gatherAssertTypes (__DIR__ . '/data/array.php ' );
16
- yield from $ this ->gatherAssertTypes (__DIR__ . '/data/collection.php ' );
17
- yield from $ this ->gatherAssertTypes (__DIR__ . '/data/comparison.php ' );
18
- yield from $ this ->gatherAssertTypes (__DIR__ . '/data/object.php ' );
15
+ // yield from $this->gatherAssertTypes(__DIR__ . '/data/array.php');
16
+ // yield from $this->gatherAssertTypes(__DIR__ . '/data/collection.php');
17
+ // yield from $this->gatherAssertTypes(__DIR__ . '/data/comparison.php');
18
+ // yield from $this->gatherAssertTypes(__DIR__ . '/data/object.php');
19
19
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/string.php ' );
20
- yield from $ this ->gatherAssertTypes (__DIR__ . '/data/type.php ' );
21
-
22
- yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-18.php ' );
23
- yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-117.php ' );
24
- yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-150.php ' );
25
- yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-183.php ' );
20
+ // yield from $this->gatherAssertTypes(__DIR__ . '/data/type.php');
21
+ //
22
+ // yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-18.php');
23
+ // yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-117.php');
24
+ // yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-150.php');
25
+ // yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-183.php');
26
26
}
27
27
28
28
/**
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ class TestStrings
13
13
*/
14
14
public function contains (string $ a , string $ b ): void
15
15
{
16
+ Assert::startsWith ("foo " , "bar " );
17
+
16
18
Assert::contains ($ a , $ a );
17
19
assertType ('string ' , $ a );
18
20
You can’t perform that action at this time.
0 commit comments