First Local Commit - After Clean up.

Signed-off-by: Rick Hays <rhays@haysgang.com>
This commit is contained in:
2019-12-02 14:54:38 -06:00
commit 10412ab7f6
486 changed files with 123242 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
<?php namespace CodeIgniter;
use CIUnitTestCase;
use Config\Services as ConfigServices;
/**
* Services class for testing.
*/
class Services
{
/**
* Mock objects for testing which are returned if exist.
*
* @var array
*/
static protected $mocks = [];
//--------------------------------------------------------------------
/**
* Reset shared instances and mocks for testing.
*/
public static function reset()
{
static::$mocks = [];
CIUnitTestCase::setPrivateProperty(ConfigServices::class, 'instances', []);
}
//--------------------------------------------------------------------
/**
* Inject mock object for testing.
*
* @param string $name
* @param $mock
*/
public static function injectMock(string $name, $mock)
{
$name = strtolower($name);
static::$mocks[$name] = $mock;
}
//--------------------------------------------------------------------
/**
* Returns a service
*
* @param string $name
* @param array $arguments
*/
public static function __callStatic(string $name, array $arguments)
{
$name = strtolower($name);
// Returns mock if exists
if (isset(static::$mocks[$name]))
{
return static::$mocks[$name];
}
if (method_exists(ConfigServices::class, $name))
{
return ConfigServices::$name(...$arguments);
}
}
//--------------------------------------------------------------------
}