mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Merge pull request #29 from kenjis/move-mocks
Move mock classes to _support
This commit is contained in:
commit
eac6a0ce34
24
tests/_support/Autoloader/MockAutoloader.php
Normal file
24
tests/_support/Autoloader/MockAutoloader.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php namespace CodeIgniter\Autoloader;
|
||||
|
||||
class MockAutoloader extends Autoloader
|
||||
{
|
||||
|
||||
protected $files = [];
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function setFiles($files)
|
||||
{
|
||||
$this->files = $files;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
protected function requireFile($file)
|
||||
{
|
||||
return in_array($file, $this->files) ? $file : false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
}
|
37
tests/_support/HTTP/MockCURLRequest.php
Normal file
37
tests/_support/HTTP/MockCURLRequest.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php namespace CodeIgniter\HTTP;
|
||||
|
||||
/**
|
||||
* Class MockCURLRequest
|
||||
*
|
||||
* Simply allows us to not actually call cURL during the
|
||||
* test runs. Instead, we can set the desired output
|
||||
* and get back the set options.
|
||||
*/
|
||||
class MockCURLRequest extends CURLRequest
|
||||
{
|
||||
public $curl_options;
|
||||
|
||||
protected $output = '';
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function setOutput($output)
|
||||
{
|
||||
$this->output = $output;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
protected function sendRequest(array $curl_options = []): string
|
||||
{
|
||||
// Save so we can access later.
|
||||
$this->curl_options = $curl_options;
|
||||
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
}
|
16
tests/_support/Security/MockSecurity.php
Normal file
16
tests/_support/Security/MockSecurity.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php namespace CodeIgniter\Security;
|
||||
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
|
||||
class MockSecurity extends Security
|
||||
{
|
||||
public function CSRFSetCookie(RequestInterface $request)
|
||||
{
|
||||
$_COOKIE['csrf_cookie_name'] = $this->CSRFHash;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
}
|
@ -1,29 +1,5 @@
|
||||
<?php namespace CodeIgniter\Autoloader;
|
||||
|
||||
class MockAutoloaderClass extends Autoloader
|
||||
{
|
||||
|
||||
protected $files = [];
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function setFiles($files)
|
||||
{
|
||||
$this->files = $files;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
protected function requireFile($file)
|
||||
{
|
||||
return in_array($file, $this->files) ? $file : false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
}
|
||||
|
||||
use Config\Autoload;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@ -48,7 +24,7 @@ class AutoloaderTest extends \CIUnitTestCase
|
||||
'App\Libraries' => '/application/somewhere',
|
||||
];
|
||||
|
||||
$this->loader = new MockAutoloaderClass();
|
||||
$this->loader = new MockAutoloader();
|
||||
$this->loader->initialize($config);
|
||||
|
||||
$this->loader->setFiles([
|
||||
|
@ -2,45 +2,6 @@
|
||||
|
||||
use Config\App;
|
||||
|
||||
/**
|
||||
* Class MockCURLRequest
|
||||
*
|
||||
* Simply allows us to not actually call cURL during the
|
||||
* test runs. Instead, we can set the desired output
|
||||
* and get back the set options.
|
||||
*/
|
||||
class MockCURLRequest extends CURLRequest
|
||||
{
|
||||
public $curl_options;
|
||||
|
||||
protected $output = '';
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function setOutput($output)
|
||||
{
|
||||
$this->output = $output;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
protected function sendRequest(array $curl_options = []): string
|
||||
{
|
||||
// Save so we can access later.
|
||||
$this->curl_options = $curl_options;
|
||||
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
class CURLRequestTest extends \CIUnitTestCase
|
||||
{
|
||||
protected $request;
|
||||
|
@ -1,19 +1,5 @@
|
||||
<?php namespace CodeIgniter\Security;
|
||||
|
||||
class MockSecurity extends Security
|
||||
{
|
||||
public function CSRFSetCookie(\CodeIgniter\HTTP\RequestInterface $request)
|
||||
{
|
||||
$_COOKIE['csrf_cookie_name'] = $this->CSRFHash;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
}
|
||||
|
||||
use Config\MockAppConfig;
|
||||
use CodeIgniter\HTTP\IncomingRequest;
|
||||
use CodeIgniter\HTTP\Request;
|
||||
|
Loading…
x
Reference in New Issue
Block a user