diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6849e88..08ae473 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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" diff --git a/ConfigHelper.php b/ConfigHelper.php index c147137..b9d6086 100644 --- a/ConfigHelper.php +++ b/ConfigHelper.php @@ -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 diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 13c7a4e..7a1e6e9 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -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() diff --git a/DependencyInjection/Padam87RasterizeExtension.php b/DependencyInjection/Padam87RasterizeExtension.php index d7da324..de2d987 100644 --- a/DependencyInjection/Padam87RasterizeExtension.php +++ b/DependencyInjection/Padam87RasterizeExtension.php @@ -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 @@ -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); diff --git a/Rasterizer.php b/Rasterizer.php index 34c1496..84c9353 100644 --- a/Rasterizer.php +++ b/Rasterizer.php @@ -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'); @@ -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); } diff --git a/Tests/ConfigHelperTest.php b/Tests/ConfigHelperTest.php index 9b2b8fc..2214940 100644 --- a/Tests/ConfigHelperTest.php +++ b/Tests/ConfigHelperTest.php @@ -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 { @@ -16,11 +15,6 @@ class ConfigHelperTest extends TestCase */ protected $config; - protected function tearDown(): void - { - m::close(); - } - public function setUp(): void { $this->config = [ @@ -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()); @@ -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']); @@ -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']); diff --git a/Tests/RasterizerTest.php b/Tests/RasterizerTest.php index d6b4da4..e322123 100644 --- a/Tests/RasterizerTest.php +++ b/Tests/RasterizerTest.php @@ -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; @@ -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('')); } - /** - * @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('', [], [], function (Process $process) { diff --git a/composer.json b/composer.json index 9dcc70b..4194f49 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 8305700..decfc2f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,19 +1,16 @@ - - - - - ./Tests - - - - - - ConfigHelper.php - Rasterizer.php - - - - - + + + + ./Tests + + + + + Tests + + + + +