Skip to content

Commit

Permalink
try to fix cache test
Browse files Browse the repository at this point in the history
  • Loading branch information
kingjia90 committed Mar 1, 2024
1 parent 2d8d815 commit a2ec772
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 55 deletions.
36 changes: 18 additions & 18 deletions .github/ci/files/bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,32 @@

ob_get_clean();

if (file_exists($a = getcwd() . '/vendor/autoload.php')) {
if (file_exists($a = getcwd() . '/vendor/autoload_runtime.php')) {
include $a;
} elseif (file_exists($a = __DIR__ . '/../../../../vendor/autoload.php')) {
} elseif (file_exists($a = __DIR__ . '/../../../../vendor/autoload_runtime.php')) {
include $a;
} elseif (file_exists($a = __DIR__ . '/../vendor/autoload.php')) {
} elseif (file_exists($a = __DIR__ . '/../vendor/autoload_runtime.php')) {
include $a;
} else {
fwrite(STDERR, 'Cannot locate autoloader; please run "composer install"' . PHP_EOL);
exit(1);
}

\Pimcore\Bootstrap::setProjectRoot();
return function (array $context) {
define('PIMCORE_CONSOLE', true);

define('PIMCORE_CONSOLE', true);
$input = new \Symfony\Component\Console\Input\ArgvInput();
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
}

if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}

$input = new \Symfony\Component\Console\Input\ArgvInput();
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
}

if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}

/** @var \Pimcore\Kernel $kernel */
$kernel = \Pimcore\Bootstrap::startupCli();
$application = new \Pimcore\Console\Application($kernel);
$application->run();
/** @var \Pimcore\Kernel $kernel */
$kernel = \Pimcore\Bootstrap::startupCli();
$application = new \Pimcore\Console\Application($kernel);
$application->run();
return $application;
};
29 changes: 15 additions & 14 deletions .github/ci/files/public/index_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,28 @@
use Pimcore\Tool;
use Symfony\Component\HttpFoundation\Request;

include __DIR__ . "/../vendor/autoload.php";
include __DIR__ . "/../vendor/autoload_runtime.php";

define('PIMCORE_PROJECT_ROOT', __DIR__ . '/..');
define('APP_ENV', 'test');
return function (array $context) {
define('PIMCORE_PROJECT_ROOT', __DIR__ . '/..');
define('APP_ENV', 'test');

\Pimcore\Bootstrap::setProjectRoot();
\Pimcore\Bootstrap::bootstrap();

$request = Request::createFromGlobals();
$request = Request::createFromGlobals();

// set current request as property on tool as there's no
// request stack available yet
Tool::setCurrentRequest($request);
Tool::setCurrentRequest($request);

/** @var \Pimcore\Kernel $kernel */
$kernel = \Pimcore\Bootstrap::kernel();
\Pimcore\Bootstrap::bootstrap();
/** @var \Pimcore\Kernel $kernel */
$kernel = \Pimcore\Bootstrap::kernel();

// reset current request - will be read from request stack from now on
Tool::setCurrentRequest(null);
Tool::setCurrentRequest(null);

$response = $kernel->handle($request);
$response->send();
$response = $kernel->handle($request);
$response->send();

$kernel->terminate($request, $response);
$kernel->terminate($request, $response);
return $kernel;
};
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"preferred-install": {
"pimcore/pimcore": "source",
"*": "dist"
},
"allow-plugins": {
"symfony/runtime": true
}
},
"prefer-stable": true,
Expand All @@ -26,7 +29,8 @@
"codeception/phpunit-wrapper": "^9",
"codeception/module-asserts": "^2",
"codeception/module-symfony": "^1.6.0 || ^3.1.0",
"symfony/dotenv": "^6.2 || ^5.4.21"
"symfony/dotenv": "^6.2 || ^5.4.21",
"symfony/runtime": "^6.4 || ^5.4"
},
"suggest": {
"pimcore/admin-ui-classic-bundle": "Required for Pimcore 11"
Expand Down
2 changes: 1 addition & 1 deletion tests/Service/OutputCacheServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ public function testIgnoreCacheWhenRequestParameterIsPassed()
$response = new JsonResponse(['data' => 123]);
$this->sut->method('loadFromCache')->willReturn($response);
$this->request->query->set('pimcore_nocache', 'true');
\Pimcore::inDebugMode(true);

// Act
$cacheItem = $this->sut->load($this->request);

// Assert
$this->assertEquals(true, \Pimcore::inDebugMode());
$this->assertEquals(null, $cacheItem);
}
}
46 changes: 25 additions & 21 deletions tests/_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
use Pimcore\Tests\Support\Util\Autoloader;


if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
include __DIR__ . '/../vendor/autoload.php';
if (file_exists(__DIR__ . '/../vendor/autoload_runtime.php')) {
include __DIR__ . '/../vendor/autoload_runtime.php';
$pimcoreTestDir = __DIR__ . '/../vendor/pimcore/pimcore/tests';
} elseif (file_exists(__DIR__ . '/../../../../vendor/autoload.php')) {
include __DIR__ . '/../../../../vendor/autoload.php';
} elseif (file_exists(__DIR__ . '/../../../../vendor/autoload_runtime.php')) {
include __DIR__ . '/../../../../vendor/autoload_runtime.php';
$pimcoreTestDir = __DIR__ . '/../../../../vendor/pimcore/pimcore/tests';
} elseif (getenv('PIMCORE_PROJECT_ROOT') != '' && file_exists(getenv('PIMCORE_PROJECT_ROOT') . '/vendor/autoload.php')) {
include getenv('PIMCORE_PROJECT_ROOT') . '/vendor/autoload.php';
} elseif (getenv('PIMCORE_PROJECT_ROOT') != '' && file_exists(getenv('PIMCORE_PROJECT_ROOT') . '/vendor/autoload_runtime.php')) {
include getenv('PIMCORE_PROJECT_ROOT') . '/vendor/autoload_runtime.php';
$pimcoreTestDir = getenv('PIMCORE_PROJECT_ROOT') . '/vendor/pimcore/pimcore/tests';
} elseif (getenv('PIMCORE_PROJECT_ROOT') != '') {
throw new \Exception('Invalid Pimcore project root "' . getenv('PIMCORE_PROJECT_ROOT') . '"');
Expand All @@ -27,24 +27,28 @@

include $pimcoreTestsSupportDir . '/Util/Autoloader.php';

\Pimcore\Bootstrap::setProjectRoot();
\Pimcore\Bootstrap::bootstrap();
return function (array $context) {

//error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING);
\Pimcore\Bootstrap::setProjectRoot();
\Pimcore\Bootstrap::bootstrap();

Autoloader::addNamespace('Pimcore\Tests', $pimcoreTestsSupportDir); //Pimcore 10 BC layer
Autoloader::addNamespace('Pimcore\Tests\Support', $pimcoreTestsSupportDir);
Autoloader::addNamespace('Pimcore\Model\DataObject', PIMCORE_CLASS_DIRECTORY . '/DataObject');
Autoloader::addNamespace('DataHubBundle\Tests', __DIR__);
Autoloader::addNamespace('DataHubBundle\Tests', __DIR__ . '/_support');
//error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING);

Autoloader::addNamespace('Pimcore\Tests', $pimcoreTestsSupportDir); //Pimcore 10 BC layer
Autoloader::addNamespace('Pimcore\Tests\Support', $pimcoreTestsSupportDir);
Autoloader::addNamespace('Pimcore\Model\DataObject', PIMCORE_CLASS_DIRECTORY . '/DataObject');
Autoloader::addNamespace('DataHubBundle\Tests', __DIR__);
Autoloader::addNamespace('DataHubBundle\Tests', __DIR__ . '/_support');

echo __DIR__ . '/_support';

if (!defined('TESTS_PATH')) {
define('TESTS_PATH', __DIR__);
}
echo __DIR__ . '/_support';

if (!defined('PIMCORE_TEST')) {
define('PIMCORE_TEST', true);
}
if (!defined('TESTS_PATH')) {
define('TESTS_PATH', __DIR__);
}

if (!defined('PIMCORE_TEST')) {
define('PIMCORE_TEST', true);
}

};

0 comments on commit a2ec772

Please sign in to comment.