File: chunk_split_variation5.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (66 lines) | stat: -rw-r--r-- 2,091 bytes parent folder | download | duplicates (3)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
--TEST--
Test chunk_split() function : usage variations - different integer values for 'chunklen' argument(Bug#42796)
--SKIPIF--
<?php
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
?>
--FILE--
<?php
/*
* passsing different integer values for 'chunklen' argument to chunk_split()
* 'ending' is set to '||'
*/

echo "*** Testing chunk_split() : different integer values for 'chunklen' ***\n";

 //Initializing variables
$ending = "||";
$str = "This contains\tand special char & numbers 123.\nIt also checks for \0 char";

// different values for chunklen
$values = array (
  0,
  1,
  -123,  //negative integer
  0234,  //octal number
  0x1A,  //hexadecimal number
  PHP_INT_MAX,  //max positive integer number
  PHP_INT_MAX * 3,  //integer overflow
  -PHP_INT_MAX - 1,  //min negative integer

);

for($count = 0; $count < count($values); $count++) {
  echo "-- Iteration $count --\n";
  try {
    var_dump( chunk_split($str, $values[$count], $ending) );
  } catch (TypeError $e) {
    echo $e->getMessage(), "\n";
  } catch (\ValueError $e) {
      echo $e->getMessage() . "\n";
  }
}

?>
--EXPECTF--
*** Testing chunk_split() : different integer values for 'chunklen' ***
-- Iteration 0 --
chunk_split(): Argument #2 ($length) must be greater than 0
-- Iteration 1 --
string(213) "T||h||i||s|| ||c||o||n||t||a||i||n||s||	||a||n||d|| ||s||p||e||c||i||a||l|| ||c||h||a||r|| ||&|| ||n||u||m||b||e||r||s|| ||1||2||3||.||
||I||t|| ||a||l||s||o|| ||c||h||e||c||k||s|| ||f||o||r|| ||%0|| ||c||h||a||r||"
-- Iteration 2 --
chunk_split(): Argument #2 ($length) must be greater than 0
-- Iteration 3 --
string(73) "This contains	and special char & numbers 123.
It also checks for %0 char||"
-- Iteration 4 --
string(77) "This contains	and special ||char & numbers 123.
It als||o checks for %0 char||"
-- Iteration 5 --
string(73) "This contains	and special char & numbers 123.
It also checks for %0 char||"
-- Iteration 6 --
chunk_split(): Argument #2 ($length) must be of type int, float given
-- Iteration 7 --
chunk_split(): Argument #2 ($length) must be greater than 0