Skip to content
Merged
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
53 changes: 53 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Test

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
strategy:
matrix:
php-versions: [ '7.4', '8.0', '8.1' ]
include:
- php-versions: '7.4'
coverage: pcov
composer-prefer: '--prefer-lowest --prefer-stable'
phpunit-flags: '--coverage-clover coverage.xml'

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: ${{ matrix.coverage }}

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-composer-${{ matrix.composer-prefer }}$-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-${{ matrix.composer-prefer }}-

- name: Install dependencies
run: composer update --prefer-dist --no-progress --ignore-platform-req="ext-*" ${{ matrix.composer-prefer }}

- name: Run test suite
run: vendor/bin/phpunit ${{ matrix.phpunit-flags }}

- name: Upload coverage
if: matrix.coverage
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.xml --revision=${{ github.event.pull_request.head.sha || github.sha }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ vendor/
composer.phar
composer.lock
phpunit.xml
.phpunit.cache
coverage.xml
38 changes: 0 additions & 38 deletions .travis.yml

This file was deleted.

10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
"docs": "https://portphp.readthedocs.org"
},
"require": {
"php": ">=5.6.0",
"php": ">=7.4",
"portphp/portphp": "^1.0.0",
"doctrine/common": "^2.13 || ^3.0"
},
"require-dev": {
"phpunit/phpunit": "^5.2",
"phpunit/phpunit": "^9.5",
"ext-sqlite3": "*",
"doctrine/orm": "~2.8",
"doctrine/mongodb-odm": "^2.0",
"doctrine/cache": "^1.11"
"doctrine/cache": "^1.11",
"doctrine/orm": "^2.8",
"doctrine/mongodb-odm": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
33 changes: 19 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
verbose="true"
>
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="false"
beStrictAboutOutputDuringTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="portphp/doctrine">
<directory suffix=".php">./tests/</directory>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
24 changes: 6 additions & 18 deletions src/DoctrineReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,41 +70,32 @@ public function getFields()
}

/**
* {@inheritdoc}
* @return mixed
*/
public function current()
{
return current($this->iterableResult->current());
}

/**
* {@inheritdoc}
*/
public function next()
public function next(): void
{
$this->iterableResult->next();
}

/**
* {@inheritdoc}
* @return mixed
*/
public function key()
{
return $this->iterableResult->key();
}

/**
* {@inheritdoc}
*/
public function valid()
public function valid(): bool
{
return $this->iterableResult->valid();
}

/**
* {@inheritdoc}
*/
public function rewind()
public function rewind(): void
{
if (!$this->iterableResult) {
$query = $this->getQueryBuilder()->select('o')->getQuery();
Expand All @@ -115,10 +106,7 @@ public function rewind()
$this->iterableResult->rewind();
}

/**
* {@inheritdoc}
*/
public function count()
public function count(): int
{
$query = $this->getQueryBuilder()->select('count(o)')->getQuery();

Expand Down
2 changes: 1 addition & 1 deletion src/DoctrineReaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Port\Doctrine;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectManager;

/**
* Factory that creates DoctrineReaders
Expand Down
23 changes: 14 additions & 9 deletions src/DoctrineWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace Port\Doctrine;

use Doctrine\DBAL\Logging\SQLLogger;
use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectRepository;
use Port\Doctrine\Exception\UnsupportedDatabaseTypeException;
use Port\Writer;
use Doctrine\Inflector\Inflector;
use Doctrine\DBAL\Logging\SQLLogger;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Persistence\Mapping\ClassMetadata;

/**
* A bulk Doctrine writer
Expand Down Expand Up @@ -74,6 +76,8 @@ class DoctrineWriter implements Writer, Writer\FlushableWriter
*/
protected $lookupMethod;

private Inflector $inflector;

/**
* Constructor
*
Expand Down Expand Up @@ -112,6 +116,7 @@ public function __construct(
);
}
$this->lookupMethod = [$this->objectRepository, $lookupMethod];
$this->inflector = InflectorFactory::create()->build();
}

/**
Expand Down Expand Up @@ -232,7 +237,7 @@ protected function updateObject(array $item, $object)
$fieldNames = array_merge($this->objectMetadata->getFieldNames(), $this->objectMetadata->getAssociationNames());
foreach ($fieldNames as $fieldName) {
$value = null;
$classifiedFieldName = Inflector::classify($fieldName);
$classifiedFieldName = $this->inflector->classify($fieldName);
if (isset($item[$fieldName])) {
$value = $item[$fieldName];
}
Expand Down Expand Up @@ -284,8 +289,8 @@ protected function truncateTable()
$connection = $this->objectManager->getConnection();
$query = $connection->getDatabasePlatform()->getTruncateTableSQL($tableName, true);
$connection->executeQuery($query);
} elseif ($this->objectManager instanceof \Doctrine\ODM\MongoDB\DocumentManager) {
$this->objectManager->getDocumentCollection($this->objectName)->remove(array());
} elseif ($this->objectManager instanceof DocumentManager) {
$this->objectManager->getDocumentCollection($this->objectName)->deleteMany([]);
}
}

Expand Down Expand Up @@ -326,7 +331,7 @@ protected function findOrCreateItem(array $item)
// first
if (!$this->truncate) {
if (!empty($this->lookupFields)) {
$lookupConditions = array();
$lookupConditions = [];
foreach ($this->lookupFields as $fieldName) {
$lookupConditions[$fieldName] = $item[$fieldName];
}
Expand All @@ -347,7 +352,7 @@ protected function findOrCreateItem(array $item)
protected function ensureSupportedObjectManager(ObjectManager $objectManager)
{
if (!($objectManager instanceof \Doctrine\ORM\EntityManager
|| $objectManager instanceof \Doctrine\ODM\MongoDB\DocumentManager)
|| $objectManager instanceof DocumentManager)
) {
throw new UnsupportedDatabaseTypeException($objectManager);
}
Expand Down
25 changes: 13 additions & 12 deletions tests/DoctrineReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

namespace Port\Doctrine\Tests;

use PHPUnit\Framework\TestCase;
use Port\Doctrine\DoctrineReader;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Setup;
use Port\Doctrine\Tests\Fixtures\Entity\User;

class DoctrineReaderTest extends \PHPUnit_Framework_TestCase
class DoctrineReaderTest extends TestCase
{
public function testGetFields()
{
$fields = $this->getReader()->getFields();
$this->assertInternalType('array', $fields);
$this->assertEquals(array('id', 'username'), $fields);
$this->assertIsArray($fields);
$this->assertEquals(['id', 'username'], $fields);
}

public function testCount()
Expand All @@ -25,7 +26,7 @@ public function testIterate()
{
$i = 1;
foreach ($this->getReader() as $data) {
$this->assertInternalType('array', $data);
$this->assertIsArray($data);
$this->assertEquals('user' . $i, $data['username']);
$i++;
}
Expand All @@ -43,27 +44,27 @@ protected function getReader()

$em->flush();

return new DoctrineReader($em, 'Port\Doctrine\Tests\Fixtures\Entity\User');
return new DoctrineReader($em, User::class);
}

protected function getEntityManager()
{
$dbParams = array(
$dbParams = [
'driver' => 'pdo_sqlite',
);
];

$paths = array(
$paths = [
__DIR__.'/../Fixtures/Entity'
);
];

$config = Setup::createAnnotationMetadataConfiguration($paths, true);
$em = EntityManager::create($dbParams, $config);

$schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
$schemaTool->createSchema(
array(
$em->getMetadataFactory()->getMetadataFor('Port\Doctrine\Tests\Fixtures\Entity\User')
)
[
$em->getMetadataFactory()->getMetadataFor(User::class)
]
);

return $em;
Expand Down
Loading