1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

100% test coverage for \e107\Shims

New test forces a failover of the `readfile()` internal function to
test the failover functionality of \e107\Shims\Internal::readfile()
This commit is contained in:
Nick Liu
2018-11-03 09:11:42 -05:00
parent 7c2b4f8f25
commit 9e0d603609
3 changed files with 37 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
<?php <?php
Codeception\Util\Autoload::addNamespace('', codecept_root_dir().'/tests/unit');
define('PARAMS_GENERATOR', realpath(codecept_root_dir()."/lib/config.php")); define('PARAMS_GENERATOR', realpath(codecept_root_dir()."/lib/config.php"));

View File

@@ -0,0 +1,31 @@
<?php
/**
* e107 website system
*
* Copyright (C) 2008-2018 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*/
namespace e107\Shims;
function readfile($filename, $use_include_path = FALSE, $context = NULL)
{
foreach(debug_backtrace(false) as $line)
{
if ($line['class'] == InternalAlternateTest::class)
{
return null;
}
}
return @\readfile($filename, $use_include_path, $context);
}
class InternalAlternateTest extends eShimsTest
{
public function testReadfile()
{
$this->testReadfileImplementation(array(InternalShims::class, 'readfile'));
}
}

View File

@@ -8,19 +8,21 @@
* *
*/ */
namespace e107\Shims;
class eShimsTest extends \Codeception\Test\Unit class eShimsTest extends \Codeception\Test\Unit
{ {
public function testReadfile() public function testReadfile()
{ {
$this->testReadfileImplementation(array(eShims::class, 'readfile')); $this->testReadfileImplementation(array(\eShims::class, 'readfile'));
} }
public function testReadfileAlt() public function testReadfileAlt()
{ {
$this->testReadfileImplementation(array(eShims::class, 'readfile_alt')); $this->testReadfileImplementation(array(\eShims::class, 'readfile_alt'));
} }
private function testReadfileImplementation($implementation) protected function testReadfileImplementation($implementation)
{ {
$tmp_handle = tmpfile(); $tmp_handle = tmpfile();
$tmp_filename = stream_get_meta_data($tmp_handle)['uri']; $tmp_filename = stream_get_meta_data($tmp_handle)['uri'];