Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add first func test #109

Merged
merged 4 commits into from
Aug 7, 2024
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
25 changes: 25 additions & 0 deletions .github/workflows/typo3_13.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,28 @@ jobs:

- name: 'Execute unit tests'
run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -s unit

functional-tests:
name: Functional tests
needs: code-quality
runs-on: self-hosted

strategy:
matrix:
php:
- '8.2'
- '8.3'

vendor:
- mysql
- mariadb

steps:
- name: 'Checkout'
uses: actions/checkout@v4

- name: 'Install testing system'
run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -s composerUpdate

- name: 'Execute functional tests'
run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -d ${{ matrix.vendor }} -s functional
11 changes: 3 additions & 8 deletions Classes/Helper/ExplainQueryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
use Doctrine\DBAL\Exception;
use StefanFroemken\Mysqlreport\Configuration\ExtConf;
use StefanFroemken\Mysqlreport\Domain\Model\QueryInformation;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use StefanFroemken\Mysqlreport\Traits\DatabaseConnectionTrait;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Helper to analyze EXPLAIN query result and add information to QueryInformation model
*/
readonly class ExplainQueryHelper
{
use DatabaseConnectionTrait;

/**
* @param QueryInformation $queryInformation
*/
Expand Down Expand Up @@ -77,10 +78,4 @@ private function getExtConf(): ExtConf
{
return GeneralUtility::makeInstance(ExtConf::class);
}

private function getDefaultConnection(): Connection
{
return GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
}
}
140 changes: 140 additions & 0 deletions Tests/Functional/Configuration/ExtConfTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package stefanfroemken/mysqlreport.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace StefanFroemken\Mysqlreport\Tests\Functional\Configuration;

use PHPUnit\Framework\Attributes\Test;
use StefanFroemken\Mysqlreport\Configuration\ExtConf;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

/**
* Test case.
*/
class ExtConfTest extends FunctionalTestCase
{
private ExtConf $subject;

protected array $testExtensionsToLoad = [
'stefanfroemken/mysqlreport',
];

protected function setUp(): void
{
parent::setUp();

$this->subject = $this->get(ExtConf::class);
}

protected function tearDown(): void
{
unset(
$this->subject,
);

parent::tearDown();
}

#[Test]
public function isEnableFrontendLoggingInitiallyReturnsFalse(): void
{
self::assertFalse(
$this->subject->isEnableFrontendLogging(),
);
}

#[Test]
public function setEnableFrontendLoggingSetsEnableFrontendLogging(): void
{
$this->subject->setEnableFrontendLogging('1');

self::assertTrue(
$this->subject->isEnableFrontendLogging(),
);
}

#[Test]
public function isEnableBackendLoggingInitiallyReturnsFalse(): void
{
self::assertFalse(
$this->subject->isEnableBackendLogging(),
);
}

#[Test]
public function setEnableBackendLoggingSetsEnableBackendLogging(): void
{
$this->subject->setEnableBackendLogging('1');

self::assertTrue(
$this->subject->isEnableBackendLogging(),
);
}

#[Test]
public function isActivateExplainQueryInitiallyReturnsFalse(): void
{
self::assertFalse(
$this->subject->isActivateExplainQuery(),
);
}

#[Test]
public function setActivateExplainQuerySetsActivateExplainQuery(): void
{
$this->subject->setActivateExplainQuery('1');

self::assertTrue(
$this->subject->isActivateExplainQuery(),
);
}

#[Test]
public function getSlowQueryThresholdInitiallyReturns10Seconds(): void
{
self::assertSame(
10.0,
$this->subject->getSlowQueryThreshold(),
);
}

#[Test]
public function setSlowQueryThresholdWithIntegerSetsSlowQueryThreshold(): void
{
$this->subject->setSlowQueryThreshold('1');

self::assertSame(
1.0,
$this->subject->getSlowQueryThreshold(),
);
}

#[Test]
public function setSlowQueryThresholdWithFloatSetsSlowQueryThreshold(): void
{
$this->subject->setSlowQueryThreshold('1.25');

self::assertSame(
1.25,
$this->subject->getSlowQueryThreshold(),
);
}

#[Test]
public function setSlowQueryThresholdWithCommaFloatSetsSlowQueryThreshold(): void
{
$this->subject->setSlowQueryThreshold('5,38');

self::assertSame(
5.38,
$this->subject->getSlowQueryThreshold(),
);
}
}
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'typo3' => '13.0.0-13.4.99',
],
'conflicts' => [
'adminpanel',
'adminpanel' => '13.0.0-13.4.99',
],
'suggests' => [
],
Expand Down