create(ParserFactory::PREFER_PHP7); self::$config = new TestConfig(); } /** * @return \Psalm\Type\Atomic */ private static function getAtomic($string) { return array_values(Type::parseString($string)->types)[0]; } /** * @return void */ public function testIntOrString() { $this->assertEquals('int|string', (string) Type::parseString('int|string')); } /** * @return void */ public function testArray() { $this->assertEquals('array', (string) Type::parseString('array')); $this->assertEquals('array', (string) Type::parseString('array')); $this->assertEquals('array', (string) Type::parseString('array')); $this->assertEquals('array', (string) Type::parseString('array')); } /** * @return void */ public function testGeneric() { $this->assertEquals('B', (string) Type::parseString('B')); } /** * @return void */ public function testPhpDocStyle() { $this->assertEquals('array', (string) Type::parseString('A[]')); $this->assertEquals('array', (string) Type::parseString('(A|B)[]')); $this->assertEquals('array>', (string) Type::parseString('A[][]')); $this->assertEquals('array>', (string) Type::parseString('(A|B)[][]')); $this->assertEquals('array', (string) Type::parseString('A[]|B[]')); $this->assertEquals('array|C', (string) Type::parseString('A[]|B[]|C')); } /** * @return void */ public function testObjectLike() { $this->assertEquals('array{a:int, b:string}', (string) Type::parseString('array{a:int, b:string}')); $this->assertEquals( 'array{a:int|string, b:string}', (string) Type::parseString('array{a:int|string, b:string}') ); $this->assertEquals( 'array{a:array, b:string}', (string) Type::parseString('array{a:array, b:string}') ); } }