Mercurial > hg > isophonics-drupal-site
comparison vendor/psy/psysh/test/CodeCleaner/LoopContextPassTest.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | |
children | c2387f117808 |
comparison
equal
deleted
inserted
replaced
12:7a779792577d | 13:5fb285c0d0e3 |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of Psy Shell. | |
5 * | |
6 * (c) 2012-2018 Justin Hileman | |
7 * | |
8 * For the full copyright and license information, please view the LICENSE | |
9 * file that was distributed with this source code. | |
10 */ | |
11 | |
12 namespace Psy\Test\CodeCleaner; | |
13 | |
14 use Psy\CodeCleaner\LoopContextPass; | |
15 | |
16 class LoopContextPassTest extends CodeCleanerTestCase | |
17 { | |
18 public function setUp() | |
19 { | |
20 $this->setPass(new LoopContextPass()); | |
21 } | |
22 | |
23 /** | |
24 * @dataProvider invalidStatements | |
25 * @expectedException \Psy\Exception\FatalErrorException | |
26 */ | |
27 public function testProcessStatementFails($code) | |
28 { | |
29 $this->parseAndTraverse($code); | |
30 } | |
31 | |
32 public function invalidStatements() | |
33 { | |
34 return [ | |
35 ['continue'], | |
36 ['break'], | |
37 ['if (true) { continue; }'], | |
38 ['if (true) { break; }'], | |
39 ['if (false) { continue; }'], | |
40 ['if (false) { break; }'], | |
41 ['function foo() { break; }'], | |
42 ['function foo() { continue; }'], | |
43 | |
44 // actually enforce break/continue depth argument | |
45 ['do { break 2; } while (true)'], | |
46 ['do { continue 2; } while (true)'], | |
47 ['for ($a; $b; $c) { break 2; }'], | |
48 ['for ($a; $b; $c) { continue 2; }'], | |
49 ['foreach ($a as $b) { break 2; }'], | |
50 ['foreach ($a as $b) { continue 2; }'], | |
51 ['switch (true) { default: break 2; }'], | |
52 ['switch (true) { default: continue 2; }'], | |
53 ['while (true) { break 2; }'], | |
54 ['while (true) { continue 2; }'], | |
55 | |
56 // invalid in 5.4+ because they're floats | |
57 // ... in 5.3 because the number is too big | |
58 ['while (true) { break 2.0; }'], | |
59 ['while (true) { continue 2.0; }'], | |
60 | |
61 // and once with nested loops, just for good measure | |
62 ['while (true) { while (true) { break 3; } }'], | |
63 ['while (true) { while (true) { continue 3; } }'], | |
64 ]; | |
65 } | |
66 | |
67 /** | |
68 * @dataProvider invalidPHP54Statements | |
69 * @expectedException \Psy\Exception\FatalErrorException | |
70 */ | |
71 public function testPHP54ProcessStatementFails($code) | |
72 { | |
73 $this->parseAndTraverse($code); | |
74 } | |
75 | |
76 public function invalidPHP54Statements() | |
77 { | |
78 return [ | |
79 // In PHP 5.4+, only positive literal integers are allowed | |
80 ['while (true) { break $n; }'], | |
81 ['while (true) { continue $n; }'], | |
82 ['while (true) { break N; }'], | |
83 ['while (true) { continue N; }'], | |
84 ['while (true) { break 0; }'], | |
85 ['while (true) { continue 0; }'], | |
86 ['while (true) { break -1; }'], | |
87 ['while (true) { continue -1; }'], | |
88 ['while (true) { break 1.0; }'], | |
89 ['while (true) { continue 1.0; }'], | |
90 ]; | |
91 } | |
92 | |
93 /** | |
94 * @dataProvider validStatements | |
95 */ | |
96 public function testProcessStatementPasses($code) | |
97 { | |
98 $this->parseAndTraverse($code); | |
99 $this->assertTrue(true); | |
100 } | |
101 | |
102 public function validStatements() | |
103 { | |
104 return [ | |
105 ['do { break; } while (true)'], | |
106 ['do { continue; } while (true)'], | |
107 ['for ($a; $b; $c) { break; }'], | |
108 ['for ($a; $b; $c) { continue; }'], | |
109 ['foreach ($a as $b) { break; }'], | |
110 ['foreach ($a as $b) { continue; }'], | |
111 ['switch (true) { default: break; }'], | |
112 ['switch (true) { default: continue; }'], | |
113 ['while (true) { break; }'], | |
114 ['while (true) { continue; }'], | |
115 | |
116 // `break 1` is redundant, but not invalid | |
117 ['while (true) { break 1; }'], | |
118 ['while (true) { continue 1; }'], | |
119 | |
120 // and once with nested loops just for good measure | |
121 ['while (true) { while (true) { break 2; } }'], | |
122 ['while (true) { while (true) { continue 2; } }'], | |
123 ]; | |
124 } | |
125 } |