summaryrefslogtreecommitdiff
path: root/ext/standard/tests/file/004.phpt
blob: 742457c7aa22bca0abc6bba2f8c5792bba51eb8c (plain)
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
--TEST--
file_put_contents() test
--FILE--
<?php
    chdir(__DIR__);
    for ($i = 1; $i < 6; $i++) {
        @unlink("./TEST{$i}");
    }

    echo "String Test: ";
    echo file_put_contents("TEST1", file_get_contents(__FILE__)) !== FALSE ? 'OK' : 'FAIL';
    echo "\n";

    $old_int = $int = rand();
    $ret = file_put_contents("TEST2", $int);
    echo "Integer Test: ";
    if ($int === $old_int && $ret !== FALSE && md5($int) == md5_file("TEST2")) {
        echo 'OK';
    } else {
        echo 'FAIL';
    }
    echo "\n";

    $old_int = $int = time() / 1000;
    $ret = file_put_contents("TEST3", $int);
    echo "Float Test: ";
    if ($int === $old_int && $ret !== FALSE && md5($int) == md5_file("TEST3")) {
        echo 'OK';
    } else {
        echo 'FAIL';
    }
    echo "\n";

    $ret = file_put_contents("TEST4", __FILE__);
    echo "Bool Test: ";
    if ($ret !== FALSE && md5(__FILE__) == md5_file("TEST4")) {
        echo 'OK';
    } else {
        echo 'FAIL';
    }
    echo "\n";

    $ret = @file_put_contents("TEST5", $_SERVER);
    echo "Array Test: ";
    if ($ret !== FALSE && @md5(implode('', $_SERVER)) == md5_file("TEST5")) {
        echo 'OK';
    } else {
        echo 'FAIL';
    }
    echo "\n";

    for ($i = 1; $i < 6; $i++) {
        @unlink("./TEST{$i}");
    }
?>
--EXPECT--
String Test: OK
Integer Test: OK
Float Test: OK
Bool Test: OK
Array Test: OK