Skip to content

Commit a9bc033

Browse files
committed
Extract assertion into helper method
1 parent 24f3b2c commit a9bc033

File tree

1 file changed

+28
-36
lines changed

1 file changed

+28
-36
lines changed

src/test/php/lang/ast/unittest/emit/CallableSyntaxTest.class.php

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,137 +2,129 @@
22

33
use unittest\{Assert, Test, Values};
44

5+
/**
6+
* Tests for first-class callable syntax
7+
*
8+
* @see https://wiki.php.net/rfc/first_class_callable_syntax#proposal
9+
*/
510
class CallableSyntaxTest extends EmittingTest {
611

12+
/**
13+
* Verification helper
14+
*
15+
* @param string $code
16+
* @return void
17+
* @throws unittest.AssertionFailedError
18+
*/
19+
private function verify($code) {
20+
Assert::equals(4, $this->run($code)('Test'));
21+
}
22+
723
#[Test]
824
public function native_function() {
9-
$f= $this->run('class <T> {
25+
$this->verify('class <T> {
1026
public function run() { return strlen(...); }
1127
}');
12-
13-
Assert::equals(4, $f('Test'));
1428
}
1529

1630
#[Test]
1731
public function instance_method() {
18-
$f= $this->run('class <T> {
32+
$this->verify('class <T> {
1933
public function length($arg) { return strlen($arg); }
2034
public function run() { return $this->length(...); }
2135
}');
22-
23-
Assert::equals(4, $f('Test'));
2436
}
2537

2638
#[Test]
2739
public function class_method() {
28-
$f= $this->run('class <T> {
40+
$this->verify('class <T> {
2941
public static function length($arg) { return strlen($arg); }
3042
public function run() { return self::length(...); }
3143
}');
32-
33-
Assert::equals(4, $f('Test'));
3444
}
3545

3646
#[Test]
3747
public function private_method() {
38-
$f= $this->run('class <T> {
48+
$this->verify('class <T> {
3949
private function length($arg) { return strlen($arg); }
4050
public function run() { return $this->length(...); }
4151
}');
42-
43-
Assert::equals(4, $f('Test'));
4452
}
4553

4654
#[Test]
4755
public function variable_function() {
48-
$f= $this->run('class <T> {
56+
$this->verify('class <T> {
4957
public function run() {
5058
$func= "strlen";
5159
return $func(...);
5260
}
5361
}');
54-
55-
Assert::equals(4, $f('Test'));
5662
}
5763

5864
#[Test]
5965
public function instance_method_reference() {
60-
$f= $this->run('class <T> {
66+
$this->verify('class <T> {
6167
private $func= "strlen";
6268
public function run() {
6369
return ($this->func)(...);
6470
}
6571
}');
66-
67-
Assert::equals(4, $f('Test'));
6872
}
6973

7074
#[Test, Values(['$this->$func(...)', '$this->{$func}(...)'])]
7175
public function variable_instance_method($expr) {
72-
$f= $this->run('class <T> {
76+
$this->verify('class <T> {
7377
private function length($arg) { return strlen($arg); }
7478
public function run() {
7579
$func= "length";
7680
return '.$expr.';
7781
}
7882
}');
79-
80-
Assert::equals(4, $f('Test'));
8183
}
8284

8385
#[Test, Values(['self::$func(...)', 'self::{$func}(...)'])]
8486
public function variable_class_method($expr) {
85-
$f= $this->run('class <T> {
87+
$this->verify('class <T> {
8688
private static function length($arg) { return strlen($arg); }
8789
public function run() {
8890
$func= "length";
8991
return '.$expr.';
9092
}
9193
}');
92-
93-
Assert::equals(4, $f('Test'));
9494
}
9595

9696
#[Test]
9797
public function variable_class_method_with_variable_class() {
98-
$f= $this->run('class <T> {
98+
$this->verify('class <T> {
9999
private static function length($arg) { return strlen($arg); }
100100
public function run() {
101101
$func= "length";
102102
$class= __CLASS__;
103103
return $class::$func(...);
104104
}
105105
}');
106-
107-
Assert::equals(4, $f('Test'));
108106
}
109107

110108
#[Test]
111109
public function string_function_reference() {
112-
$f= $this->run('class <T> {
110+
$this->verify('class <T> {
113111
public function run() { return "strlen"(...); }
114112
}');
115-
116-
Assert::equals(4, $f('Test'));
117113
}
118114

119115
#[Test]
120116
public function array_instance_method_reference() {
121-
$f= $this->run('class <T> {
117+
$this->verify('class <T> {
122118
public function length($arg) { return strlen($arg); }
123119
public function run() { return [$this, "length"](...); }
124120
}');
125-
126-
Assert::equals(4, $f('Test'));
127121
}
128122

129123
#[Test]
130124
public function array_class_method_reference() {
131-
$f= $this->run('class <T> {
125+
$this->verify('class <T> {
132126
public static function length($arg) { return strlen($arg); }
133127
public function run() { return [self::class, "length"](...); }
134128
}');
135-
136-
Assert::equals(4, $f('Test'));
137129
}
138130
}

0 commit comments

Comments
 (0)