Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Feb 8, 2024
1 parent 3e99cb5 commit 21898cc
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/Command/Database/Insert.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ public function execute(): void
}
}


$state->updateTransactionData();

parent::execute();
Expand Down Expand Up @@ -173,6 +172,6 @@ private function hasGeneratedFields(): bool
}
}

return true;
return false;
}
}
4 changes: 2 additions & 2 deletions src/Heap/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ public function getChanges(): array

public function getValue(string $key): mixed
{
return array_key_exists($key, $this->data) ? $this->data[$key] : ($this->transactionData[$key] ?? null);
return \array_key_exists($key, $this->data) ? $this->data[$key] : ($this->transactionData[$key] ?? null);
}

public function hasValue(string $key, bool $allowNull = true): bool
{
if (!$allowNull) {
return isset($this->data[$key]) || isset($this->transactionData[$key]);
}
return array_key_exists($key, $this->data) || array_key_exists($key, $this->transactionData);
return \array_key_exists($key, $this->data) || \array_key_exists($key, $this->transactionData);

Check warning on line 174 in src/Heap/State.php

View check run for this annotation

Codecov / codecov/patch

src/Heap/State.php#L174

Added line #L174 was not covered by tests
}

public function register(string $key, mixed $value): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,29 @@ public function test2(): void
$this->assertNumWrites(1);
}

public function test3(): void
{
$user = new Entity\User3();

$this->captureWriteQueries();
$this->save($user);

// ORM won't detect any values to store
// because the id field isn't marked as autogenerated
$this->assertNumWrites(0);
}

public function test4(): void
{
$user = new Entity\User4();

$this->save($user);

// ORM won't detect any values to store
// because the id field isn't marked as autogenerated
$this->assertNumWrites(0);
}

private function makeTables(): void
{
// Make tables
Expand All @@ -56,5 +79,15 @@ private function makeTables(): void
$this->makeTable('user2', [
'id' => 'primary', // autoincrement
]);

$this->makeTable('user3', [
'id' => 'primary', // autoincrement
]);

$this->logger->display();
$this->makeTable('user4', [
'id' => 'primary',
'counter' => 'int',
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case321\Entity;

class User3
{
public int $id;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case321\Entity;

class User4
{
public int $id;
public int $counter;
}
40 changes: 40 additions & 0 deletions tests/ORM/Functional/Driver/Common/Integration/Case321/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Cycle\ORM\Select\Source;
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case321\Entity\User1;
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case321\Entity\User2;
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case321\Entity\User3;
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case321\Entity\User4;

return [
'user1' => [
Expand Down Expand Up @@ -52,4 +54,42 @@
'id' => GeneratedField::ON_INSERT, // autoincrement
],
],
'user3' => [
Schema::ENTITY => User3::class,
Schema::MAPPER => Mapper::class,
Schema::SOURCE => Source::class,
Schema::DATABASE => 'default',
Schema::TABLE => 'user3',
Schema::PRIMARY_KEY => ['id'],
Schema::FIND_BY_KEYS => ['id'],
Schema::COLUMNS => [
'id' => 'id',
],
Schema::RELATIONS => [],
Schema::SCOPE => null,
Schema::TYPECAST => [
'id' => 'int',
],
Schema::SCHEMA => [],
Schema::GENERATED_FIELDS => [],
],
'user4' => [
Schema::ENTITY => User4::class,
Schema::MAPPER => Mapper::class,
Schema::SOURCE => Source::class,
Schema::DATABASE => 'default',
Schema::TABLE => 'user4',
Schema::PRIMARY_KEY => ['id'],
Schema::COLUMNS => [
'id' => 'id',
'counter' => 'counter',
],
Schema::TYPECAST => [
'id' => 'int',
'counter' => 'counter',
],
Schema::GENERATED_FIELDS => [
'counter' => GeneratedField::BEFORE_UPDATE,
],
],
];

0 comments on commit 21898cc

Please sign in to comment.