<commit_before><?php

use PHPUnit\Framework\TestCase;

class SilerTest extends TestCase
{
    public function testGet()
    {
        $_GET = ['foo' => 'bar'];

        $this->assertEquals($_GET, get());
        $this->assertEquals('bar', get('foo'));
        $this->assertEquals('qux', get('baz', 'qux'));
        $this->assertNull(get('baz'));
    }

    public function testPost()
    {
        $_POST = ['foo' => 'bar'];

        $this->assertEquals($_POST, post());
        $this->assertEquals('bar', post('foo'));
        $this->assertEquals('qux', post('baz', 'qux'));
        $this->assertNull(post('baz'));
    }

    public function testInput()
    {
        $_REQUEST = ['foo' => 'bar'];

        $this->assertEquals($_REQUEST, input());
        $this->assertEquals('bar', input('foo'));
        $this->assertEquals('qux', input('baz', 'qux'));
        $this->assertNull(input('baz'));
    }

    public function testUrl()
    {
        $_SERVER['SCRIPT_NAME'] = '/foo/test.php';
        $this->assertEquals('/foo/bar', url('/bar'));
    }

    public function testPath()
    {
        $_SERVER['SCRIPT_NAME'] = '/foo/test.php';
        $_SERVER['REQUEST_URI'] = '/bar';

        $this->assertEquals('/bar', path());
    }

    public function testUri()
    {
        $_SERVER['HTTP_HOST'] = 'test:8000';
        $_SERVER['REQUEST_URI'] = '/foo';

        $this->assertEquals('http://test:8000/foo', uri());
    }

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage Path /foo
     */
    public function testStaticPath()
    {
        $_SERVER['SCRIPT_NAME'] = '';
        $_SERVER['REQUEST_URI'] = '/foo';

        static_path('/foo', function () {
            throw new Exception('Path /foo');
        });
    }

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage Path /foo/bar
     */
    public function testRegexpPath()
    {
        $_SERVER['SCRIPT_NAME'] = '';
        $_SERVER['REQUEST_URI'] = '/foo/bar';

        regexp_path('/^\/foo\/([a-z]+)$/', function ($params) {
            throw new Exception('Path /foo/'.$params[1]);
        });
    }

    public function testRequestMethodIs()
    {
        $_SERVER['REQUEST_METHOD'] = 'POST';
        $this->assertTrue(is_post());

        $_SERVER['REQUEST_METHOD'] = 'GET';
        $this->assertTrue(is_get());

        $_SERVER['REQUEST_METHOD'] = 'PUT';
        $this->assertTrue(is_put());

        $_SERVER['REQUEST_METHOD'] = 'DELETE';
        $this->assertTrue(is_delete());

        $_SERVER['REQUEST_METHOD'] = 'CUSTOM';
        $this->assertTrue(request_method_is('custom'));
    }

    public function testRequireFn()
    {
        $this->assertEquals('baz', require_fn(__DIR__.'/foo.php')(['bar' => 'baz']));
    }
}<commit_msg>Fix test for PHP 5.6<commit_after><?php

use PHPUnit\Framework\TestCase;

class SilerTest extends TestCase
{
    public function testGet()
    {
        $_GET = ['foo' => 'bar'];

        $this->assertEquals($_GET, get());
        $this->assertEquals('bar', get('foo'));
        $this->assertEquals('qux', get('baz', 'qux'));
        $this->assertNull(get('baz'));
    }

    public function testPost()
    {
        $_POST = ['foo' => 'bar'];

        $this->assertEquals($_POST, post());
        $this->assertEquals('bar', post('foo'));
        $this->assertEquals('qux', post('baz', 'qux'));
        $this->assertNull(post('baz'));
    }

    public function testInput()
    {
        $_REQUEST = ['foo' => 'bar'];

        $this->assertEquals($_REQUEST, input());
        $this->assertEquals('bar', input('foo'));
        $this->assertEquals('qux', input('baz', 'qux'));
        $this->assertNull(input('baz'));
    }

    public function testUrl()
    {
        $_SERVER['SCRIPT_NAME'] = '/foo/test.php';
        $this->assertEquals('/foo/bar', url('/bar'));
    }

    public function testPath()
    {
        $_SERVER['SCRIPT_NAME'] = '/foo/test.php';
        $_SERVER['REQUEST_URI'] = '/bar';

        $this->assertEquals('/bar', path());
    }

    public function testUri()
    {
        $_SERVER['HTTP_HOST'] = 'test:8000';
        $_SERVER['REQUEST_URI'] = '/foo';

        $this->assertEquals('http://test:8000/foo', uri());
    }

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage Path /foo
     */
    public function testStaticPath()
    {
        $_SERVER['SCRIPT_NAME'] = '';
        $_SERVER['REQUEST_URI'] = '/foo';

        static_path('/foo', function () {
            throw new Exception('Path /foo');
        });
    }

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage Path /foo/bar
     */
    public function testRegexpPath()
    {
        $_SERVER['SCRIPT_NAME'] = '';
        $_SERVER['REQUEST_URI'] = '/foo/bar';

        regexp_path('/^\/foo\/([a-z]+)$/', function ($params) {
            throw new Exception('Path /foo/'.$params[1]);
        });
    }

    public function testRequestMethodIs()
    {
        $_SERVER['REQUEST_METHOD'] = 'POST';
        $this->assertTrue(is_post());

        $_SERVER['REQUEST_METHOD'] = 'GET';
        $this->assertTrue(is_get());

        $_SERVER['REQUEST_METHOD'] = 'PUT';
        $this->assertTrue(is_put());

        $_SERVER['REQUEST_METHOD'] = 'DELETE';
        $this->assertTrue(is_delete());

        $_SERVER['REQUEST_METHOD'] = 'CUSTOM';
        $this->assertTrue(request_method_is('custom'));
    }

    public function testRequireFn()
    {
        $cb = require_fn(__DIR__.'/foo.php');
        $this->assertEquals('baz', $cb(['bar' => 'baz']));
    }
}
{'fraction_non_alphanumeric': 0.19960545193687232, 'fraction_numerical': 0.003586800573888092, 'mean_word_length': 2.4193746167995096, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1506546', 'n_tokens_mistral': 1709, 'n_tokens_neox': 1647, 'n_words': 272}