Skip to content

Commit

Permalink
Merge branch 'master' into select-count
Browse files Browse the repository at this point in the history
  • Loading branch information
hustlahusky committed Dec 7, 2021
2 parents b7ea9a9 + 4018f8a commit e3099fd
Show file tree
Hide file tree
Showing 19 changed files with 591 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
key: ${{ env.key }}

- name: Cache extensions
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
Expand All @@ -70,7 +70,7 @@ jobs:
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-pgsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
key: ${{ env.key }}

- name: Cache extensions
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
Expand All @@ -73,7 +73,7 @@ jobs:
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }}
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Restore Composer Cache
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand All @@ -23,10 +23,11 @@ jobs:
- name: Check CS
run: vendor/bin/spiral-cs check src tests
test:
needs: lint
needs: sqlite
name: Test PHP ${{ matrix.php-versions }} with Code Coverage
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0']
steps:
Expand All @@ -48,7 +49,7 @@ jobs:
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Restore Composer Cache
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand All @@ -66,10 +67,10 @@ jobs:
file: ./coverage.xml

sqlite:
needs: lint
name: SQLite PHP ${{ matrix.php-versions }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0']
steps:
Expand All @@ -86,7 +87,7 @@ jobs:
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Restore Composer Cache
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand Down
38 changes: 26 additions & 12 deletions src/ORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,12 @@ public function make(string $role, array $data = [], int $node = Node::NEW)
}

/**
* @inheritdoc
* @deprecated since Cycle ORM v1.8, this method will be removed in future releases.
* Use method {@see with} instead.
*/
public function withFactory(FactoryInterface $factory): ORMInterface
{
$orm = clone $this;
$orm->factory = $factory;

return $orm;
return $this->with(null, $factory);
}

/**
Expand All @@ -199,14 +197,12 @@ public function getFactory(): FactoryInterface
}

/**
* @inheritdoc
* @deprecated since Cycle ORM v1.8, this method will be removed in future releases.
* Use method {@see with} instead.
*/
public function withSchema(SchemaInterface $schema): ORMInterface
{
$orm = clone $this;
$orm->schema = $schema;

return $orm;
return $this->with($schema);
}

/**
Expand All @@ -222,12 +218,30 @@ public function getSchema(): SchemaInterface
}

/**
* @inheritdoc
* @deprecated since Cycle ORM v1.8, this method will be removed in future releases.
* Use method {@see with} instead.
*/
public function withHeap(HeapInterface $heap): ORMInterface
{
return $this->with(null, null, $heap);
}

public function with(
?SchemaInterface $schema = null,
?FactoryInterface $factory = null,
?HeapInterface $heap = null
): ORMInterface {
$orm = clone $this;
$orm->heap = $heap;

if ($schema !== null) {
$orm->schema = $schema;
}
if ($factory !== null) {
$orm->factory = $factory;
}
if ($heap !== null) {
$orm->heap = $heap;
}

return $orm;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ protected function normalize(array $schema): array
$aliases[$item[self::ENTITY]] = $role;
}

// Single Table Inheritance marker
if (isset($item[self::CHILDREN]) && !isset($item[self::COLUMNS]['_type'])) {
$item[self::COLUMNS]['_type'] = '_type';
}

unset($item[self::ROLE]);
$result[$role] = $item;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Select/ScopeInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

// phpcs:ignoreFile

declare(strict_types=1);

namespace Cycle\ORM\Select;
Expand All @@ -14,3 +16,5 @@ interface ScopeInterface
*/
public function apply(QueryBuilder $query);
}

interface_exists(ConstrainInterface::class);
10 changes: 10 additions & 0 deletions tests/ORM/Driver/MySQL/TableInheritanceWithoutTypeColumnTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;

class TableInheritanceWithoutTypeColumnTest extends \Cycle\ORM\Tests\TableInheritanceWithoutTypeColumnTest
{
public const DRIVER = 'mysql';
}
10 changes: 10 additions & 0 deletions tests/ORM/Driver/MySQL/TransactionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\MySQL;

class TransactionTest extends \Cycle\ORM\Tests\TransactionTest
{
public const DRIVER = 'mysql';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\Postgres;

class TableInheritanceWithoutTypeColumnTest extends \Cycle\ORM\Tests\TableInheritanceWithoutTypeColumnTest
{
public const DRIVER = 'postgres';
}
10 changes: 10 additions & 0 deletions tests/ORM/Driver/Postgres/TransactionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\Postgres;

class TransactionTest extends \Cycle\ORM\Tests\TransactionTest
{
public const DRIVER = 'postgres';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\SQLServer;

class TableInheritanceWithoutTypeColumnTest extends \Cycle\ORM\Tests\TableInheritanceWithoutTypeColumnTest
{
public const DRIVER = 'sqlserver';
}
10 changes: 10 additions & 0 deletions tests/ORM/Driver/SQLServer/TransactionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\SQLServer;

class TransactionTest extends \Cycle\ORM\Tests\TransactionTest
{
public const DRIVER = 'sqlserver';
}
10 changes: 10 additions & 0 deletions tests/ORM/Driver/SQLite/TableInheritanceWithoutTypeColumnTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\SQLite;

class TableInheritanceWithoutTypeColumnTest extends \Cycle\ORM\Tests\TableInheritanceWithoutTypeColumnTest
{
public const DRIVER = 'sqlite';
}
10 changes: 10 additions & 0 deletions tests/ORM/Driver/SQLite/TransactionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Driver\SQLite;

class TransactionTest extends \Cycle\ORM\Tests\TransactionTest
{
public const DRIVER = 'sqlite';
}
45 changes: 45 additions & 0 deletions tests/ORM/Fixtures/TransactionTestMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Fixtures;

use Cycle\ORM\Command\CommandInterface;
use Cycle\ORM\Heap\Node;
use Cycle\ORM\Heap\State;
use Cycle\ORM\Mapper\Mapper;

class TransactionTestMapper extends Mapper
{
public function queueDelete($entity, Node $node, State $state): CommandInterface
{
if ($entity->id == '3') {
return new class () implements CommandInterface {
public function isReady(): bool
{
return true;
}

public function isExecuted(): bool
{
return false;
}

public function execute()
{
throw new \Exception('Something went wrong');
}

public function complete()
{
}

public function rollBack()
{
}
};
}

return parent::queueDelete($entity, $node, $state);
}
}
26 changes: 26 additions & 0 deletions tests/ORM/ORMTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Cycle\ORM\Tests;

use Cycle\ORM\Factory;
use Cycle\ORM\Heap\Heap;
use Cycle\ORM\Mapper\Mapper;
use Cycle\ORM\Schema;
use Cycle\ORM\Tests\Fixtures\User;
Expand Down Expand Up @@ -70,6 +72,30 @@ public function testORMClone(): void
$this->assertNotSame($orm, $this->orm);
}

public function testORMCloneWithSchema(): void
{
$orm = $this->orm->with(new Schema([]));

$this->assertNotSame($orm, $this->orm);
$this->assertNotSame($orm->getSchema(), $this->orm->getSchema());
}

public function testORMCloneWithFactory(): void
{
$orm = $this->orm->with(null, new Factory($this->dbal));

$this->assertNotSame($orm, $this->orm);
$this->assertNotSame($orm->getFactory(), $this->orm->getFactory());
}

public function testORMCloneWithHeap(): void
{
$orm = $this->orm->with(null, null, new Heap());

$this->assertNotSame($orm, $this->orm);
$this->assertNotSame($orm->getHeap(), $this->orm->getHeap());
}

public function testORMGetByRole(): void
{
$this->assertNull($this->orm->get('user', ['id' => 1], false));
Expand Down
Loading

0 comments on commit e3099fd

Please sign in to comment.