Skip to content
Open
30 changes: 22 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,41 @@ jobs:
tests:
name: PHP ${{ matrix.php }} / Symfony ${{ matrix.symfony_version }} / ${{ matrix.os }} / ${{ matrix.dependency-version }}

# The bundle constraints are widened to ^7.0|^8.0, but roach-php/core 3.2.1
# still requires symfony/* ^7.0, so the 8.x cells cannot resolve until core
# widens its constraints upstream. Keep them as allowed failures so the
# dual-support intent stays visible without turning the PR red.
continue-on-error: ${{ matrix.symfony_version != '7.4.*' }}

env:
extensions: dom, curl
key: cache-v1
PHPUNIT_COVERAGE: 0
PHP_INI: date.timezone='UTC', memory_limit=-1

strategy:
fail-fast: false
matrix:
os: [ 'ubuntu-latest' ]
php: [ '8.0', '8.1' ]
symfony_version: [ '6.0.*' ]
php: [ '8.2', '8.3', '8.4', '8.5' ]
symfony_version: [ '7.4.*', '8.0.*', '8.1.*' ]
dependency-version: [ 'prefer-lowest', 'prefer-stable' ]
exclude:
# Symfony >= 8.0 requires PHP >= 8.4
- php: '8.2'
symfony_version: '8.0.*'
- php: '8.2'
symfony_version: '8.1.*'
- php: '8.3'
symfony_version: '8.0.*'
- php: '8.3'
symfony_version: '8.1.*'

runs-on: ${{ matrix.os }}

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -38,7 +55,7 @@ jobs:
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: "${{ env.COMPOSER_CACHE_DIR }}"
key: "php-${{ matrix.php }}-composer-${{ matrix.dependency-version }}-${{ matrix.symfony_version }}-${{ matrix.os }}-${{ hashFiles('composer.lock') }}"
Expand All @@ -64,8 +81,5 @@ jobs:
- name: Install PHPUnit
run: vendor/bin/simple-phpunit install

- name: Run psalm
run: vendor/bin/psalm

- name: Run tests with phpunit
run: vendor/bin/simple-phpunit -v -c phpunit.xml.dist
run: vendor/bin/simple-phpunit -c phpunit.xml.dist
25 changes: 11 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@
"description": "Symfony bundle for roach-php/core",
"type": "symfony-bundle",
"require": {
"php": ">= 8.0",
"roach-php/core": "~1.1.0",
"symfony/config": "^6.0",
"symfony/dependency-injection": "^6.0",
"symfony/http-kernel": "^6.0",
"symfony/console": "^6.0",
"symfony/serializer": "^6.0"
"php": ">= 8.2",
"roach-php/core": "^3.2",
"symfony/config": "^7.0|^8.0",
"symfony/dependency-injection": "^7.0|^8.0",
"symfony/http-kernel": "^7.0|^8.0",
"symfony/console": "^7.0|^8.0",
"symfony/serializer": "^7.0|^8.0"
},
"require-dev": {
"roave/security-advisories": "dev-latest",
"symfony/phpunit-bridge": "^6.0",
"symfony/var-dumper": "^6.0",
"symfony/framework-bundle": "^6.0",
"symfony/maker-bundle": "^1.37",
"vimeo/psalm": "^4.21",
"psalm/plugin-symfony": "^3.1",
"psalm/plugin-phpunit": "^0.16.1"
"symfony/phpunit-bridge": "^7.0|^8.0",
"symfony/var-dumper": "^7.0|^8.0",
"symfony/framework-bundle": "^7.0|^8.0",
"symfony/maker-bundle": "^1.68"
},
"license": "MIT",
"autoload": {
Expand Down
14 changes: 7 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
colors="true"
bootstrap="tests/bootstrap.php"
>
Expand All @@ -11,7 +11,7 @@
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
<server name="SYMFONY_PHPUNIT_VERSION" value="11.5" />
<server name="SYMFONY_DEPRECATIONS_HELPER" value="disabled" />
<server name="KERNEL_CLASS" value="Nelexa\RoachPhpBundle\Tests\App\Kernel" force="true" />
</php>
Expand All @@ -22,16 +22,16 @@
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<source>
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory suffix=".tpl.php">.</directory>
</exclude>
</coverage>
</source>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<extensions>
<bootstrap class="Symfony\Bridge\PhpUnit\SymfonyExtension" />
</extensions>
</phpunit>
8 changes: 4 additions & 4 deletions src/Command/RunSpiderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@

final class RunSpiderCommand extends Command
{
protected static $defaultName = 'roach:run';

protected static $defaultDescription = 'Run the provided spider';

/** @var array<class-string<\RoachPHP\Spider\SpiderInterface>, array<string>> */
private array $spiderNames;

Expand All @@ -45,6 +41,10 @@ public function __construct(private ServiceLocator $serviceLocator, private Seri

protected function configure(): void
{
$this
->setName('roach:run')
->setDescription('Run the provided spider');

$spiderArgDescription = "Spider class name\nSupport spiders:\n";

foreach ($this->spiderNames as $className => $aliases) {
Expand Down
9 changes: 4 additions & 5 deletions src/Normalizer/ItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
namespace Nelexa\RoachPhpBundle\Normalizer;

use RoachPHP\ItemPipeline\ItemInterface;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

class ItemNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
class ItemNormalizer implements NormalizerInterface
{
public function hasCacheableSupportsMethod(): bool
public function getSupportedTypes(?string $format): array
{
return true;
return [ItemInterface::class => true];
}

public function supportsNormalization(mixed $data, ?string $format = null): bool
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return $data instanceof ItemInterface;
}
Expand Down
17 changes: 17 additions & 0 deletions src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,23 @@
;
$services->set(\RoachPHP\Downloader\Middleware\RobotsTxtMiddleware::class);
$services->set(\RoachPHP\Downloader\Middleware\UserAgentMiddleware::class);
// New in roach-php/core 3.x: drops responses with unallowed HTTP status.
// Configure per spider via the "handleStatus" option.
$services
->set(\RoachPHP\Downloader\Middleware\HttpErrorMiddleware::class)
->args([
service('roach_php.logger'),
])
;
// New in roach-php/core 3.x: assigns proxies to requests.
// Configure per spider via the "proxy" or "loader" options.
$services
->set(\RoachPHP\Downloader\Middleware\ProxyMiddleware::class)
->args([
service('service_container'),
service('roach_php.logger'),
])
;

// Extensions
$services
Expand Down
14 changes: 5 additions & 9 deletions tests/Command/MakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,17 @@

namespace Nelexa\RoachPhpBundle\Tests\Command;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Small;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester;

/**
* @internal
*
* @small
*/
#[Small]
class MakeCommandTest extends KernelTestCase
{
/**
* @dataProvider provideMakeCommand
*/
#[DataProvider('provideMakeCommand')]
public function testMakeCommand(
string $commandName,
array $input,
Expand Down Expand Up @@ -56,7 +52,7 @@ public function testMakeCommand(
}
}

public function provideMakeCommand(): iterable
public static function provideMakeCommand(): iterable
{
yield 'make:roach:spider' => [
'make:roach:spider',
Expand Down
7 changes: 2 additions & 5 deletions tests/Command/RunSpiderCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@

namespace Nelexa\RoachPhpBundle\Tests\Command;

use PHPUnit\Framework\Attributes\Medium;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;

/**
* @internal
*
* @medium
*/
#[Medium]
final class RunSpiderCommandTest extends KernelTestCase
{
public function testExecute(): void
Expand Down
7 changes: 2 additions & 5 deletions tests/Spider/QuotesSpiderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@
namespace Nelexa\RoachPhpBundle\Tests\Spider;

use Nelexa\RoachPhpBundle\Tests\App\Spider\QuotesSpider;
use PHPUnit\Framework\Attributes\Medium;
use RoachPHP\Roach;
use RoachPHP\Testing\FakeLogger;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
* @medium
*
* @internal
*/
#[Medium]
final class QuotesSpiderTest extends KernelTestCase
{
private FakeLogger $logger;
Expand Down
Loading