Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
See: #1961, #1970
  • Loading branch information
sergeyklay committed Oct 19, 2019
1 parent ffd1afb commit df6455c
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 14 deletions.
34 changes: 20 additions & 14 deletions test/globals/server.zep
@@ -1,21 +1,27 @@

namespace Test\Globals;

class Server
{
public function f1() -> void
{
echo _SERVER["PHP_SELF"];
this->f2();
echo _SERVER["PHP_SELF"];
}
/**
* @see https://github.com/phalcon/zephir/issues/1961
*/
public function f1() -> void
{
echo _SERVER["PHP_SELF"];
this->f2();
echo _SERVER["PHP_SELF"];
}

public function f2() -> void
{
echo _SERVER["SCRIPT_NAME"];
}
public function f2() -> void
{
echo _SERVER["SCRIPT_NAME"];
}

public function check() {
return _SERVER["HTTP_USER_AGENT"];
}
/**
* @see https://github.com/phalcon/zephir/issues/1970
*/
public function check() -> var
{
return _SERVER["HTTP_USER_AGENT"];
}
}
64 changes: 64 additions & 0 deletions unit-tests/Extension/Globals/ServerTest.php
@@ -0,0 +1,64 @@
<?php

/*
* This file is part of the Zephir.
*
* (c) Zephir Team <team@zephir-lang.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Extension\Globals;

use PHPUnit\Framework\TestCase;
use Test\Globals\Server;

class ServerTest extends TestCase
{
private $server;

/**
* This method is called before each test.
*/
protected function setUp()
{
$this->server = $_SERVER;
}

/**
* This method is called after each test.
*/
protected function tearDown()
{
$_SERVER = $this->server;
}

/**
* @test
* @see https://github.com/phalcon/zephir/issues/1961
*/
public function shouldPrintPhpSelf()
{
$test = new Server();

ob_start();
$test->f1();
$actual = ob_get_contents();
ob_end_clean();

$this->assertSame(str_repeat($_SERVER['PHP_SELF'], 3), $actual);
}

/**
* @test
* @see https://github.com/phalcon/zephir/issues/1961
*/
public function shouldPrintUserAgent()
{
$test = new Server();
$_SERVER['HTTP_USER_AGENT'] = 'Test';

$this->assertSame('Test', $test->check());
}
}

0 comments on commit df6455c

Please sign in to comment.