Skip to content

Commit f99e3b3

Browse files
committed
simplify test
1 parent 5f4200a commit f99e3b3

1 file changed

Lines changed: 15 additions & 47 deletions

File tree

tests/PHPStan/Rules/Variables/data/bug-14318.php

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -115,57 +115,25 @@ public static function maybeThrows8(int $s): void
115115
}
116116

117117
/**
118-
* @throws \RuntimeException
118+
* @param array<string>|null $reasons
119+
* @throws \Exception
119120
*/
120-
function maybeThrows9(string $s): void
121-
{
122-
if (random_int(0, 1) === 1) {
123-
throw new \RuntimeException();
121+
function check1(array &$reasons = null): void {
122+
$fileName = time() % 2 ? "abc":null;
123+
if (!$fileName) {
124+
$reasons[] = sprintf("Dependency check fail");
125+
throw new \Exception("check failed");
124126
}
125127
}
126128

127-
/**
128-
* @throws \RuntimeException
129-
*/
130-
function maybeThrows10(int $s): void
131-
{
132-
if (random_int(0, 1) === 1) {
133-
throw new \RuntimeException();
134-
}
135-
}
136-
137-
class HelloWorld9
138-
{
139-
public function test9(): void
140-
{
141-
global $pdo;
142-
143-
try {
144-
maybeThrows9($sql = "SELECT * FROM foo");
145-
$rs = $pdo->query($sql);
146-
if ($result = $rs->fetch(\PDO::FETCH_ASSOC)) {
147-
// do something
148-
}
149-
} catch (\PDOException $e) {
150-
var_dump($sql);
151-
}
152-
}
153-
}
154-
155-
class HelloWorld10
156-
{
157-
public function test10(): void
158-
{
159-
global $pdo;
160-
161-
try {
162-
maybeThrows10(strlen($sql = "SELECT * FROM foo"));
163-
$rs = $pdo->query($sql);
164-
if ($result = $rs->fetch(\PDO::FETCH_ASSOC)) {
165-
// do something
166-
}
167-
} catch (\PDOException $e) {
168-
var_dump($sql);
129+
function test1():void {
130+
try {
131+
check1($reasons);
132+
printf("ok\n");
133+
} catch (\Exception $e) {
134+
if (!empty($reasons)) {
135+
$e = new \Exception("Dependency check failed: " . implode(', ', $reasons), 0, $e);
169136
}
137+
throw new \Exception("Failed", 0, $e);
170138
}
171139
}

0 commit comments

Comments
 (0)