Skip to content

Commit

Permalink
Merge pull request #17 from elbformat/matrix-jobs
Browse files Browse the repository at this point in the history
Run tests with multiple php/symfony versions
  • Loading branch information
hgiesenow committed Mar 1, 2023
2 parents 81fa509 + 511dd26 commit 5f4dcec
Show file tree
Hide file tree
Showing 17 changed files with 124 additions and 69 deletions.
46 changes: 37 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,29 @@ orbs:
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
build:
parameters: &jobParams
php_version:
type: string
symfony_version:
type: string
monolog_version:
type: string
docker:
- image: 'hgiesenow/php:8.1'
- image: 'hgiesenow/php:<< parameters.php_version >>'
steps:
- checkout
- run: 'composer install --dev'
- run: 'composer require -W symfony/dom-crawler:"^<< parameters.symfony_version >>" symfony/property-access:"^<< parameters.symfony_version >>"; rm composer.lock'
- run: 'composer require --dev -W symfony/framework-bundle:"^<< parameters.symfony_version >>"; rm composer.lock'
- run: 'composer require --dev -W monolog/monolog:"^<< parameters.monolog_version >>"; rm composer.lock'
- run: 'if [ "5.4" == "<< parameters.symfony_version >>" ]; then composer require --dev -W symfony/swiftmailer-bundle:"^3.5"; fi'
- persist_to_workspace:
root: '.'
paths: 'vendor'
phpunit:
parameters:
<<: *jobParams
docker:
- image: 'hgiesenow/php:8.1'
- image: 'hgiesenow/php:<< parameters.php_version >>'
steps:
- checkout
- attach_workspace:
Expand All @@ -39,23 +51,39 @@ jobs:
- run: 'vendor/bin/php-cs-fixer fix --diff --dry-run src'
- run: 'vendor/bin/php-cs-fixer fix --diff --dry-run tests'
psalm:
parameters:
<<: *jobParams
docker:
- image: 'hgiesenow/php:8.1'
- image: 'hgiesenow/php:<< parameters.php_version >>'
steps:
- checkout
- attach_workspace:
at: '.'
- run: 'vendor/bin/psalm'
- run: 'if [ "5.4" == "<< parameters.symfony_version >>" ]; then vendor/bin/psalm; else vendor/bin/psalm -c psalm-sf6.xml; fi'

# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
test-workflow:
jobs:
- build
- build:
name: 'build/php-<< matrix.php_version >>/sf-<< matrix.symfony_version >>/monolog-<< matrix.monolog_version >>'
matrix:
parameters: &params
php_version: ['8.1','8.2']
symfony_version: ['5.4','6.2']
monolog_version: ['2.6']
- phpunit:
requires: ['build']
name: 'phpunit/php-<< matrix.php_version >>/sf-<< matrix.symfony_version >>/monolog-<< matrix.monolog_version >>'
requires: ['build/php-<< matrix.php_version >>/sf-<< matrix.symfony_version >>/monolog-<< matrix.monolog_version >>']
matrix:
parameters:
<<: *params
- php-cs-fixer:
requires: ['build']
requires: ['build/php-8.1/sf-5.4/monolog-2.6']
- psalm:
requires: ['build']
name: 'psalm/php-<< matrix.php_version >>/sf-<< matrix.symfony_version >>/monolog-<< matrix.monolog_version >>'
requires: ['build/php-<< matrix.php_version >>/sf-<< matrix.symfony_version >>/monolog-<< matrix.monolog_version >>']
matrix:
parameters:
<<: *params
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@
"ext-json": "*",
"behat/behat": "^3.8",
"friends-of-behat/symfony-extension": "^2.2",
"symfony/dom-crawler": "^5.4",
"symfony/property-access": "^5.4"
"symfony/dom-crawler": "^5.4|^6.2",
"symfony/property-access": "^5.4|^6.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.3",
"phpunit/phpunit": "^9.5",
"vimeo/psalm": "^4.13",
"monolog/monolog": "^2.6",
"symfony/framework-bundle": "^5.4",
"doctrine/orm": "^2.12",
"symfony/swiftmailer-bundle": "^3.5"
"symfony/framework-bundle": "^5.4|^6.2",
"doctrine/orm": "^2.12"
},
"config": {
"allow-plugins": {
Expand Down
6 changes: 6 additions & 0 deletions doc/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ vendor/bin/php-cs-fixer fix --diff src
vendor/bin/php-cs-fixer fix --diff tests
# Check code
vendor/bin/psalm
# Enable optional bundles
composer require --dev -W symfony/swiftmailer-bundle:"^3.5"
# Try upgraded monolog version
composer require --dev -W monolog/monolog:"^3.0"
```



Enable xdebug inside the container
```bash
apk add autoconf g++ make
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.1-alpine
FROM php:8.2-alpine
# For codecov upload inside circleci
RUN apk add gpg gpg-agent gpgv
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="true" backupStaticAttributes="false" colors="false" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" forceCoversAnnotation="false" processIsolation="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" stopOnRisky="false" verbose="false">
<coverage processUncoveredFiles="true">
<coverage processUncoveredFiles="false">
<include>
<directory suffix=".php">src/</directory>
</include>
Expand Down
25 changes: 25 additions & 0 deletions psalm-sf6.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
<file name="src/Context/SwiftmailerContext.php" />
<file name="src/Swiftmailer/TestTransport.php" />
<file name="src/DependencyInjection/SwiftmailerCompilerPass.php" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<MissingDependency>
<errorLevel type="suppress">
<file name="src/DependencyInjection/ElbformatSymfonyBehatExtension.php" />
</errorLevel>
</MissingDependency>
</issueHandlers>
</psalm>
2 changes: 1 addition & 1 deletion tests/Application/ApplicationFactoryTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Application;
namespace Elbformat\SymfonyBehatBundle\Tests\Application;

use Elbformat\SymfonyBehatBundle\Application\ApplicationFactory;
use PHPUnit\Framework\TestCase;
Expand Down
2 changes: 1 addition & 1 deletion tests/Browser/StateFactoryTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Browser;
namespace Elbformat\SymfonyBehatBundle\Tests\Browser;

use Elbformat\SymfonyBehatBundle\Browser\State;
use Elbformat\SymfonyBehatBundle\Browser\StateFactory;
Expand Down
2 changes: 1 addition & 1 deletion tests/Browser/StateTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Browser;
namespace Elbformat\SymfonyBehatBundle\Tests\Browser;

use Elbformat\SymfonyBehatBundle\Browser\State;
use PHPUnit\Framework\TestCase;
Expand Down
2 changes: 1 addition & 1 deletion tests/BundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testBuild(): void
{
$bundle = new ElbformatSymfonyBehatBundle();
$container = $this->createMock(ContainerBuilder::class);
$container->expects($this->exactly(2))->method('addCompilerPass')->withConsecutive([$this->isInstanceOf(MonologCompilerPass::class)], [$this->isInstanceOf(SwiftmailerCompilerPass::class)])->willReturn(null);
$container->expects($this->exactly(2))->method('addCompilerPass')->withConsecutive([$this->isInstanceOf(MonologCompilerPass::class)], [$this->isInstanceOf(SwiftmailerCompilerPass::class)]);
$bundle->build($container);
}
}
2 changes: 1 addition & 1 deletion tests/Context/AbstractDatabaseContextTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Context;
namespace Elbformat\SymfonyBehatBundle\Tests\Context;

use Behat\Gherkin\Node\TableNode;
use Doctrine\Common\Collections\ArrayCollection;
Expand Down
2 changes: 1 addition & 1 deletion tests/Context/BrowserContextTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Context;
namespace Elbformat\SymfonyBehatBundle\Tests\Context;

use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
Expand Down
2 changes: 1 addition & 1 deletion tests/Context/CommandContextTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Context;
namespace Elbformat\SymfonyBehatBundle\Tests\Context;

use Elbformat\SymfonyBehatBundle\Application\ApplicationFactory;
use Elbformat\SymfonyBehatBundle\Context\CommandContext;
Expand Down
73 changes: 30 additions & 43 deletions tests/Context/LoggingContextTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

namespace Context;
namespace Elbformat\SymfonyBehatBundle\Tests\Context;

use Behat\Gherkin\Node\TableNode;
use Behat\Testwork\Hook\Scope\AfterTestScope;
use Behat\Testwork\Tester\Result\TestResult;
use Elbformat\SymfonyBehatBundle\Context\LoggingContext;
use Monolog\Formatter\FormatterInterface;
use Monolog\Handler\TestHandler;
use Monolog\Level;
use Monolog\LogRecord;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Kernel;
Expand All @@ -27,7 +29,7 @@ protected function setUp(): void
$this->container = $this->createMock(ContainerInterface::class);
$this->handler = new TestHandler();
$this->formatter = $this->createMock(FormatterInterface::class);
$this->formatter->method('format')->willReturnCallback(function (array $record) {
$this->formatter->method('format')->willReturnCallback(function ($record) {
return $record['message'];
});
$this->handler->setFormatter($this->formatter);
Expand All @@ -38,7 +40,7 @@ protected function setUp(): void
public function testDumpLog(): void
{
$this->container->method('get')->with('monolog.handler.main')->willReturn($this->handler);
$this->handler->handle(['level' => 100,'message' => 'ignore me']);
$this->handle(100, 'ignore me');
$event = $this->createMock(AfterTestScope::class);
$testResult = $this->createMock(TestResult::class);
$testResult->method('isPassed')->willReturn(false);
Expand All @@ -58,24 +60,15 @@ public function testDumpLogPassed(): void
public function testTheLogfileContainsAnEntry(): void
{
$this->container->method('get')->with('monolog.handler.main')->willReturn($this->handler);
$record = [
'level' => 400,
'message' => 'Hello World',
'extra' => null,
];
$this->formatter->expects($this->once())->method('format');
$this->handler->handle($record);
$this->handle(400, 'Hello World');
$this->loggingContext->theLogfileContainsAnEntry('main', 'error', 'Hello World');
}

public function testTheLogfileContainsAnEntryFail(): void
{
$this->container->method('get')->with('monolog.handler.main')->willReturn($this->handler);
$record = [
'level' => '400',
'message' => 'Bye World',
];
$this->handler->handle($record);
$this->handle(400, 'Bye World');
$this->expectExceptionMessage('Log entry not found.');
$this->loggingContext->theLogfileContainsAnEntry('main', 'error', 'Hello World');
}
Expand All @@ -86,10 +79,10 @@ public function testTheLogfileContainsAnEntryWithContext(): void
$record = [
'level' => '400',
'message' => 'Hello World',
'context' => ['hello' =>'world'],
'context' => ['hello' => 'world'],
];
$this->formatter->expects($this->once())->method('format');
$this->handler->handle($record);
$this->handle(400, 'Hello World', ['hello' => 'world']);
$tableData = [
0 => ['hello', 'world'],
];
Expand All @@ -102,7 +95,7 @@ public function testTheLogfileContainsAnEntryWithContextRegex(): void
$record = [
'level' => '400',
'message' => 'Hello World',
'context' => ['hello' =>'world'],
'context' => ['hello' => 'world'],
];
$this->formatter->expects($this->once())->method('format');
$this->handler->handle($record);
Expand Down Expand Up @@ -158,12 +151,7 @@ public function testTheLogfileContainsAnEntryWithContextFail(): void
public function testTheLogfileContainsAnEntryWithContextJsonFail(): void
{
$this->container->method('get')->with('monolog.handler.main')->willReturn($this->handler);
$record = [
'level' => '400',
'message' => 'Hello World',
'context' => ['obj' => ['hello' => 'not']],
];
$this->handler->handle($record);
$this->handle(400, 'Hello World', ['obj' => ['hello' => 'not']]);
$this->expectExceptionMessage('Log entry found, but with different context.');
$tableData = [
0 => ['obj', '{"hello":"world"}'],
Expand All @@ -174,47 +162,31 @@ public function testTheLogfileContainsAnEntryWithContextJsonFail(): void
public function testTheLogfileDoesntContainAnyEntries(): void
{
$this->container->method('get')->with('monolog.handler.main')->willReturn($this->handler);
$record = [
'level' => '100',
'message' => 'Hello World',
];
$this->formatter->expects($this->once())->method('format');
$this->handler->handle($record);
$this->handle(100, 'Hello World');
$this->loggingContext->theLogfileDoesntContainAnyEntries('main', 'error');
}

public function testTheLogfileDoesntContainAnyEntriesFail(): void
{
$this->container->method('get')->with('monolog.handler.main')->willReturn($this->handler);
$record = [
'level' => '400',
'message' => 'Hello World',
];
$this->handler->handle($record);
$this->handle(400, 'Hello World');
$this->expectExceptionMessage('Log entries found');
$this->loggingContext->theLogfileDoesntContainAnyEntries('main', 'error');
}

public function testTheLogfileDoesntContainAnEntry(): void
{
$this->container->method('get')->with('monolog.handler.main')->willReturn($this->handler);
$record = [
'level' => '100',
'message' => 'Hello World',
];
$this->formatter->expects($this->once())->method('format');
$this->handler->handle($record);
$this->handle(100, 'Hello World');
$this->loggingContext->theLogfileDoesntContainAnEntry('main', 'error', ' Hello world');
}

public function testTheLogfileDoesntContainAnEntryFail(): void
{
$this->container->method('get')->with('monolog.handler.main')->willReturn($this->handler);
$record = [
'level' => '400',
'message' => 'Hello World',
];
$this->handler->handle($record);
$this->handle(400, 'Hello World');
$this->expectExceptionMessage('Entry found');
$this->loggingContext->theLogfileDoesntContainAnEntry('main', 'error', 'Hello World');
}
Expand All @@ -225,4 +197,19 @@ public function testGetLogHandlerFails(): void
$this->expectExceptionMessage('No monolog TestHandler found named monolog.handler.main. Is it public?');
$this->loggingContext->printLogs();
}

protected function handle(int $level, string $message, array $context = []): void
{
// Preparation for monolog 3.x
if (class_exists('\\Monolog\\LogRecord')) {
$record = new LogRecord(new \DateTimeImmutable(), 'main', Level::fromValue($level), $message, $context);
} else {
$record = [
'level' => $level,
'message' => $message,
'context' => $context,
];
}
$this->handler->handle($record);
}
}

0 comments on commit 5f4dcec

Please sign in to comment.