Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
POSTGRES_PASSWORD: 'bedita'
POSTGRES_DB: 'bedita'
ports:
- '3306:3306'
- '5432:5432'
options: '${{ fromJson(matrix.db).options }}'

Expand Down
5 changes: 4 additions & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@
'skipLog' => ['Cake\Network\Exception\NotFoundException', 'BEdita\API\Exception\ExpiredTokenException'],
'log' => true,
'trace' => true,
'ignoredDeprecationPaths' => ['vendor/cakephp/cakephp/src/Log/Engine/FileLog.php'],
'ignoredDeprecationPaths' => [
'vendor/cakephp/cakephp/src/Log/Engine/FileLog.php',
'vendor/cakephp/migrations/src/Db/Table/ForeignKey.php',
],
],

/*
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ parameters:
- tests
excludePaths:
- src/Console/Installer.php
- tests/Fixture
13 changes: 7 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@
bootstrap="./tests/bootstrap.php"
cacheDirectory=".phpunit.cache"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd"
displayDetailsOnTestsThatTriggerDeprecations="false"
displayDetailsOnTestsThatTriggerErrors="false"
displayDetailsOnTestsThatTriggerNotices="false"
displayDetailsOnTestsThatTriggerWarnings="false"
displayDetailsOnPhpunitDeprecations="false"
>
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
<const name="UNIT_TEST_RUN" value="1"/>
</php>

<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="BEdita Api Template Test Suite">
<testsuite name="MyApp">
<directory>./tests/TestCase/</directory>
</testsuite>
<!-- Add plugin test suites here. -->
</testsuites>

<!-- Load extension for fixtures -->
<extensions>
<bootstrap class="Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/>
</extensions>

<!-- Ignore vendor tests in code coverage reports -->
<source>
<include>
Expand Down
26 changes: 26 additions & 0 deletions tests/Fixture/ApplicationsFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);

namespace MyApp\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

/**
* ApplicationsFixture
*/
class ApplicationsFixture extends TestFixture
{
/**
* @inheritDoc
*/
public array $records = [
[
'api_key' => API_KEY,
'client_secret' => null,
'name' => 'my_webapp',
'created' => '2026-01-29 07:10:57',
'modified' => '2026-01-29 07:10:57',
'enabled' => 1,
],
];
}
73 changes: 73 additions & 0 deletions tests/Fixture/ObjectTypesFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
declare(strict_types=1);

namespace MyApp\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

/**
* Fixture for `object_types` table.
*/
class ObjectTypesFixture extends TestFixture
{
/**
* @inheritDoc
*/
public array $records = [
// 1
[
'singular' => 'object',
'name' => 'objects',
'is_abstract' => true,
'parent_id' => null,
'tree_left' => 1,
'tree_right' => 24,
'description' => null,
'plugin' => 'BEdita/Core',
'model' => 'Objects',
'created' => '2025-11-10 09:27:23',
'modified' => '2025-11-10 09:27:23',
'enabled' => true,
'core_type' => true,
'translation_rules' => null,
'is_translatable' => false,
],
// 2
[
'singular' => 'user',
'name' => 'users',
'is_abstract' => false,
'parent_id' => 1,
'tree_left' => 6,
'tree_right' => 7,
'description' => null,
'plugin' => 'BEdita/Core',
'model' => 'Users',
'created' => '2025-11-10 09:27:23',
'modified' => '2025-11-10 09:27:23',
'enabled' => true,
'core_type' => true,
'translation_rules' => null,
'is_translatable' => false,
],
// 3
[
'singular' => 'profile',
'name' => 'profiles',
'is_abstract' => false,
'parent_id' => 1,
'tree_left' => 4,
'tree_right' => 5,
'description' => null,
'associations' => ['Tags'],
'plugin' => 'BEdita/Core',
'model' => 'Profiles',
'created' => '2025-11-10 09:27:23',
'modified' => '2025-11-10 09:27:23',
'enabled' => true,
'core_type' => true,
'translation_rules' => null,
'is_translatable' => false,
],
];
}
76 changes: 76 additions & 0 deletions tests/Fixture/ObjectsFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);

namespace MyApp\Test\Fixture;

use Cake\Database\Driver\Postgres;
use Cake\Datasource\ConnectionManager;
use Cake\TestSuite\Fixture\TestFixture;

/**
* ObjectsFixture
*/
class ObjectsFixture extends TestFixture
{
/**
* @inheritDoc
*/
public array $records = [
// 1
[
'object_type_id' => 2,
'status' => 'on',
'uname' => 'gustavo-admin',
'locked' => 1,
'deleted' => 0,
'created' => '2026-01-29 07:09:23',
'modified' => '2026-01-29 07:09:23',
'title' => 'Gustavo Admin',
'lang' => 'it',
'created_by' => 1,
'modified_by' => 1,
],
];

/**
* @inheritDoc
*/
public function init(): void
{
parent::init();

// remove `objects_createdby_fk` and `objects_modifiedby_fk` constraints
// to avoid PostgreSQL error inserting first user that references itself.
// CakePHP inserting fixture disables constraints but
// when the constraints are enabled again PostgreSQL give an SQL error.
$connection = ConnectionManager::get($this->connection());
if (!$connection->getDriver() instanceof Postgres) {
return;
}

$constraints = $this->_schema->constraints();
$removeConstraints = ['objects_createdby_fk', 'objects_modifiedby_fk'];
if (empty(array_intersect($constraints, $removeConstraints))) {
return;
}

$restoreConstraints = [];
foreach ($this->_schema->constraints() as $name) {
if (in_array($name, $removeConstraints)) {
continue;
}

$restoreConstraints[$name] = $this->_schema->getConstraint($name);
$this->_schema->dropConstraint($name);
}

$dropConstraintSql = $this->_schema->dropConstraintSql($connection);
foreach ($dropConstraintSql as $sql) {
$connection->execute($sql);
}

foreach ($restoreConstraints as $name => $attrs) {
$this->_schema->addConstraint($name, $attrs);
}
}
}
24 changes: 24 additions & 0 deletions tests/Fixture/ProfilesFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);

namespace MyApp\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

/**
* Fixture for `profiles` table.
*/
class ProfilesFixture extends TestFixture
{
/**
* @inheritDoc
*/
public array $records = [
[
'id' => 1,
'name' => 'Gustavo',
'surname' => 'Admin',
'email' => 'gustavo-admin@example.com',
],
];
}
18 changes: 18 additions & 0 deletions tests/Fixture/PropertiesFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace MyApp\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

/**
* Fixture for `properties` table.
*/
class PropertiesFixture extends TestFixture
{
/**
* @inheritDoc
*/
public array $records = [
];
}
Loading
Loading