diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a6aa1f4 --- /dev/null +++ b/.travis.yml @@ -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 \ No newline at end of file diff --git a/composer.json b/composer.json index e658475..8246640 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,6 @@ }, "minimum-stability": "alpha", "require-dev": { - "phpunit/phpunit": "7.2.7" + "phpunit/phpunit": "9.2.6" } } \ No newline at end of file diff --git a/src/SixDreams/Bulk/AbstractBulk.php b/src/SixDreams/Bulk/AbstractBulk.php index e85e8c4..fc9cc31 100644 --- a/src/SixDreams/Bulk/AbstractBulk.php +++ b/src/SixDreams/Bulk/AbstractBulk.php @@ -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; @@ -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( @@ -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(); diff --git a/src/SixDreams/Bulk/BulkUpdate.php b/src/SixDreams/Bulk/BulkUpdate.php index 6593449..ae2da43 100644 --- a/src/SixDreams/Bulk/BulkUpdate.php +++ b/src/SixDreams/Bulk/BulkUpdate.php @@ -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; @@ -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'; diff --git a/src/SixDreams/DTO/AbstractColumnMetadata.php b/src/SixDreams/DTO/AbstractColumnMetadata.php index ca3afb9..52d588e 100644 --- a/src/SixDreams/DTO/AbstractColumnMetadata.php +++ b/src/SixDreams/DTO/AbstractColumnMetadata.php @@ -6,7 +6,7 @@ /** * Contains information about table column. */ -abstract class AbstractColumnMetadata +abstract class AbstractColumnMetadata implements ColumnMetadataInterface { /** @var string */ private $name; diff --git a/src/SixDreams/DTO/ColumnMetadataInterface.php b/src/SixDreams/DTO/ColumnMetadataInterface.php new file mode 100644 index 0000000..cc92a60 --- /dev/null +++ b/src/SixDreams/DTO/ColumnMetadataInterface.php @@ -0,0 +1,31 @@ +fields[$field] = $column; @@ -75,7 +74,7 @@ public function addField(string $field, AbstractColumnMetadata $column): Metadat /** * Getter for Fields * - * @return AbstractColumnMetadata[] + * @return ColumnMetadataInterface[] */ public function getFields(): array { @@ -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]; } diff --git a/tests/InsertTest.php b/tests/InsertTest.php index b6b582c..171781f 100644 --- a/tests/InsertTest.php +++ b/tests/InsertTest.php @@ -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') ); diff --git a/tests/UpdateTest.php b/tests/UpdateTest.php index e7d3f89..ae9cef5 100644 --- a/tests/UpdateTest.php +++ b/tests/UpdateTest.php @@ -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); } @@ -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()) @@ -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())