-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathCallTest.php
52 lines (40 loc) · 1.61 KB
/
CallTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
namespace Overblog\GraphQLBundle\Tests\ExpressionLanguage\ExpressionFunction;
use Overblog\GraphQLBundle\ExpressionLanguage\ExpressionFunction\Call;
use Overblog\GraphQLBundle\Tests\ExpressionLanguage\TestCase;
use function sprintf;
use function str_replace;
final class CallTest extends TestCase
{
protected function getFunctions(): array
{
return [new Call()];
}
public function method(string $arg): string
{
return $arg.$arg;
}
public static function staticMethod(string $arg): string
{
return $arg.$arg;
}
public function testCallCompile(): void
{
// Compile
$this->assertEquals('AA', eval('
$class = new '.self::class.'();
return '.$this->expressionLanguage->compile('call(class.method, ["A"])', ['class']).';
'));
$this->assertEquals('AA', eval('return '.$this->expressionLanguage->compile(sprintf('call("%s::method", ["A"])', str_replace('\\', '\\\\', self::class))).';'));
}
public function testCallEvaluate(): void
{
// Static method using FQN
$this->assertEquals('AA', $this->expressionLanguage->evaluate(sprintf('call("%s::staticMethod", ["A"])', str_replace('\\', '\\\\', self::class))));
// Static method using array callable
$this->assertEquals('AA', $this->expressionLanguage->evaluate(sprintf('call(["%s", "staticMethod"], ["A"])', str_replace('\\', '\\\\', self::class))));
// Global function
$this->assertEquals('AA', $this->expressionLanguage->evaluate('call("\implode", ["", ["A", "A"]])'));
}
}