Browse Source

[ADD] AspectMock to tests

tags/v1.8.2.4
Adam Bukowski 4 years ago
parent
commit
359c59174f
5 changed files with 581 additions and 136 deletions
  1. +2
    -1
      composer.json
  2. +517
    -134
      composer.lock
  3. +5
    -0
      tests/_fakeLoader/composer.json
  4. +6
    -0
      tests/_support/Helper/Unit.php
  5. +51
    -1
      tests/unit/_bootstrap.php

+ 2
- 1
composer.json View File

@@ -26,6 +26,7 @@
}
},
"require-dev": {
"codeception/codeception": "*"
"codeception/codeception": "*",
"codeception/aspect-mock": "*"
}
}

+ 517
- 134
composer.lock
File diff suppressed because it is too large
View File


+ 5
- 0
tests/_fakeLoader/composer.json View File

@@ -0,0 +1,5 @@
{
"autoload-dev": {
"classmap": ["../../"]
}
}

+ 6
- 0
tests/_support/Helper/Unit.php View File

@@ -4,6 +4,12 @@ namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I

use Codeception\TestInterface;

class Unit extends \Codeception\Module
{
function _after(TestInterface $test)
{
\AspectMock\Test::clean();
}
}

+ 51
- 1
tests/unit/_bootstrap.php View File

@@ -1,10 +1,60 @@
<?php

//---------------------------------------------------------------------
// SET DEFAULT EPESI CONSTANTS
//---------------------------------------------------------------------

define('DATA_DIR', 'data');
define('CID', false);
define('SET_SESSION', false);

include 'include.php';
//---------------------------------------------------------------------
// Load EPESI composer autoloader with classmap to fix
// class loading issue
//---------------------------------------------------------------------

$fakeLoader = __DIR__ . '/../_fakeLoader/vendor/autoload.php';
if (!file_exists($fakeLoader)) {
$fakeLoaderDir = realpath(dirname(dirname($fakeLoader)));
throw new Exception("Please initialize fake composer autoloader\nOpen $fakeLoaderDir and invoke `composer install`");
}
$loader = require_once $fakeLoader;
$composerLoader = new \Go\ParserReflection\Locator\ComposerLocator($loader);
$loader->unregister();

//---------------------------------------------------------------------
// Init AspectMock Kernel with cache directory
//---------------------------------------------------------------------

$kernel = \AspectMock\Kernel::getInstance();
$options = [
'debug' => true,
'includePaths' => [__DIR__ . '/../../include/', __DIR__ . '/../../modules/'],
'excludePaths' => [__DIR__]
];
$cacheDir = sys_get_temp_dir() . '/aspect_mock_cache' . dirname(dirname(__DIR__));
@mkdir($cacheDir, 0777, true);
if (file_exists($cacheDir)) {
$options['cacheDir'] = $cacheDir;
}
$kernel->init($options);

//---------------------------------------------------------------------
// Initialize custom class locator with created composerLoader
//---------------------------------------------------------------------

\Go\ParserReflection\ReflectionEngine::init(new \Go\ParserReflection\Locator\CallableLocator(
function ($className) use ($composerLoader) {
$className = ltrim($className, '\\');
return $composerLoader->locateClass($className);
}
));

//---------------------------------------------------------------------
// Load EPESI
//---------------------------------------------------------------------

$kernel->loadFile('include.php');

ModuleManager::load_modules();
Base_AclCommon::set_sa_user();


Loading…
Cancel
Save