Skip to content

Commit

Permalink
Basic test and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hexplor committed Feb 25, 2025
1 parent 5fbc889 commit e295374
Show file tree
Hide file tree
Showing 14 changed files with 113,371 additions and 0 deletions.
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":{"Gantry\\Tests\\PHP83\\Component\\TwigTest::testTwigFilters":4,"Gantry\\Tests\\PHP83\\Component\\TwigTest::testTwigFunctions":4,"Gantry\\Tests\\PHP83\\Framework\\GantryTest::testGantryContainer":4,"Gantry\\Tests\\PHP83\\Platform\\PlatformTest::testJoomlaPlatform":1,"Gantry\\Tests\\PHP83\\Platform\\PlatformTest::testWordPressPlatform":1,"Gantry\\Tests\\PHP83\\Framework\\GantryTest::testGantryInstance":4,"Gantry\\Tests\\PHP83\\Framework\\GantryTest::testGantryDebug":4},"times":{"Gantry\\Tests\\PHP83\\Component\\Layout\\LayoutTest::testLayoutInitialization":0,"Gantry\\Tests\\PHP83\\Component\\Layout\\LayoutTest::testLayoutPresets":0,"Gantry\\Tests\\PHP83\\Component\\Layout\\LayoutTest::testLayoutRendering":0,"Gantry\\Tests\\PHP83\\PHP83TypesTest::testNullableAndUnionTypes":0,"Gantry\\Tests\\PHP83\\PHP83TypesTest::testTraitCompatibility":0,"Gantry\\Tests\\PHP83\\Component\\TwigTest::testTwigExtensionInstantiation":0,"Gantry\\Tests\\PHP83\\Component\\TwigTest::testTwigFilters":0,"Gantry\\Tests\\PHP83\\Component\\TwigTest::testTwigFunctions":0,"Gantry\\Tests\\PHP83\\Framework\\GantryTest::testGantryInstance":0,"Gantry\\Tests\\PHP83\\Framework\\GantryTest::testGantryContainer":0,"Gantry\\Tests\\PHP83\\Framework\\GantryTest::testGantryDebug":0,"Gantry\\Tests\\PHP83\\Platform\\PlatformTest::testPlatformDetection":0,"Gantry\\Tests\\PHP83\\Platform\\PlatformTest::testJoomlaPlatform":0,"Gantry\\Tests\\PHP83\\Platform\\PlatformTest::testWordPressPlatform":0}}
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ bin/composer-install

After that, you need to properly symlink Gantry into your CMS installation.

## Testing PHP 8.3 Compatibility

The framework includes a PHPUnit test suite specifically for validating PHP 8.3 compatibility. To run these tests:

```bash
# Install composer dependencies if not already done
bin/composer-install

# Run the PHP 8.3 compatibility tests
vendor/bin/phpunit
```

This will execute tests that verify key components work correctly with PHP 8.3 including:
- Type system compatibility (nullable and union types)
- Trait implementation compatibility
- Core framework functionality
- Platform-specific features
- Twig integration

## Bundling JS and Compiling SCSS

In our development environment, we use **Gulp** to bundle **JavaScript** and compile **SCSS** with the capability of `watch` so that any change on target files will automatically trigger the recompilation.
Expand Down
35 changes: 35 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="tests/php83/bootstrap.php">

<testsuites>
<testsuite name="PHP 8.3 Compatibility Tests">
<directory>tests/php83</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">src/classes</directory>
<directory suffix=".php">platforms/*/classes</directory>
<exclude>
<directory>vendor</directory>
<directory>platforms/*/vendor</directory>
</exclude>
</whitelist>
</filter>

<php>
<ini name="error_reporting" value="E_ALL" />
<ini name="display_errors" value="On" />
<ini name="display_startup_errors" value="On" />
</php>
</phpunit>
76 changes: 76 additions & 0 deletions tests/php83/Component/Layout/LayoutTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace Gantry\Tests\PHP83\Component\Layout;

use Gantry\Tests\PHP83\MockableTest;
use Gantry\Component\Layout\Layout;

/**
* Test layout component with PHP 8.3
*/
class LayoutTest extends MockableTest
{
/**
* Test layout initialization
*/
public function testLayoutInitialization()
{
// Test creating a layout instance with minimal parameters
$layout = new Layout('test');
$this->assertInstanceOf(Layout::class, $layout);

// Test getting layout name
$this->assertEquals('test', $layout->name);
}

/**
* Test layout preset loading
*/
public function testLayoutPresets()
{
$layout = new Layout('test');

// Test preset functionality
$preset = [
'name' => 'Test Preset',
'sections' => [
'main' => [
'type' => 'section',
'attributes' => ['id' => 'main']
]
]
];

$layout->initPreset($preset);

// Test that preset was applied
$this->assertNotEmpty($layout->preset);
}

/**
* Test layout rendering with PHP 8.3 compatibility
*/
public function testLayoutRendering()
{
$layout = new Layout('test');

// Simple preset for testing
$preset = [
'name' => 'Test Preset',
'sections' => [
'main' => [
'type' => 'section',
'attributes' => ['id' => 'main'],
'children' => []
]
]
];

$layout->initPreset($preset);

// Test that the layout can be converted to array
$array = $layout->toArray();
$this->assertIsArray($array);
$this->assertArrayHasKey('name', $array);
}
}
60 changes: 60 additions & 0 deletions tests/php83/Component/PHP83TypesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Gantry\Tests\PHP83;

use Gantry\Tests\PHP83\MockableTest;

/**
* Test PHP 8.3 specific type handling and compatibility
*/
class PHP83TypesTest extends MockableTest
{
/**
* Test that nullable types and union types work correctly
*
* @covers \Gantry\Component\Stylesheet\CssCompiler
*/
public function testNullableAndUnionTypes()
{
// Test with null values for nullable parameters
$instance = new \Gantry\Component\Stylesheet\CssCompiler();

// Set null target path and verify it handles correctly
$instance->setTargetPath(null);
$this->assertNull($instance->getTargetPath());

// Test with string target
$testPath = 'test/path/to/css';
$instance->setTargetPath($testPath);
$this->assertEquals($testPath, $instance->getTargetPath());
}

/**
* Test compatibility with PHP 8.3 trait handling
*
* @covers \Gantry\Component\Theme\ThemeTrait
*/
public function testTraitCompatibility()
{
// Create a mock class using the trait
$mock = new class {
use \Gantry\Component\Theme\ThemeTrait;

public function getUrl()
{
return $this->url;
}

public function setUrl($url)
{
$this->url = $url;
return $this;
}
};

// Test the trait functionality
$testUrl = 'https://test.com/theme';
$mock->setUrl($testUrl);
$this->assertEquals($testUrl, $mock->getUrl());
}
}
61 changes: 61 additions & 0 deletions tests/php83/Component/TwigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Gantry\Tests\PHP83\Component;

use Gantry\Tests\PHP83\MockableTest;
use Gantry\Component\Twig\TwigExtension;

/**
* Test Twig integration with PHP 8.3
*/
class TwigTest extends MockableTest
{
/**
* Test Twig extension class instantiation
*/
public function testTwigExtensionInstantiation()
{
$extension = new TwigExtension();
$this->assertInstanceOf(TwigExtension::class, $extension);
}

/**
* Test Twig filters availability
*/
public function testTwigFilters()
{
$extension = new TwigExtension();
$filters = $extension->getFilters();

$this->assertIsArray($filters);
$this->assertNotEmpty($filters);

// Check for core filters
$filterNames = array_map(function ($filter) {
return $filter->getName();
}, $filters);

$this->assertContains('transFilter', $filterNames);
$this->assertContains('truncateHtml', $filterNames);
}

/**
* Test Twig functions availability
*/
public function testTwigFunctions()
{
$extension = new TwigExtension();
$functions = $extension->getFunctions();

$this->assertIsArray($functions);
$this->assertNotEmpty($functions);

// Check for core functions
$functionNames = array_map(function ($function) {
return $function->getName();
}, $functions);

$this->assertContains('trans', $functionNames);
$this->assertContains('url', $functionNames);
}
}
66 changes: 66 additions & 0 deletions tests/php83/Framework/GantryMock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Gantry\Framework\Base;

/**
* Mock Gantry class for testing
*/
class Gantry
{
private static $instance;

/**
* @var \stdClass
*/
public $container;

private $debugMode = false;

/**
* Constructor.
*/
protected function __construct()
{
// Create container as a class to allow method calls
$this->container = new class {
public $services = ['platform' => 'mock'];

public function has($service) {
return isset($this->services[$service]);
}

public function get($service) {
return $this->services[$service] ?? null;
}
};
}

/**
* Get instance of the Gantry Framework
*
* @return Gantry
*/
public static function instance()
{
if (!self::$instance) {
self::$instance = new static();
}

return self::$instance;
}

/**
* Set/Get debug mode.
*
* @param bool|null $enabled True to enable debugging, null to ignore.
* @return bool
*/
public function debug($enabled = null)
{
if (isset($enabled)) {
$this->debugMode = (bool) $enabled;
}

return $this->debugMode;
}
}
60 changes: 60 additions & 0 deletions tests/php83/Framework/GantryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Gantry\Tests\PHP83\Framework;

use Gantry\Tests\PHP83\MockableTest;
use Gantry\Framework\Base\Gantry;

/**
* Test core Gantry framework functionality with PHP 8.3
*/
class GantryTest extends MockableTest
{
/**
* Test instance creation and basic functionality
*/
public function testGantryInstance()
{
// Get the Gantry instance
$gantry = Gantry::instance();

// Test that we got a valid instance
$this->assertInstanceOf(Gantry::class, $gantry);

// Test that we can access the container
$container = $gantry->container;
$this->assertNotNull($container);
}

/**
* Test Gantry container services
*/
public function testGantryContainer()
{
$gantry = Gantry::instance();

// Test platform service
$this->assertTrue($gantry->container->has('platform'));

// Test theme service
if ($gantry->container->has('theme')) {
$theme = $gantry->container->get('theme');
$this->assertNotNull($theme);
}
}

/**
* Test debugging functionality
*/
public function testGantryDebug()
{
$gantry = Gantry::instance();

// Test debug mode can be set
$gantry->debug(true);
$this->assertTrue($gantry->debug());

$gantry->debug(false);
$this->assertFalse($gantry->debug());
}
}
Loading

0 comments on commit e295374

Please sign in to comment.