Skip to content

Commit

Permalink
minor #5442 DX: FunctionsAnalyzerTest - add missing 7.0 requirement (…
Browse files Browse the repository at this point in the history
…keradus)

This PR was merged into the 2.17 branch.

Discussion
----------

DX: FunctionsAnalyzerTest - add missing 7.0 requirement

Commits
-------

4b95a78 DX: FunctionsAnalyzerTest - add missing 7.0 requirement
  • Loading branch information
keradus committed Jan 18, 2021
2 parents 7c550c6 + 4b95a78 commit 1f05946
Showing 1 changed file with 23 additions and 1 deletion.
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

0 comments on commit 1f05946

Please sign in to comment.