Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Jul 18, 2024
1 parent 94e105c commit f5d4cc6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 43 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
matrix:
php: [ 8.1, 8.2, 8.3 ]
pimcore: [ ^11.2, ^11.3 ]
pimcore: [ ^11.1, ^11.2, ^11.3 ]
dependencies: [ highest ]
exclude:
- php: 8.1
Expand Down Expand Up @@ -56,6 +56,8 @@ jobs:

- name: Setup DB
run: |
apt-get update
apt-get install mysql-client locales-all -y
mysql --host 127.0.0.1 --port ${{ job.services.database.ports['3306'] }} -uroot -proot -e "CREATE DATABASE coreshop_test CHARSET=utf8mb4;"
- name: Get composer cache directory
Expand All @@ -72,13 +74,13 @@ jobs:
- if: matrix.dependencies == 'highest'
name: Install dependencies highest
run: |
composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update
composer req pimcore/pimcore:${{ matrix.pimcore }} coreshop/pimcore:4.0.x-dev --no-interaction --no-scripts --no-update
composer update --no-progress --prefer-dist --optimize-autoloader
- if: matrix.dependencies == 'lowest'
name: Install dependencies lowest
run: |
composer req pimcore/pimcore:${{ matrix.pimcore }} --no-interaction --no-scripts --no-update
composer req pimcore/pimcore:${{ matrix.pimcore }} coreshop/pimcore:4.0.x-dev --no-interaction --no-scripts --no-update
composer update --no-progress --prefer-dist --optimize-autoloader --prefer-lowest
- name: Cache clear
Expand All @@ -88,7 +90,7 @@ jobs:
run: bin/console assets:install --symlink

- name: Install Pimcore
run: PIMCORE_KERNEL_CLASS=Kernel vendor/bin/pimcore-install --env=test --skip-database-config
run: PIMCORE_KERNEL_CLASS=Kernel vendor/bin/pimcore-install --env=test --skip-database-config --no-interaction

- name: Install DataDefinitions
run: bin/console pimcore:bundle:install DataDefinitionsBundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function setKernel(): void
/**
* @BeforeScenario
*/
public function purgeObjects()
public function purgeObjects(): void
{
Cache::clearAll();
Cache\RuntimeCache::clear();
Expand All @@ -62,16 +62,16 @@ public function purgeObjects()
foreach ($list->getObjects() as $obj) {
$obj->delete();
}

//Force
$this->connection->executeQuery('DELETE FROM objects WHERE id <> 1');
}

/**
* @BeforeScenario
*/
public function purgeAssets()
public function purgeAssets(): void
{
Cache::clearAll();
Cache\RuntimeCache::clear();

/**
* @var Asset\Listing $list
*/
Expand All @@ -95,17 +95,20 @@ public function purgeIMLog()
/**
* @BeforeScenario
*/
public function purgeBricks()
public function purgeBricks(): void
{
$list = new Objectbrick\Definition\Listing();
$list->load();

foreach ($list->load() as $brick) {
/**
* @psalm-suppress DocblockTypeContradiction
*/
if (!$brick instanceof Objectbrick\Definition) {
continue;
}

if (strpos($brick->getKey(), 'Behat') === 0) {
if (str_starts_with($brick->getKey(), 'Behat')) {
$brick->delete();
}
}
Expand All @@ -123,15 +126,15 @@ public function clearRuntimeCacheScenario()
/**
* @BeforeStep
*/
public function clearRuntimeCacheStep()
public function clearRuntimeCacheStep(): void
{
//We should not clear Pimcore Objects here, otherwise we lose the reference to it
//and end up having the same object twice
$copy = \Pimcore\Cache\RuntimeCache::getInstance()->getArrayCopy();
$keepItems = [];

foreach ($copy as $key => $value) {
if (strpos($key, 'object_') === 0) {
if (str_starts_with($key, 'object_')) {
$keepItems[] = $key;
}
}
Expand All @@ -142,13 +145,16 @@ public function clearRuntimeCacheStep()
/**
* @BeforeScenario
*/
public function purgeClasses()
public function purgeClasses(): void
{
$list = new ClassDefinition\Listing();
$list->setCondition('name LIKE ?', ['Behat%']);
$list->load();

foreach ($list->getClasses() as $class) {
/**
* @psalm-suppress DocblockTypeContradiction
*/
if (!$class instanceof ClassDefinition) {
continue;
}
Expand All @@ -160,17 +166,20 @@ public function purgeClasses()
/**
* @BeforeScenario
*/
public function purgeFieldCollections()
public function purgeFieldCollections(): void
{
$list = new Fieldcollection\Definition\Listing();
$list->load();

foreach ($list->load() as $collection) {
/**
* @psalm-suppress DocblockTypeContradiction
*/
if (!$collection instanceof Fieldcollection\Definition) {
continue;
}

if (strpos($collection->getKey(), 'Behat') === 0) {
if (str_starts_with($collection->getKey(), 'Behat')) {
$collection->delete();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class PimcoreSetupContext implements Context
/**
* @BeforeSuite
*/
public static function setupPimcore()
public static function setupPimcore(): void
{
if (getenv('IM_SKIP_DB_SETUP')) {
return;
Expand All @@ -36,12 +36,15 @@ public static function setupPimcore()

$connection = \Pimcore::getContainer()->get('database_connection');

if (null === $connection) {
throw new \Exception('Database connection not found');
}

$dbName = $connection->getParams()['dbname'];
$params = $connection->getParams();
$config = $connection->getConfiguration();

unset($params['url']);
unset($params['dbname']);
unset($params['url'], $params['dbname']);

// use a dedicated setup connection as the framework connection is bound to the DB and will
// fail if the DB doesn't exist
Expand All @@ -55,34 +58,20 @@ public static function setupPimcore()

$schemaManager->createDatabase($connection->quoteIdentifier($dbName));


if (!$connection->isConnected()) {
$connection->connect();
}

//Prior 5.5
if (@class_exists('\Pimcore\Model\Tool\Setup')) {
$setup = new \Pimcore\Model\Tool\Setup();
$setup->database();

$setup->contents(
[
'username' => 'admin',
'password' => microtime(),
]
);
}
else {
$installer = new \Pimcore\Bundle\InstallBundle\Installer(
\Pimcore::getContainer()->get('monolog.logger.pimcore'),
\Pimcore::getContainer()->get('event_dispatcher')
);

$installer->setupDatabase([
'username' => 'admin',
'password' => microtime(),
]);
}
$installer = new \Pimcore\Bundle\InstallBundle\Installer(
\Pimcore::getContainer()->get('monolog.logger.pimcore'),
\Pimcore::getContainer()->get('event_dispatcher'),
);

$installer->setupDatabase($connection, [
'username' => 'admin',
'password' => 'coreshop',
]);


static::$pimcoreSetupDone = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function createClassNamed($className): void
$name = $this->classStorage->set($className);

$classDefinition = new ClassDefinition();
$classDefinition->setId($name);
$classDefinition->setName($name);
$classDefinition->setLayoutDefinitions(
json_decode(''),
Expand Down

0 comments on commit f5d4cc6

Please sign in to comment.