Skip to content

Commit

Permalink
Test more constant expression executable lines
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Oct 22, 2022
1 parent 74b7413 commit 5409243
Show file tree
Hide file tree
Showing 2 changed files with 329 additions and 1 deletion.
285 changes: 285 additions & 0 deletions tests/_files/source_with_multiline_constant_return.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,289 @@ public function Spaceship(): int
1
;
}

public function nowdocSimpleA(): string
{
return <<<'EOF'
foo
EOF;
}

public function nowdocSimpleB(): string
{
return
<<<'EOF'
foo
EOF;
}

public function nowdocSimpleC(): string
{
return
<<<'EOF'
foo
EOF
;
}

public function nowdocConcatA(): string
{
return '' .
<<<'EOF'
foo
EOF;
}

public function nowdocConcatB(): string
{
return ''
. <<<'EOF'
foo
EOF;
}

public function nowdocConcatC(): string
{
return <<<'EOF'
foo
EOF
. '';
}

public function nowdocConcatNested(): string
{
return (<<<'EOF'
foo
EOF
. <<<'EOF'
foo
EOF)
. (<<<'EOF'
foo
EOF
. <<<'EOF'
foo
EOF);
}

public function complexAssociativityRight(): int
{
return
1
**
2
**
3;
}

public function complexAssociativityLeft(): int
{
return
1
>>
2
>>
3;
}

public function complexAssociativityNa(): bool
{
return
!
!
!
false;
}

public function complexTernary(): int
{
return
1
? (
2
? 3
: 4
)
: 5;
}

public function complexNullCoalescing(): int
{
return
null
??
1
??
null;
}

public function constFromArray(): string
{
return [
'foo',
'bar',
'ro',
'fi',
'omega',
][2];
}

public function withNotConstInTheMiddle(): string
{
return
''
. ''
. phpversion()
. ''
. '';
}

public function andA(): bool
{
return
true
&& false;
}

public function andB(): bool
{
return
true
&& true;
}

public function andC(): bool
{
return
false
&& true;
}

public function andD(): bool
{
return
false
&& false;
}

public function andE(): bool
{
return
__TRAIT__ // compile time constant evaluated to false
&& 1
&& 0;
}

public function andF(): bool
{
return
PHP_VERSION_ID // compile time constant evaluated to true
&& 1
&& 0;
}

public function orA(): bool
{
return
true
|| false;
}

public function orB(): bool
{
return
true
|| true;
}

public function orC(): bool
{
return
false
|| true;
}

public function orD(): bool
{
return
false
|| false;
}

public function orE(): bool
{
return
__TRAIT__
|| true
|| false;
}

public function orF(): bool
{
return
PHP_VERSION_ID
|| true
|| false;
}

public function orG(): bool
{
return
PHP_VERSION_ID === PHP_VERSION_ID
|| true
|| false;
}

public function orH(): bool
{
return
PHP_VERSION_ID !== PHP_VERSION_ID
|| true
|| false;
}

public function constIfFalseA(): bool
{
if (false) {
return true;
}

return false;
}

public function constIfFalseB(): bool
{
if (__TRAIT__) {
return true;
}

return false;
}

public function constIfTrueA(): bool
{
if (true) {
return true;
}

return false;
}

public function constIfTrueB(): bool
{
if (PHP_VERSION_ID) {
return true;
}

return false;
}

public function constIfUnknown(): bool
{
if (__NOT_EXPECTED_TO_BE_KNOWN_CONSTANT__) {
return true;
}

return false;
}
}
45 changes: 44 additions & 1 deletion tests/tests/Data/RawCodeCoverageDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ public function testReturnStatementWithConstantExprOnlyReturnTheLineOfLast(): vo
28,
37,
46,
53,
55,
64,
73,
Expand All @@ -446,7 +447,7 @@ public function testReturnStatementWithConstantExprOnlyReturnTheLineOfLast(): vo
100,
109,
118,
127,
125,
136,
145,
154,
Expand All @@ -460,6 +461,48 @@ public function testReturnStatementWithConstantExprOnlyReturnTheLineOfLast(): vo
226,
235,
244,
251,
259,
267,
276,
284,
293,
308,
319,
329,
338,
344,
350,
356,
360,
371,
379,
381,
388,
395,
401,
408,
415,
425,
431,
438,
446,
453,
460,
467,
475,
484,
490,
494,
499,
503,
508,
509,
517,
518,
526,
527,
530,
],
array_keys(RawCodeCoverageData::fromUncoveredFile($file, new ParsingFileAnalyser(true, true))->lineCoverage()[$file])
);
Expand Down

0 comments on commit 5409243

Please sign in to comment.