Skip to content

Commit 0b65906

Browse files
authored
Merge pull request #512: fix #511
2 parents d100182 + 9e745d0 commit 0b65906

File tree

14 files changed

+479
-47
lines changed

14 files changed

+479
-47
lines changed

.github/workflows/main.yml

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,44 +28,41 @@ jobs:
2828
run: |
2929
sudo curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
3030
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
31-
- name: Checkout
31+
32+
- name: 📦 Checkout
3233
uses: actions/checkout@v2
33-
- name: Setup DB services
34+
- name: 🛠️ Setup DB services
3435
run: |
3536
cd tests
3637
docker compose up -d
3738
cd ..
38-
- name: Setup PHP ${{ matrix.php-version }}
39+
- name: 🛠️ Setup PHP ${{ matrix.php-versions }}
3940
uses: shivammathur/setup-php@v2
4041
with:
41-
php-version: ${{ matrix.php-version }}
42+
php-version: ${{ matrix.php-versions }}
4243
coverage: pcov
4344
tools: pecl
4445
extensions: mbstring, pdo, pdo_sqlite, pdo_pgsql, pdo_sqlsrv, pdo_mysql
45-
- name: Get Composer Cache Directory
46-
id: composer-cache
47-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
48-
- name: Restore Composer Cache
49-
uses: actions/cache@v2
46+
47+
- name: 🤖 Validate composer.json and composer.lock
48+
run: composer validate --ansi --strict
49+
50+
- name: 📥 Install dependencies with composer
51+
uses: ramsey/composer-install@v3
5052
with:
51-
path: ${{ steps.composer-cache.outputs.dir }}
52-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
53-
restore-keys: ${{ runner.os }}-composer-
54-
- name: Install dependencies with composer
55-
if: matrix.php-version != '8.4'
56-
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
57-
- name: Install dependencies with composer php 8.4
58-
if: matrix.php-version == '8.4'
59-
run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
60-
- name: Execute Tests
53+
dependency-versions: "highest"
54+
55+
- name: 🚀 Execute Tests
6156
run: |
6257
vendor/bin/phpunit --coverage-clover=coverage.clover
58+
6359
- name: Upload coverage to Codecov
6460
continue-on-error: true # if is fork
6561
uses: codecov/codecov-action@v1
6662
with:
6763
token: ${{ secrets.CODECOV_TOKEN }}
6864
file: ./coverage.clover
65+
6966
- name: Upload coverage to Scrutinizer
7067
continue-on-error: true # if is fork
7168
uses: sudo-bot/action-scrutinizer@latest
@@ -88,34 +85,30 @@ jobs:
8885
- "8.3"
8986
- "8.4"
9087
steps:
91-
- name: Checkout
88+
- name: 📦 Checkout
9289
uses: actions/checkout@v2
93-
- name: Setup PHP ${{ matrix.php-version }}
90+
- name: 🛠️ Setup DB services
91+
run: |
92+
cd tests
93+
docker compose up -d
94+
cd ..
95+
- name: 🛠️ Setup PHP ${{ matrix.php-versions }}
9496
uses: shivammathur/setup-php@v2
9597
with:
96-
php-version: ${{ matrix.php-version }}
98+
php-version: ${{ matrix.php-versions }}
9799
coverage: pcov
98100
tools: pecl
99-
extensions: mbstring, pdo, pdo_sqlite
100-
- name: Get Composer Cache Directory
101-
id: composer-cache
102-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
103-
- name: Restore Composer Cache
104-
uses: actions/cache@v2
105-
with:
106-
path: ${{ steps.composer-cache.outputs.dir }}
107-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
108-
restore-keys: ${{ runner.os }}-composer-
101+
extensions: mbstring, pdo, pdo_sqlite, pdo_pgsql, pdo_sqlsrv, pdo_mysql
109102

110-
- name: Install dependencies with composer
111-
if: matrix.php-version != '8.4'
112-
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
103+
- name: 🤖 Validate composer.json and composer.lock
104+
run: composer validate --ansi --strict
113105

114-
- name: Install dependencies with composer php 8.4
115-
if: matrix.php-version == '8.4'
116-
run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
106+
- name: 📥 Install dependencies with composer
107+
uses: ramsey/composer-install@v3
108+
with:
109+
dependency-versions: "highest"
117110

118-
- name: Execute Tests
111+
- name: 🚀 Execute Tests
119112
env:
120113
DB: sqlite
121114
run: |

psalm-baseline.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="6.8.8@1361cd33008feb3ae2b4a93f1860e14e538ec8c2">
2+
<files psalm-version="6.10.0@9c0add4eb88d4b169ac04acb7c679918cbb9c252">
33
<file src="src/Collection/ArrayCollectionFactory.php">
44
<DocblockTypeContradiction>
55
<code><![CDATA[throw new CollectionFactoryException('Unsupported iterable type.')]]></code>
@@ -2162,9 +2162,6 @@
21622162
<DocblockTypeContradiction>
21632163
<code><![CDATA[$compareCallback === null]]></code>
21642164
</DocblockTypeContradiction>
2165-
<InvalidOperand>
2166-
<code><![CDATA[$roleName]]></code>
2167-
</InvalidOperand>
21682165
<MissingOverrideAttribute>
21692166
<code><![CDATA[public function define(string $role, int $property): mixed]]></code>
21702167
<code><![CDATA[public function defineRelation(string $role, string $relation): array]]></code>

src/Parser/AbstractNode.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ abstract class AbstractNode
5252

5353
protected ?ParentMergeNode $mergeParent = null;
5454

55-
/** @var SubclassMergeNode[] */
55+
/** @var SubclassMergeNode[] */
5656
protected array $mergeSubclass = [];
5757

5858
protected ?string $indexName;
@@ -65,7 +65,7 @@ abstract class AbstractNode
6565
protected ?MultiKeyCollection $indexedData = null;
6666

6767
/**
68-
* @param string[] $columns List of columns node must fetch from the row.
68+
* @param string[] $columns List of columns node must fetch from the row.
6969
* When columns are empty original line will be returned as result.
7070
* @param string[]|null $outerKeys Defines column name in parent Node to be aggregated.
7171
*/
@@ -95,11 +95,13 @@ public function parseRow(int $offset, array $row): int
9595
);
9696

9797
if ($this->isEmptyPrimaryKey($data)) {
98-
// Skip all columns which are related to current node and sub nodes.
98+
// Skip all columns that are related to current node and sub nodes.
9999
return \count($this->columns)
100100
+ \array_reduce(
101101
$relatedNodes,
102-
static fn(int $cnt, AbstractNode $node): int => $cnt + \count($node->columns),
102+
static fn(int $cnt, AbstractNode $node): int => $node::class === ArrayNode::class
103+
? 0
104+
: $cnt + \count($node->columns),
103105
0,
104106
);
105107
}
@@ -389,6 +391,7 @@ protected function intersectData(array $keys, array $data): array
389391
foreach ($keys as $key) {
390392
$result[$key] = $data[$key];
391393
}
394+
392395
return $result;
393396
}
394397

@@ -404,6 +407,7 @@ private function isEmptyPrimaryKey(array $data): bool
404407
return true;
405408
}
406409
}
410+
407411
return false;
408412
}
409413
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Issue511;
6+
7+
use Cycle\ORM\Select;
8+
use Cycle\ORM\Tests\Functional\Driver\Common\BaseTest;
9+
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\IntegrationTestTrait;
10+
use Cycle\ORM\Tests\Traits\TableTrait;
11+
12+
/**
13+
* @link https://github.com/cycle/orm/issues/511
14+
*/
15+
abstract class CaseTest extends BaseTest
16+
{
17+
use IntegrationTestTrait;
18+
use TableTrait;
19+
20+
public function testSelect(): void
21+
{
22+
(new Select($this->orm, Entity\User::class))
23+
->load('visitPermission')
24+
->load('visitPermission.cities')
25+
->load('passport')
26+
->fetchAll();
27+
28+
$this->assertTrue(true);
29+
}
30+
31+
public function setUp(): void
32+
{
33+
// Init DB
34+
parent::setUp();
35+
$this->makeTables();
36+
$this->fillData();
37+
38+
$this->loadSchema(__DIR__ . '/schema.php');
39+
}
40+
41+
private function makeTables(): void
42+
{
43+
$this->makeTable('user', [
44+
'id' => 'primary',
45+
'login' => 'string',
46+
]);
47+
48+
$this->makeTable('passport', [
49+
'id' => 'primary',
50+
'number' => 'string',
51+
'user_id' => 'int',
52+
]);
53+
$this->makeFK('passport', 'user_id', 'user', 'id', 'NO ACTION', 'NO ACTION');
54+
55+
$this->makeTable('city', [
56+
'id' => 'primary',
57+
'name' => 'string',
58+
]);
59+
60+
$this->makeTable('user_visit_permission', [
61+
'id' => 'primary',
62+
'user_id' => 'int',
63+
'all_cities' => 'bool',
64+
]);
65+
$this->makeFK('user_visit_permission', 'user_id', 'user', 'id', 'NO ACTION', 'NO ACTION');
66+
67+
$this->makeTable('user_visit__permission_city', [
68+
'id' => 'primary',
69+
'user_id' => 'int',
70+
'city_id' => 'int',
71+
]);
72+
$this->makeFK('user_visit__permission_city', 'user_id', 'user', 'id', 'NO ACTION', 'NO ACTION');
73+
$this->makeFK('user_visit__permission_city', 'city_id', 'city', 'id', 'NO ACTION', 'NO ACTION');
74+
}
75+
76+
private function fillData(): void
77+
{
78+
$this->getDatabase()->table('user')->insertMultiple(
79+
['login'],
80+
[
81+
['user-1'],
82+
],
83+
);
84+
85+
$this->getDatabase()->table('passport')->insertMultiple(
86+
['user_id', 'number'],
87+
[
88+
[1, '123456'],
89+
],
90+
);
91+
}
92+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Issue511\Entity;
6+
7+
class City
8+
{
9+
public ?int $id = null;
10+
public string $name = '';
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Issue511\Entity;
6+
7+
class Passport
8+
{
9+
public ?int $id = null;
10+
public string $number;
11+
public User $user;
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Issue511\Entity;
6+
7+
class User
8+
{
9+
public ?int $id = null;
10+
public string $login;
11+
public ?Passport $passport = null;
12+
public ?VisitPermission $visitPermission = null;
13+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Issue511\Entity;
6+
7+
class VisitPermission
8+
{
9+
public int $user_id;
10+
public User $user;
11+
public bool $allCities = false;
12+
public array $cities = [];
13+
14+
public function __construct(User $user, bool $allCities = false)
15+
{
16+
$this->user = $user;
17+
$this->allCities = $allCities;
18+
}
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Issue511\Entity;
6+
7+
class VisitPermissionCityPivot
8+
{
9+
private ?int $id = null;
10+
}

0 commit comments

Comments
 (0)