summaryrefslogtreecommitdiff
path: root/tests/output/stream_isatty.inc
blob: 4b7f39986f4af6de2ae304e99790abf37471cca9 (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
<?php

function testToStdOut()
{
    $sampleStreams = array(
        'STDIN (constant)'              => STDIN,
        'STDIN (fopen)'                 => fopen('php://stdin', 'rb'),
        'STDIN (php://fd/0)'            => fopen('php://fd/0', 'rb'),
        'STDOUT (constant)'             => STDOUT,
        'STDOUT (fopen)'                => fopen('php://stdout', 'wb'),
        'STDOUT (php://fd/1)'           => fopen('php://fd/1', 'wb'),
        'STDERR (constant)'             => STDERR,
        'STDERR (fopen)'                => fopen('php://stderr', 'wb'),
        'STDERR (php://fd/2)'           => fopen('php://fd/2', 'wb'),
        'Not a stream'                  => 'foo',
        'Invalid stream (php://temp)'   => fopen('php://temp', 'wb'),
        'Invalid stream (php://input)'  => fopen('php://input', 'wb'),
        'Invalid stream (php://memory)' => fopen('php://memory', 'wb'),
        'File stream'                   => $closeMe = fopen(__FILE__, 'rb'),
    );

    foreach ($sampleStreams as $name => $stream) {
        echo "$name: "; var_dump(stream_isatty($stream));
    }

    fclose($closeMe);
}

function testToStdErr()
{
    ob_start();
    testToStdOut();
    $result = ob_get_contents();
    ob_end_clean();
    fwrite(STDERR, $result);
}