PHP code example of hampel / xenforo-test-framework
1. Go to this page and download the library: Download hampel/xenforo-test-framework library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// start by ensuring we are running the minimum ion, '5.6.0', '<'))
{
die("PHP 5.6.0 or newer is R__;
// this is where we load in the main XenForo framework, but we aren't executing it yet
whether we've got an API call
if (\XF::requestUrlMatchesApi())
{
\XF::runApp('XF\Api\App');
}
else // ... or a regular web call
{
\XF::runApp('XF\Pub\App');
}
// start by ensuring we are running the minimum ion, '5.6.0', '<'))
{
die("PHP 5.6.0 or newer is _;
// this is where we load in the main XenForo framework, but we aren't executing it yet
s is the important bit. Rather than "running" our application - we instead instantiate a CLI runner (based on
// Symfony's Console Component) and have that work our what command we're asking for and executing that for us.
$runner = new \XF\Cli\Runner();
$runner->run();
namespace Tests;
use Hampel\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
/**
* @var string $rootDir path to your XenForo root directory, relative to the addon path
*
* Set $rootDir to '../../../..' if you use a vendor in your addon id (ie <Vendor/AddonId>)
* Otherwise, set this to '../../..' for no vendor
*
* No trailing slash!
*/
protected $rootDir = '../../../..';
/**
* @var array $addonsToLoad an array of XenForo addon ids to load
*
* Specifying an array of addon ids will cause only those addons to be loaded - useful for isolating your addon for
* testing purposes
*
* Leave empty to load all addons
*/
protected $addonsToLoad = [];
/**
* Helper function to load mock data from a file (eg json)
* To use, create a "mock" folder relative to the tests folder, eg:
* 'src/addons/MyVendor/MyAddon/tests/mock'
*
* @param $file
*
* @return false|string
*/
protected function getMockData($file)
{
return file_get_contents(__DIR__ . '/mock/' . $file);
}
}
namespace Tests;
trait CreatesApplication
{
/**
* Creates the application.
*
* @return \XF\App
*/
public function createApplication()
{
protected function fakesMail()
{
$this->swap('mailer.transport', function (Container $c) {
return new Transport(
\Swift_DependencyContainer::getInstance()->lookup('transport.eventdispatcher')
);
});
$this->swap('mailer.queue', function(Container $c)
{
return new Queue($c['db']);
});
}
$this->mock('request', XF\Http\Request::class, function ($mock) {
$mock->expects()->getIp(true)->once()->andReturns('10.0.0.1');
});
namespace XF\Cron;
/**
* Cron entry for cleaning up bans.
*/
class Ban
{
/**
* Deletes expired bans.
*/
public static function deleteExpiredBans()
{
\XF::app()->repository('XF:Banning')->deleteExpiredUserBans();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.