Skip to content

Commit

Permalink
bugfixes for run successful tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avolver committed Aug 2, 2020
1 parent 98e94af commit 91c01e1
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 31 deletions.
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
language: php
dist: bionic

cache:
directories:
- vendor
- $HOME/.composer/cache

before_install:
- phpenv config-rm xdebug.ini || true

install:
- travis_retry composer -n install --prefer-dist

script:
- ./vendor/bin/phpunit --configuration phpunit.build.xml

jobs:
include:
- stage: Test
php: 7.4
- stage: Test
php: 7.2

allow_failures:
- env: DEPENDENCIES=dev
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
},
"minimum-stability": "alpha",
"require-dev": {
"phpunit/phpunit": "7.2.7"
"phpunit/phpunit": "9.2.6"
}
}
23 changes: 11 additions & 12 deletions src/SixDreams/Bulk/AbstractBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
namespace SixDreams\Bulk;

use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Schema\Identifier;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\EntityManagerInterface;
use SixDreams\DTO\AbstractColumnMetadata;
use SixDreams\DTO\ColumnMetadataInterface;
use SixDreams\DTO\JoinColumnMetadata;
use SixDreams\DTO\Metadata;
use SixDreams\Exceptions\FieldNotFoundException;
Expand Down Expand Up @@ -94,14 +93,14 @@ protected function getAllUsedFields(array &$values): array
/**
* Bind value to statement.
*
* @param Statement $statement
* @param int|string $index
* @param AbstractColumnMetadata $column
* @param mixed $value
* @param Statement $statement
* @param int|string $index
* @param ColumnMetadataInterface $column
* @param mixed $value
*/
protected function bind(Statement $statement, $index, AbstractColumnMetadata $column, $value): void
protected function bind(Statement $statement, $index, ColumnMetadataInterface $column, $value): void
{
$type = ParameterType::STRING;
$type = \PDO::PARAM_STR;
if (Type::hasType($column->getType())) {
$type = Type::getType($column->getType());
$value = $type->convertToDatabaseValue(
Expand All @@ -117,15 +116,15 @@ protected function bind(Statement $statement, $index, AbstractColumnMetadata $co
/**
* Extract joined entity value, if entity is really joined.
*
* @param AbstractColumnMetadata $column
* @param object|null $value
* @param string $field
* @param ColumnMetadataInterface $column
* @param object|null $value
* @param string $field
*
* @return mixed
*
* @throws FieldNotFoundException
*/
protected function getJoinedEntityValue(AbstractColumnMetadata $column, $value, string $field)
protected function getJoinedEntityValue(ColumnMetadataInterface $column, $value, string $field)
{
if (($column instanceof JoinColumnMetadata) && null !== $value && \is_object($value)) {
$subPropName = $field . '.' . $column->getReferenced();
Expand Down
9 changes: 5 additions & 4 deletions src/SixDreams/Bulk/BulkUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\EntityManagerInterface;
use SixDreams\DTO\ColumnMetadata;
use SixDreams\DTO\ColumnMetadataInterface;
use SixDreams\Exceptions\CannotChangeWhereException;
use SixDreams\Exceptions\FieldNotFoundException;
use SixDreams\Exceptions\NullValueException;
Expand Down Expand Up @@ -247,13 +248,13 @@ public function getSQL(): array
* Check is value is simple (float, int, null) and return it's representation in SQL, otherwise return null (marker
* that value require binding).
*
* @param mixed $value
* @param AbstractPlatform $platform
* @param ColumnMetadata $metadata
* @param mixed $value
* @param AbstractPlatform $platform
* @param ColumnMetadataInterface|null $metadata
*
* @return float|int|string|null
*/
protected function simpleValue($value, AbstractPlatform $platform, ?ColumnMetadata $metadata = null)
protected function simpleValue($value, AbstractPlatform $platform, ?ColumnMetadataInterface $metadata = null)
{
if ($metadata && $platform->getName() === 'postgresql' && $metadata->getType() === Type::BOOLEAN) {
return $value ? 'true' : 'false';
Expand Down
2 changes: 1 addition & 1 deletion src/SixDreams/DTO/AbstractColumnMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Contains information about table column.
*/
abstract class AbstractColumnMetadata
abstract class AbstractColumnMetadata implements ColumnMetadataInterface
{
/** @var string */
private $name;
Expand Down
31 changes: 31 additions & 0 deletions src/SixDreams/DTO/ColumnMetadataInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);

namespace SixDreams\DTO;

/**
* Contains information about table column.
*/
interface ColumnMetadataInterface
{
/**
* Returns column name.
*
* @return string
*/
public function getName(): string;

/**
* Return true, if column has active nullable flag.
*
* @return bool
*/
public function isNullable(): bool;

/**
* Returns column type.
*
* @return string
*/
public function getType(): string;
}
15 changes: 7 additions & 8 deletions src/SixDreams/DTO/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace SixDreams\DTO;

use Doctrine\ORM\Id\AbstractIdGenerator;
use SixDreams\Generator\BulkGeneratorInterface;

/**
Expand All @@ -14,7 +13,7 @@ final class Metadata
/** @var string */
private $table;

/** @var AbstractColumnMetadata[] */
/** @var ColumnMetadataInterface[] */
private $fields = [];

/** @var string */
Expand All @@ -26,7 +25,7 @@ final class Metadata
/**
* MetadataDto constructor.
*
* @param string $table
* @param string|null $table
*/
public function __construct(?string $table = null)
{
Expand Down Expand Up @@ -61,11 +60,11 @@ public function setTable(string $table): Metadata
* Add column.
*
* @param string $field
* @param AbstractColumnMetadata $column
* @param ColumnMetadataInterface $column
*
* @return Metadata
*/
public function addField(string $field, AbstractColumnMetadata $column): Metadata
public function addField(string $field, ColumnMetadataInterface $column): Metadata
{
$this->fields[$field] = $column;

Expand All @@ -75,7 +74,7 @@ public function addField(string $field, AbstractColumnMetadata $column): Metadat
/**
* Getter for Fields
*
* @return AbstractColumnMetadata[]
* @return ColumnMetadataInterface[]
*/
public function getFields(): array
{
Expand All @@ -99,9 +98,9 @@ public function hasField(string $name): bool
*
* @param string $name
*
* @return AbstractColumnMetadata
* @return ColumnMetadataInterface
*/
public function getField(string $name): AbstractColumnMetadata
public function getField(string $name): ColumnMetadataInterface
{
return $this->fields[$name];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/InsertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testEntity(): void
$bulk = new BulkInsert($manager, Author::class);
$bulk->addEntity((new Author())->setFullName('full namez')->setOtherData('random stuff'));
self::assertEquals(
[['id' => null, 'fullName' => 'full namez', 'otherData' => 'random stuff']],
[['id' => 'akwkorfmq0w0kg8scsgsos4c0', 'fullName' => 'full namez', 'otherData' => 'random stuff']],
$this->extractField($bulk, 'values')
);

Expand Down
8 changes: 4 additions & 4 deletions tests/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testShortEntity(): void
->addEntity((new Book())->setId(123)->setTitle('test'), ['title'])
->getSQL();

self::assertEquals('UPDATE book SET title = (WHEN 123 THEN :T0) WHERE id IN (123);', $query);
self::assertEquals('UPDATE book SET title = CASE WHEN id = 123 THEN :T0 END WHERE id IN (123);', $query);
self::assertCount(1, $bind);
}

Expand All @@ -63,7 +63,7 @@ public function provider(): array
{
return [
[
'UPDATE book SET title = (WHEN 123 THEN :T0 WHEN 333 THEN :T3), SET short_text = (WHEN 123 THEN NULL WHEN 333 THEN short_text), SET author_id = (WHEN 123 THEN NULL WHEN 333 THEN 1) WHERE id IN (123, 333);',
'UPDATE book SET title = CASE WHEN id = 123 THEN :T0 WHEN id = 333 THEN :T3 END, short_text = CASE WHEN id = 123 THEN NULL WHEN id = 333 THEN short_text END, author_id = CASE WHEN id = 123 THEN NULL WHEN id = 333 THEN 1 END WHERE id IN (123, 333);',
2,
[
123 => (new Book())
Expand All @@ -76,12 +76,12 @@ public function provider(): array
]
],
[
'UPDATE book SET title = (WHEN 123 THEN :T0), SET short_text = (WHEN 123 THEN NULL), SET author_id = (WHEN 123 THEN :T2) WHERE id IN (123);',
'UPDATE book SET title = CASE WHEN id = 123 THEN :T0 END, short_text = CASE WHEN id = 123 THEN NULL END, author_id = CASE WHEN id = 123 THEN :T2 END WHERE id IN (123);',
2,
[
123 => [
'title' => 'Overwrite',
'author' => 666,
'author' => 32770,
'shortText' => 'ddd'
],
333 => (new Book())
Expand Down

0 comments on commit 91c01e1

Please sign in to comment.