Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX: FunctionsAnalyzerTest - add missing 7.0 requirement #5442

Merged
merged 1 commit into from
Jan 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,25 @@ public function testFunctionReturnTypeInfo($code, $methodIndex, $expected)
$tokens = Tokens::fromCode($code);
$analyzer = new FunctionsAnalyzer();

static::assertSame(serialize($expected), serialize($analyzer->getFunctionReturnType($tokens, $methodIndex)));
$actual = $analyzer->getFunctionReturnType($tokens, $methodIndex);
static::assertSame(serialize($expected), serialize($actual));
}

/**
* @param string $code
* @param int $methodIndex
* @param array $expected
*
* @dataProvider provideFunctionsWithReturnTypePhp70Cases
* @requires PHP 7.0
*/
public function testFunctionReturnTypeInfoPhp70($code, $methodIndex, $expected)
{
$tokens = Tokens::fromCode($code);
$analyzer = new FunctionsAnalyzer();

$actual = $analyzer->getFunctionReturnType($tokens, $methodIndex);
static::assertSame(serialize($expected), serialize($actual));
}

public function provideFunctionsWithArgumentsCases()
Expand Down Expand Up @@ -514,6 +532,10 @@ public function provideFunctionsWithArgumentsCases()
public function provideFunctionsWithReturnTypeCases()
{
yield ['<?php function(){};', 1, null];
}

public function provideFunctionsWithReturnTypePhp70Cases()
{
yield ['<?php function($a): array {};', 1, new TypeAnalysis('array', 7, 7)];
yield ['<?php function($a): \Foo\Bar {};', 1, new TypeAnalysis('\Foo\Bar', 7, 10)];
yield ['<?php function($a): /* not sure if really an array */array {};', 1, new TypeAnalysis('array', 8, 8)];
Expand Down