Skip to content

Commit d712c79

Browse files
authored
Merge pull request #530: Set ignoreUninitializedRelations option to false by default
2 parents ec26571 + eeee29e commit d712c79

File tree

6 files changed

+58
-20
lines changed

6 files changed

+58
-20
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
3131
3232
- name: 📦 Checkout
33-
uses: actions/checkout@v2
33+
uses: actions/checkout@v5
3434
- name: 🛠️ Setup DB services
3535
run: |
3636
cd tests
@@ -86,7 +86,7 @@ jobs:
8686
- "8.4"
8787
steps:
8888
- name: 📦 Checkout
89-
uses: actions/checkout@v2
89+
uses: actions/checkout@v5
9090
- name: 🛠️ Setup DB services
9191
run: |
9292
cd tests

psalm-baseline.xml

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,9 @@
378378
</ClassMustBeFinal>
379379
</file>
380380
<file src="src/Factory.php">
381-
<InvalidArgument>
382-
<code><![CDATA[$database]]></code>
383-
</InvalidArgument>
384-
<InvalidCast>
385-
<code><![CDATA[$database]]></code>
386-
</InvalidCast>
381+
<ArgumentTypeCoercion>
382+
<code><![CDATA[$role]]></code>
383+
</ArgumentTypeCoercion>
387384
<InvalidPropertyAssignmentValue>
388385
<code><![CDATA[[
389386
SchemaInterface::REPOSITORY => Repository::class,
@@ -472,9 +469,6 @@
472469
<code><![CDATA[$class]]></code>
473470
<code><![CDATA[$e->getCode()]]></code>
474471
</PossiblyInvalidArgument>
475-
<TooFewArguments>
476-
<code><![CDATA[new Typecast($database)]]></code>
477-
</TooFewArguments>
478472
</file>
479473
<file src="src/Heap/Heap.php">
480474
<InvalidNullableReturnType>
@@ -2014,8 +2008,6 @@
20142008
<code><![CDATA[\IteratorAggregate]]></code>
20152009
</MissingTemplateParam>
20162010
<MixedArgument>
2017-
<code><![CDATA[$data[0]]]></code>
2018-
<code><![CDATA[$node->getResult()]]></code>
20192011
<code><![CDATA[$subOption]]></code>
20202012
<code><![CDATA[$subOption + $options]]></code>
20212013
</MixedArgument>
@@ -2050,17 +2042,18 @@
20502042
$this->schema,
20512043
$this->entityFactory,
20522044
$this->loader->getTarget(),
2053-
$node->getResult(),
2045+
$this->loadData(),
20542046
$findInHeap,
20552047
typecast: true,
20562048
)]]></code>
20572049
<code><![CDATA[Iterator<TEntity>]]></code>
2058-
<code><![CDATA[\array_map([$mapper, 'cast'], $node->getResult())]]></code>
2059-
<code><![CDATA[array<array-key, array<string, mixed>>]]></code>
2050+
<code><![CDATA[\array_map([$mapper, 'cast'], $this->loadData(false))]]></code>
2051+
<code><![CDATA[array<array-key, array<non-empty-string, mixed>>]]></code>
2052+
<code><![CDATA[array<array-key, array<non-empty-string, mixed>>]]></code>
20602053
</MixedReturnTypeCoercion>
2061-
<PossiblyInvalidArgument>
2062-
<code><![CDATA[$node->getResult()]]></code>
2063-
</PossiblyInvalidArgument>
2054+
<PossiblyFalseArgument>
2055+
<code><![CDATA[\reset($pk)]]></code>
2056+
</PossiblyFalseArgument>
20642057
</file>
20652058
<file src="src/Select/AbstractLoader.php">
20662059
<MixedArgument>

src/Options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final class Options
1313
* @readonly
1414
* @note will be set to TRUE in the next major version.
1515
*/
16-
public bool $ignoreUninitializedRelations = true;
16+
public bool $ignoreUninitializedRelations = false;
1717

1818
/**
1919
* @readonly

tests/ORM/Functional/Driver/Common/BaseTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ public function setUp(): void
153153
))->withCollectionFactory('array', new ArrayCollectionFactory()),
154154
new Schema([]),
155155
$this->getCommandGenerator(),
156+
options: (new \Cycle\ORM\Options())
157+
->withIgnoreUninitializedRelations(true)
158+
->withGroupByToDeduplicate(true),
156159
);
157160
}
158161

tests/ORM/Functional/Driver/Common/Relation/BelongsTo/BelongsToNullableRelationTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Cycle\ORM\Tests\Functional\Driver\Common\Relation\BelongsTo;
66

7+
use Cycle\ORM\Options;
78
use Cycle\ORM\Relation;
89
use Cycle\ORM\Select;
910
use Cycle\ORM\Tests\Fixtures\Profile;
@@ -65,4 +66,22 @@ public function testRemoveParentUsingSetNull(): void
6566
->fetchOne();
6667
$this->assertNull($profile->user);
6768
}
69+
70+
/**
71+
* If relation property was unset and IgnoreUninitializedRelations option is false - set to null
72+
*/
73+
public function testUnsetPropertyWithoutIgnoreUninitializedRelations(): void
74+
{
75+
echo static::class;
76+
$this->orm = $this->orm->with(options: (new Options())->withIgnoreUninitializedRelations(false));
77+
/** @var Profile $profile */
78+
$profile = (new Select($this->orm, Profile::class))
79+
->wherePK(1)->load('user')->fetchOne();
80+
81+
unset($profile->user);
82+
83+
$this->captureWriteQueries();
84+
$this->save($profile);
85+
$this->assertNumWrites(1);
86+
}
6887
}

tests/ORM/Functional/Driver/Common/Relation/BelongsTo/BelongsToRelationTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Cycle\ORM\Heap\Heap;
99
use Cycle\ORM\Heap\Node;
1010
use Cycle\ORM\Mapper\Mapper;
11+
use Cycle\ORM\Options;
1112
use Cycle\ORM\Relation;
1213
use Cycle\ORM\Schema;
1314
use Cycle\ORM\Select;
@@ -394,6 +395,28 @@ public function testUnsetProperty(): void
394395
$this->assertNumWrites(0);
395396
}
396397

398+
/**
399+
* If non-nullable relation property was unset - throw NullException
400+
*/
401+
public function testUnsetPropertyWithoutIgnoreUninitializedRelations(): void
402+
{
403+
echo static::class;
404+
$this->orm = $this->orm->with(options: (new Options())->withIgnoreUninitializedRelations(false));
405+
/** @var Profile $profile */
406+
$profile = (new Select($this->orm, Profile::class))
407+
->wherePK(1)->load('user')->fetchOne();
408+
409+
unset($profile->user);
410+
$this->expectException(NullException::class);
411+
412+
$this->captureWriteQueries();
413+
try {
414+
$this->save($profile);
415+
} finally {
416+
$this->assertNumWrites(0);
417+
}
418+
}
419+
397420
public function setUp(): void
398421
{
399422
parent::setUp();

0 commit comments

Comments
 (0)