Skip to content

Commit

Permalink
Add a test case when an exception is expected when setting a private …
Browse files Browse the repository at this point in the history
…field
  • Loading branch information
laxity7 committed Nov 7, 2024
1 parent e42905c commit 4b2923c
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/ORM/Functional/Driver/Common/Integration/Case6/CaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case6;

use Cycle\ORM\Select;
use Cycle\ORM\Tests\Functional\Driver\Common\BaseTest;
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case6\Entity\User;
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\IntegrationTestTrait;
use Cycle\ORM\Tests\Traits\TableTrait;

abstract class CaseTest extends BaseTest
{
use IntegrationTestTrait;
use TableTrait;

public function setUp(): void
{
// Init DB
parent::setUp();

// Make tables
$this->makeTable('users', [
'id' => 'int,primary',
'login' => 'string',
]);

$this->loadSchema(__DIR__ . '/schema.php');

$this->getDatabase()->table('users')->insertMultiple(
['id', 'login'],
[
[1, 'foo'],
],
);
}

public function testSelect(): void
{
/** @var User $model */
$model = (new Select($this->orm,User::class))
->wherePK(1)
->fetchOne();

$this->assertSame('foo', $model->getLogin());
$this->expectException(\Exception::class);
$model->login = 'new login';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

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

class User
{
private ?int $id = null;
private string $login;

public function __construct(string $login)
{
$this->login = $login;
}

public function getId(): ?string
{
return $this->id === null ? null : (string)$this->id;
}

public function getLogin(): string
{
return $this->login;
}
}
31 changes: 31 additions & 0 deletions tests/ORM/Functional/Driver/Common/Integration/Case6/schema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

use Cycle\ORM\Mapper\Mapper;
use Cycle\ORM\SchemaInterface as Schema;
use Cycle\ORM\Select\Repository;
use Cycle\ORM\Select\Source;
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case6\Entity\User;

return [
'users' => [
Schema::ENTITY => User::class,
Schema::MAPPER => Mapper::class,
Schema::SOURCE => Source::class,
Schema::REPOSITORY => Repository::class,
Schema::DATABASE => 'default',
Schema::TABLE => 'users',
Schema::PRIMARY_KEY => ['id'],
Schema::FIND_BY_KEYS => ['id'],
Schema::COLUMNS => [
'id' => 'id',
'login' => 'login',
],
Schema::RELATIONS => [],
Schema::TYPECAST => [
'id' => 'int',
'login' => 'string',
],
],
];
17 changes: 17 additions & 0 deletions tests/ORM/Functional/Driver/MySQL/Integration/Case6/CaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Functional\Driver\MySQL\Integration\Case6;

// phpcs:ignore
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case6\CaseTest as CommonClass;

/**
* @group driver
* @group driver-sqlite
*/
class CaseTest extends CommonClass
{
public const DRIVER = 'mysql';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Functional\Driver\Postgres\Integration\Case6;

// phpcs:ignore
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case6\CaseTest as CommonClass;

/**
* @group driver
* @group driver-sqlite
*/
class CaseTest extends CommonClass
{
public const DRIVER = 'postgres';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Functional\Driver\SQLServer\Integration\Case6;

// phpcs:ignore
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case6\CaseTest as CommonClass;

/**
* @group driver
* @group driver-sqlite
*/
class CaseTest extends CommonClass
{
public const DRIVER = 'sqlserver';
}
17 changes: 17 additions & 0 deletions tests/ORM/Functional/Driver/SQLite/Integration/Case6/CaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Functional\Driver\SQLite\Integration\Case6;

// phpcs:ignore
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case6\CaseTest as CommonClass;

/**
* @group driver
* @group driver-sqlite
*/
class CaseTest extends CommonClass
{
public const DRIVER = 'sqlite';
}

0 comments on commit 4b2923c

Please sign in to comment.