assertSame('int|string', (string) Type::parseString('int|string')); } /** * @return void */ public function testNullable() { $this->assertSame('null|string', (string) Type::parseString('?string')); } /** * @return void */ public function testArray() { $this->assertSame('array', (string) Type::parseString('array')); $this->assertSame('array', (string) Type::parseString('array')); $this->assertSame('array', (string) Type::parseString('array')); $this->assertSame('array', (string) Type::parseString('array')); } /** * @return void */ public function testGeneric() { $this->assertSame('B', (string) Type::parseString('B')); } /** * @return void */ public function testPhpDocStyle() { $this->assertSame('array', (string) Type::parseString('A[]')); $this->assertSame('array', (string) Type::parseString('(A|B)[]')); $this->assertSame('array>', (string) Type::parseString('A[][]')); $this->assertSame('array>', (string) Type::parseString('(A|B)[][]')); $this->assertSame('array', (string) Type::parseString('A[]|B[]')); $this->assertSame('array|C', (string) Type::parseString('A[]|B[]|C')); } /** * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testInvalidType() { Type::parseString('array(A)'); } /** * @return void */ public function testObjectLike() { $this->assertSame('array{a:int, b:string}', (string) Type::parseString('array{a:int, b:string}')); $this->assertSame( 'array{a:int|string, b:string}', (string) Type::parseString('array{a:int|string, b:string}') ); $this->assertSame( 'array{a:array, b:string}', (string) Type::parseString('array{a:array, b:string}') ); $this->assertSame( 'array{0:stdClass|null}', (string)Type::parseString('array{stdClass|null}') ); $this->assertSame( 'array{0:array}', (string)Type::parseString('array{array}') ); $this->assertSame( 'array{0:array}', (string)Type::parseString('array{array}') ); } }