It does two types of "mocking":
a) The first type simulates behavior of WordPress (TRUE_HOOKS). With this type you can call add_filter and apply_filters
and the registered filter will be actually executed.
b) The second type uses WP_MOCK. You can use all features of WP_MOCK if you choose it. The problem is,
WP_MOCK does not execute the registered hooks; therefore, we introduced this thin wrapper.
Usage:
Just call HookMock::setUp with desired type of mocking in the setUp method of your test case
and HookMock::tearDown in the tearDown method.
Note:
For now, this class supports only filters.
public static function assertFilesEqualDatabase() { HookMock::setUp(HookMock::TRUE_HOOKS); self::staticInitialization(); $entityNames = self::$schemaInfo->getAllEntityNames(); foreach ($entityNames as $entityName) { self::assertEntitiesEqualDatabase($entityName); } self::clearGlobalVariables(); HookMock::tearDown(); }
use Composer\Autoload\ClassLoader; use VersionPress\Storages\Mirror; use VersionPress\Storages\StorageFactory; use VersionPress\Tests\Utils\HookMock; $opts = ['from:', 'to:']; $args = getopt('', $opts); if (count($args) < count($opts)) { die("Please specify all arguments\n"); } require_once __DIR__ . '/../../vendor/autoload.php'; \Tracy\Debugger::enable(\Tracy\Debugger::DEVELOPMENT, __DIR__); $classloader = new ClassLoader(); $classloader->addPsr4('VersionPress\\', __DIR__ . '/../../src'); $classloader->register(); HookMock::setUp(HookMock::TRUE_HOOKS); // @codingStandardsIgnoreLine class FooChangeInfo extends \VersionPress\ChangeInfos\TrackedChangeInfo { private $files; public function __construct($files) { $this->files = $files; } public function getChangeDescription() { return join("\n", $this->files); } public function getScope() { return "file";
protected function setUp() { $this->root = vfsStream::setup(); HookMock::setUp(); }
protected function setUp() { HookMock::setUp(); }
public static function tearDownAfterClass() { HookMock::tearDown(); }
protected function tearDown() { HookMock::tearDown(); }