Skip to content

Commit

Permalink
Merge pull request #58 from courtney-miles/update-php-81
Browse files Browse the repository at this point in the history
Update compatibility for PHP 8.1
  • Loading branch information
courtney-miles authored Oct 19, 2023
2 parents 151dcce + fb4448b commit 9abaef3
Show file tree
Hide file tree
Showing 25 changed files with 33 additions and 64 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['7.2', '7.3', '7.4', '8.0']
php-version: ['7.2', '7.3', '7.4', '8.0', '8.1']
symfony-pkg-version: ['^4.0', '^5.0', '^6.0']
composer-flag:
- '--prefer-dist'
Expand All @@ -21,6 +21,8 @@ jobs:
symfony-pkg-version: '^6.0'
- php-version: '7.4'
symfony-pkg-version: '^6.0'
- php-version: '8.1'
composer-flag: '--prefer-stable --prefer-lowest'
services:
mysql:
image: mysql:5.7
Expand Down Expand Up @@ -53,19 +55,19 @@ jobs:
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
restore-keys: |1
${{ runner.os }}-php-
- name: Install Composer dependencies
run: composer update ${{ matrix.composer-flag }} -W --with symfony/validator:"${{ matrix.symfony-pkg-version }}" --with symfony/event-dispatcher:"${{ matrix.symfony-pkg-version }}" --no-interaction --no-progress

# This may be necessary for older dev packages that do not have
# upper PHP compatibility version constraints.
- name: Update Composer Dev dependencies
run: composer update mockery/mockery --prefer-dist --no-interaction --no-progress
run: composer update phpunit/phpunit mockery/mockery --prefer-dist --no-interaction --no-progress

- name: Run Code Style Check for PHP ${{ matrix.php-version }}
run: composer run-script style-check
if: matrix.php-version != '7.1'
if: matrix.php-version == '8.0'

- name: Run tests for PHP ${{ matrix.php-version }}
run: composer run-script test
Expand All @@ -77,4 +79,4 @@ jobs:
run: vendor/bin/php-coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: success() && matrix.php-version == '7.4' && matrix.composer-flag == '--prefer-dist'
if: success() && matrix.php-version == '8.0' && matrix.composer-flag == '--prefer-dist'
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.0-cli
FROM php:8.1-cli

# system dependecies
RUN apt-get update && apt-get install -y \
Expand All @@ -19,4 +19,4 @@ RUN curl -sS https://getcomposer.org/installer | php \
&& apt-get install git unzip -y
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV XDEBUG_MODE=coverage
WORKDIR /src
WORKDIR /src
1 change: 1 addition & 0 deletions PHPUnit/MySQLTestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ private function connect(string $dsn): \PDO
{
$pdo = new \PDO($dsn, $this->getDatabaseUser(), $this->getDatabasePassword());
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(\PDO::ATTR_STRINGIFY_FETCHES, true);

return $pdo;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"require": {
"php": "7.2 - 8.0",
"php": "7.2 - 8.1",
"ext-PDO": "*",
"ext-pdo_mysql": "*",
"symfony/validator": ">=4.0 <6.2",
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
<directory suffix=".php">./src/</directory>
</include>
</coverage>
</phpunit>
</phpunit>
2 changes: 1 addition & 1 deletion src/Extract/CsvFileExtractor/CsvMultiFileExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function setHeaders(array $headers): void
}
}

public function getIterator()
public function getIterator(): \Traversable
{
$iterator = new \AppendIterator();

Expand Down
1 change: 1 addition & 0 deletions src/Extract/CsvFileExtractor/EnforcePrimaryKeyIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function __construct(\Traversable $iterator, array $primaryKeyFields)
/**
* @throws DuplicatePrimaryKeyValueException
*/
#[\ReturnTypeWillChange]
public function current()
{
$currentRecord = parent::current();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function __construct(\Traversable $iterator, array $uniqueFields)
$this->uniqueFieldValues = array_fill_keys($uniqueFields, []);
}

#[\ReturnTypeWillChange]
public function current()
{
$currentRecord = parent::current();
Expand Down
1 change: 1 addition & 0 deletions src/Extract/CsvFileExtractor/MapIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __construct(\Traversable $iterator, array $headers)
$this->headers = $headers;
}

#[\ReturnTypeWillChange]
public function current()
{
$record = parent::current();
Expand Down
2 changes: 1 addition & 1 deletion src/Extract/DatabaseExtractor/DatabaseExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(\PDO $pdo, string $queryStr, array $queryParams = []
$this->queryParams = $queryParams;
}

public function getIterator(): iterable
public function getIterator(): \Traversable
{
$this->queryStmt->execute($this->queryParams);

Expand Down
3 changes: 0 additions & 3 deletions src/Load/DatabaseLoader/SimpleDeleteStmt.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public function __construct(\PDO $pdo, string $table, array $conditions = [], st
$this->database = $database;
}

/**
* {@inheritdoc}
*/
public function execute(): int
{
$conditionsStr = null;
Expand Down
2 changes: 1 addition & 1 deletion src/SlurpBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function __construct(
$this->factory = $slurpFactory;
}

public static function create(?ConstraintValidatorFactoryInterface $constraintValidatorFactory = null): self
public static function create(ConstraintValidatorFactoryInterface $constraintValidatorFactory = null): self
{
return new static(
new PipelineBuilder(),
Expand Down
2 changes: 1 addition & 1 deletion src/SlurpFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SlurpFactory
*/
private $constraintValidatorFactory;

public function __construct(?ConstraintValidatorFactoryInterface $constraintValidatorFactory = null)
public function __construct(ConstraintValidatorFactoryInterface $constraintValidatorFactory = null)
{
$this->constraintValidatorFactory = $constraintValidatorFactory;
}
Expand Down
2 changes: 1 addition & 1 deletion src/SlurpPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function addViolation(ViolationInterface $violation): void
$this->violations[] = $violation;
}

public function hasViolations(?string $classType = null): bool
public function hasViolations(string $classType = null): bool
{
if (empty($this->violations)) {
return false;
Expand Down
7 changes: 0 additions & 7 deletions src/Transform/SchemaTransformer/SchemaTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public function __construct(Schema $tableSchema)
}

/**
* @param mixed $value
*
* @return mixed
*
* @throws TransformationException
*/
public function transformField(string $field, $value)
Expand Down Expand Up @@ -97,9 +93,6 @@ public function transformRecord(array $record): array
return $record;
}

/**
* @param mixed $name
*/
protected function getField($name): ?BaseField
{
try {
Expand Down
6 changes: 0 additions & 6 deletions src/Validate/ConstraintValidation/ConstraintValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ public function setFieldConstraints(string $field, $constraints): void
$this->fieldConstraints[$field] = $constraints;
}

/**
* {@inheritdoc}
*/
public function validateField(int $recordId, string $field, $value): array
{
$violations = [];
Expand All @@ -64,9 +61,6 @@ public function validateField(int $recordId, string $field, $value): array
return $violations;
}

/**
* {@inheritdoc}
*/
public function validateRecord(int $recordId, array $record): array
{
$violations = [];
Expand Down
3 changes: 0 additions & 3 deletions src/Validate/FieldViolation.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ class FieldViolation implements ViolationInterface
*/
private $field;

/**
* @var mixed
*/
private $value;

/**
Expand Down
6 changes: 0 additions & 6 deletions src/Validate/SchemaValidation/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ public function __construct(Schema $tableSchema)
$this->tableSchema = $tableSchema;
}

/**
* {@inheritdoc}
*/
public function validateField(int $recordId, string $field, $value): array
{
$violations = [];
Expand All @@ -74,9 +71,6 @@ public function validateField(int $recordId, string $field, $value): array
return $violations;
}

/**
* {@inheritdoc}
*/
public function validateRecord(int $recordId, array $record): array
{
$violations = [];
Expand Down
2 changes: 0 additions & 2 deletions src/Validate/ValidatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
interface ValidatorInterface
{
/**
* @param mixed $value
*
* @return ViolationInterface[]
*/
public function validateField(int $recordId, string $field, $value): array;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class VerifyValueCountIteratorTest extends TestCase
{
/**
* @dataProvider getValueCountMismatchTestData
* @dataProvider provideValueCountMismatchTestData
*
* @throws ValueCountMismatchException
*/
Expand All @@ -45,7 +45,7 @@ public function testValueCountMismatch(array $values, int $expectedCount): void
$iterator->current();
}

public function getValueCountMismatchTestData(): array
public static function provideValueCountMismatchTestData(): array
{
return [
[[123, 234], 1],
Expand Down
4 changes: 2 additions & 2 deletions tests/Slurp/Load/DatabaseLoader/StagedLoadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function setUp(): void
}

/**
* @dataProvider getTableRefsForBeginCommitTest
* @dataProvider provideTableRefsForBeginCommitTest
*
* @throws LogicException
*/
Expand Down Expand Up @@ -89,7 +89,7 @@ static function ($sql) use (&$capturedSql) {
);
}

public function getTableRefsForBeginCommitTest(): array
public static function provideTableRefsForBeginCommitTest(): array
{
return [
['my_tbl', null, '`my_tbl`', '`_my_tbl_stage`'],
Expand Down
1 change: 1 addition & 0 deletions tests/Slurp/OuterPipeline/ExtractionStageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public function __construct(array $rows, int $exceptionAtCount, string $exceptio
parent::__construct(new \ArrayObject($rows));
}

#[\ReturnTypeWillChange]
public function current()
{
if ($this->key() !== $this->exceptionAtCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class UnexpectedTypeExceptionTest extends TestCase
{
/**
* @dataProvider getConstructorArgs
* @dataProvider provideConstructorArgs
*/
public function testConstructMessage($value, $expectedType, $expectedMessage): void
{
Expand All @@ -28,7 +28,7 @@ public function testConstructMessage($value, $expectedType, $expectedMessage): v
$this->assertSame($expectedMessage, $e->getMessage());
}

public function getConstructorArgs(): array
public static function provideConstructorArgs(): array
{
return [
['foo', \stdClass::class, 'Expected argument of type "stdClass", "string" given'],
Expand Down
17 changes: 2 additions & 15 deletions tests/Slurp/Transform/SchemaTransformer/SchemaTransformerTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
<?php

/**
* @author Courtney Miles
*
* @see https://github.com/courtney-miles/slurp
*
* @package milesasylum/slurp
*
* @license MIT
*/

declare(strict_types=1);

namespace MilesAsylum\Slurp\Tests\Slurp\Transform\SchemaTransformer;
Expand Down Expand Up @@ -65,10 +55,7 @@ public function testTransformRecord(): void
}

/**
* @dataProvider getComplexTypeConversionTestData
*
* @param mixed $complexValue
* @param mixed $scalarValue
* @dataProvider provideComplexTypeConversionTestData
*
* @throws TransformationException
*/
Expand All @@ -89,7 +76,7 @@ public function testConvertComplexTypeBackToScalar(string $fieldClass, $complexV
);
}

public function getComplexTypeConversionTestData(): array
public static function provideComplexTypeConversionTestData(): array
{
return [
[TimeField::class, [12, 23, 34], '12:23:34'],
Expand Down
6 changes: 4 additions & 2 deletions tests/Slurp/Transform/SlurpTransformer/TransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ public function testTransformUndefinedField(): void
);
}

/**
* @requires PHPUnit < 10.0.0
*/
public function testTransformUndefinedFieldTriggersWarning(): void
{
$this->expectWarning();
$this->expectExceptionMessage(
'Unable to apply transformation for field \'bar\'. The supplied record did not contain this field.'
)
;
);

$mockChange = \Mockery::mock(Change::class);
$mockChangeTransformer = \Mockery::mock(ChangeTransformerInterface::class);
Expand Down

0 comments on commit 9abaef3

Please sign in to comment.