Skip to content

Commit 3892eba

Browse files
committed
import expect
1 parent f08e877 commit 3892eba

37 files changed

+526
-39
lines changed

Zend/tests/assert/expect_001.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
test passing assertion
3+
--INI--
4+
zend.assertions=1
5+
assert.exception=1
6+
--FILE--
7+
<?php
8+
assert(true);
9+
var_dump(true);
10+
?>
11+
--EXPECTF--
12+
bool(true)

Zend/tests/assert/expect_002.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
test failing assertion
3+
--INI--
4+
zend.assertions=1
5+
assert.exception=1
6+
--FILE--
7+
<?php
8+
assert(false);
9+
var_dump(true);
10+
?>
11+
--EXPECTF--
12+
Fatal error: Uncaught exception 'AssertionException' with message 'assert(false)' in %sexpect_002.php:%d
13+
Stack trace:
14+
#0 %sexpect_002.php(%d): assert(false, 'assert(false)')
15+
#1 {main}
16+
thrown in %sexpect_002.php on line %d

Zend/tests/assert/expect_003.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
test catching failed assertion
3+
--INI--
4+
zend.assertions=1
5+
assert.exception=1
6+
--FILE--
7+
<?php
8+
try {
9+
assert(false);
10+
} catch (AssertionException $ex) {
11+
var_dump($ex->getMessage());
12+
}
13+
?>
14+
--EXPECT--
15+
string(13) "assert(false)"

Zend/tests/assert/expect_004.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
test providing reason (fail)
3+
--INI--
4+
zend.assertions=1
5+
assert.exception=1
6+
--FILE--
7+
<?php
8+
try {
9+
assert(false, "I require this to succeed");
10+
} catch (AssertionException $ex) {
11+
var_dump($ex->getMessage());
12+
}
13+
?>
14+
--EXPECT--
15+
string(25) "I require this to succeed"

Zend/tests/assert/expect_005.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
test providing reason (pass)
3+
--INI--
4+
zend.assertions=1
5+
assert.exception=1
6+
--FILE--
7+
<?php
8+
try {
9+
/* by passing we test there are no leaks upon success */
10+
assert(true, "I require this to succeed");
11+
} catch (AssertionException $ex) {
12+
var_dump($ex->getMessage());
13+
}
14+
var_dump(true);
15+
?>
16+
--EXPECT--
17+
bool(true)

Zend/tests/assert/expect_006.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
test looping assert (pass)
3+
--INI--
4+
zend.assertions=1
5+
assert.exception=1
6+
--FILE--
7+
<?php
8+
for($i=0; $i<100000; $i++) {
9+
assert ($i < 100000, "The universe should make sense");
10+
}
11+
var_dump(true);
12+
?>
13+
--EXPECT--
14+
bool(true)

Zend/tests/assert/expect_007.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
test compiled reason
3+
--INI--
4+
zend.assertions=1
5+
assert.exception=1
6+
--FILE--
7+
<?php
8+
$next = 1;
9+
$data = array(
10+
"key" => "X-HTTP ",
11+
"value" => "testing"
12+
);
13+
14+
class HeaderMalfunctionException extends AssertionException {}
15+
16+
assert (preg_match("~^([a-zA-Z0-9-]+)$~", $data["key"]), new HeaderMalfunctionException("malformed key found at {$next} \"{$data["key"]}\""));
17+
?>
18+
--EXPECTF--
19+
Fatal error: Uncaught exception 'HeaderMalfunctionException' with message 'malformed key found at 1 "X-HTTP "' in %sexpect_007.php:10
20+
Stack trace:
21+
#0 {main}
22+
thrown in %sexpect_007.php on line 10

Zend/tests/assert/expect_008.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
test disabled expectations have no ill side effects
3+
--INI--
4+
zend.assertions=0
5+
assert.exception=1
6+
--FILE--
7+
<?php
8+
class One {
9+
public function __construct() {
10+
assert($this || 0);
11+
}
12+
}
13+
class Two extends One {}
14+
15+
class OdEar extends AssertionException {}
16+
17+
function blah(){ return 1; }
18+
19+
$variable = 1;
20+
assert(true, "constant message");
21+
assert(($variable && $variable) || php_sapi_name(), new OdEar("constant message"));
22+
assert(false);
23+
assert(blah(), blah());
24+
25+
new Two();
26+
new Two();
27+
new Two();
28+
29+
assert (blah() || blah() || blah(), blah() || blah() || blah() || blah());
30+
31+
var_dump(true);
32+
?>
33+
--EXPECT--
34+
bool(true)

Zend/tests/assert/expect_009.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
test stack trace is correct from failed exception in extended class
3+
--INI--
4+
zend.assertions=1
5+
assert.exception=1
6+
--FILE--
7+
<?php
8+
class One {
9+
public function __construct() {
10+
11+
}
12+
}
13+
class Two extends One {
14+
public function __construct() {
15+
assert(false);
16+
}
17+
}
18+
new Two();
19+
?>
20+
--EXPECTF--
21+
Fatal error: Uncaught exception 'AssertionException' with message 'assert(false)' in %sexpect_009.php:%d
22+
Stack trace:
23+
#0 %sexpect_009.php(%d): assert(false, 'assert(false)')
24+
#1 %sexpect_009.php(%d): Two->__construct()
25+
#2 {main}
26+
thrown in %sexpect_009.php on line %d

Zend/tests/assert/expect_010.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
test stack trace is correct from failed exception in extended class (parent implementing constructor)
3+
--INI--
4+
zend.assertions=1
5+
assert.exception=1
6+
--FILE--
7+
<?php
8+
class One {
9+
public function __construct() {
10+
assert(false);
11+
}
12+
}
13+
class Two extends One {}
14+
15+
new Two();
16+
?>
17+
--EXPECTF--
18+
Fatal error: Uncaught exception 'AssertionException' with message 'assert(false)' in %sexpect_010.php:%d
19+
Stack trace:
20+
#0 %sexpect_010.php(%d): assert(false, 'assert(false)')
21+
#1 %sexpect_010.php(%d): One->__construct()
22+
#2 {main}
23+
thrown in %sexpect_010.php on line %d

0 commit comments

Comments
 (0)