Skip to content
Open
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
10 changes: 3 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@ on:
jobs:
phpunit:
name: "PHPUnit"
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-24.04"

strategy:
matrix:
php-version:
- "8.0"
- "8.1"
- "8.4"
dependencies:
- "highest"
include:
- php-version: "8.0"
dependencies: "lowest"

- "lowest"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
Expand Down
7 changes: 1 addition & 6 deletions ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@

class ConfigHelper
{
private array $config;
private string $projectDir;

public function __construct(string $projectDir, array $config)
public function __construct(private string $projectDir, private array $config)
{
$this->config = $config;
$this->projectDir = $projectDir;
}

public function buildProcess(InputStream $input, array $arguments = [], array $env = []): Process
Expand Down
8 changes: 2 additions & 6 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ public function getConfigTreeBuilder(): TreeBuilder
]
)
->beforeNormalization()
->ifTrue(function ($v) {
return !isset($v['format']);
})
->then(function ($v) {
return array_merge(['format' => 'pdf'], $v);
})
->ifTrue(fn(array $v) => !isset($v['format']))
->then(fn($v) => array_merge(['format' => 'pdf'], $v))
->end()
->prototype('scalar')->end()
->end()
Expand Down
6 changes: 3 additions & 3 deletions DependencyInjection/Padam87RasterizeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Padam87\RasterizeBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
* This is the class that loads and manages your bundle configuration
Expand All @@ -17,12 +17,12 @@ class Padam87RasterizeExtension extends Extension
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yaml');

$container->setParameter('padam87_rasterize.config', $config);
Expand Down
11 changes: 3 additions & 8 deletions Rasterizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@

class Rasterizer
{
protected ConfigHelper $configHelper;
protected ?Stopwatch $stopwatch;

public function __construct(ConfigHelper $configHelper, Stopwatch $stopwatch = null)
public function __construct(protected ConfigHelper $configHelper, protected ?Stopwatch $stopwatch = null)
{
$this->configHelper = $configHelper;
$this->stopwatch = $stopwatch;
}

public function rasterize(string $html, array $arguments = [], array $env = [], callable $callback = null): string
public function rasterize(string $html, array $arguments = [], array $env = [], ?callable $callback = null): string
{
if ($this->stopwatch instanceof Stopwatch) {
$this->stopwatch->start('rasterizer');
Expand All @@ -26,7 +21,7 @@ public function rasterize(string $html, array $arguments = [], array $env = [],

$process = $this->configHelper->buildProcess($input, $arguments, $env);

if ($callback) {
if ($callback !== null) {
$callback($process);
}

Expand Down
26 changes: 7 additions & 19 deletions Tests/ConfigHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
namespace Padam87\RasterizeBundle\Tests;

use Padam87\RasterizeBundle\ConfigHelper;
use Mockery as m;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\InputStream;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessUtils;

class ConfigHelperTest extends TestCase
{
Expand All @@ -16,11 +15,6 @@ class ConfigHelperTest extends TestCase
*/
protected $config;

protected function tearDown(): void
{
m::close();
}

public function setUp(): void
{
$this->config = [
Expand All @@ -37,10 +31,8 @@ public function setUp(): void
];
}

/**
* @test
*/
public function isTheProcessBuilt()
#[Test]
public function isTheProcessBuilt(): void
{
$configHelper = new ConfigHelper(__DIR__, $this->config);
$process = $configHelper->buildProcess(new InputStream());
Expand All @@ -55,10 +47,8 @@ public function isTheProcessBuilt()
$this->assertCount(1, $process->getEnv());
}

/**
* @test
*/
public function attributeMerge()
#[Test]
public function attributeMerge(): void
{
$configHelper = new ConfigHelper(__DIR__, $this->config);
$process = $configHelper->buildProcess(new InputStream(), ['paper' => 'A4']);
Expand All @@ -69,10 +59,8 @@ public function attributeMerge()
);
}

/**
* @test
*/
public function envMerge()
#[Test]
public function envMerge(): void
{
$configHelper = new ConfigHelper(__DIR__, $this->config);
$process = $configHelper->buildProcess(new InputStream(), [], ['MY_ENV' => 'something']);
Expand Down
53 changes: 22 additions & 31 deletions Tests/RasterizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace Padam87\RasterizeBundle\Tests;

use Mockery as m;
use Mockery\MockInterface;
use Padam87\RasterizeBundle\ConfigHelper;
use Padam87\RasterizeBundle\Rasterizer;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;
use Symfony\Component\Stopwatch\Stopwatch;
Expand All @@ -16,51 +15,43 @@ class RasterizerTest extends TestCase
private $stopwatch;
private $process;

protected function tearDown(): void
{
m::close();
}

public function setUp(): void
{
$this->configHelper = m::mock(ConfigHelper::class);
$this->stopwatch = m::mock(Stopwatch::class);
$this->process = m::mock(Process::class);
$this->configHelper = $this->createMock(ConfigHelper::class);
$this->stopwatch = $this->createMock(Stopwatch::class);
$this->process = $this->createMock(Process::class);
}

/**
* @test
*/
public function testRasterize()

#[Test]
public function testRasterize(): void
{
$this->stopwatch->shouldReceive('start')->once();
$this->stopwatch->shouldReceive('stop')->once();
$this->stopwatch->expects($this->once())->method('start');
$this->stopwatch->expects($this->once())->method('stop');

$this->configHelper->shouldReceive('buildProcess')->once()->andReturn($this->process);
$this->configHelper->expects($this->once())->method('buildProcess')->willReturn($this->process);

$this->process->shouldReceive('start');
$this->process->shouldReceive('wait');
$this->process->shouldReceive('getOutput')->andReturn('pdfcontent');
$this->process->expects($this->any())->method('start');
$this->process->expects($this->any())->method('wait');
$this->process->expects($this->any())->method('getOutput')->willReturn('pdfcontent');

$rasterizer = new Rasterizer($this->configHelper, $this->stopwatch);

$this->assertSame('pdfcontent', $rasterizer->rasterize('<html></html>'));
}

/**
* @test
*/
public function testCallback()
#[Test]
public function testCallback(): void
{
$this->stopwatch->shouldReceive('start')->once();
$this->stopwatch->shouldReceive('stop')->once();
$this->stopwatch->expects($this->once())->method('start');
$this->stopwatch->expects($this->once())->method('stop');

$this->configHelper->shouldReceive('buildProcess')->once()->andReturn($this->process);
$this->configHelper->expects($this->once())->method('buildProcess')->willReturn($this->process);

$this->process->shouldReceive('start');
$this->process->shouldReceive('wait');
$this->process->shouldReceive('setTimeout');
$this->process->shouldReceive('getOutput')->andReturn('pdfcontent');
$this->process->expects($this->any())->method('start');
$this->process->expects($this->any())->method('wait');
$this->process->expects($this->any())->method('setTimeout');
$this->process->expects($this->any())->method('getOutput')->willReturn('pdfcontent');

$rasterizer = new Rasterizer($this->configHelper, $this->stopwatch);
$output = $rasterizer->rasterize('<html></html>', [], [], function (Process $process) {
Expand Down
15 changes: 7 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
"psr-4": { "Padam87\\RasterizeBundle\\": "" }
},
"require": {
"php": "^8.0",
"symfony/config": "^5.4|^6.0|^7.0",
"symfony/dependency-injection": "^5.4|^6.0|^7.0",
"symfony/http-kernel": "^5.4|^6.0|^7.0",
"symfony/process": "^5.4|^6.0|^7.0",
"symfony/stopwatch": "^5.4|^6.0|^7.0"
"php": "^8.4",
"symfony/config": "^6.0 || ^7.0 || ^8.0",
"symfony/dependency-injection": "^6.0 || ^7.0 || ^8.0",
"symfony/http-kernel": "^6.0 || ^7.0 || ^8.0",
"symfony/process": "^6.0 || ^7.0 || ^8.0",
"symfony/stopwatch": "^6.0 || ^7.0 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "~9.0",
"mockery/mockery": "~1.4"
"phpunit/phpunit": "^12.0"
},
"scripts": {
"test": "phpunit"
Expand Down
31 changes: 14 additions & 17 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="./Tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="Padam87RasterizeBundle">
<directory suffix="Test.php">./Tests</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<include>
<file>ConfigHelper.php</file>
<file>Rasterizer.php</file>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<phpunit bootstrap="./Tests/bootstrap.php" colors="true" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Padam87RasterizeBundle">
<directory suffix="Test.php">./Tests</directory>
</testsuite>
</testsuites>
<source ignoreIndirectDeprecations="true">
<include>
<directory>Tests</directory>
</include>
</source>
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="0" force="true" />
</php>
</phpunit>
Loading