Skip to content

Commit

Permalink
removed IStructure (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 2, 2024
1 parent 1287b3a commit 787349a
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 100 deletions.
4 changes: 2 additions & 2 deletions src/Database/Conventions/DiscoveredConventions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Nette\Database\Conventions;

use Nette\Database\Conventions;
use Nette\Database\IStructure;
use Nette\Database\Structure;


/**
Expand All @@ -19,7 +19,7 @@
class DiscoveredConventions implements Conventions
{
public function __construct(
protected readonly IStructure $structure,
protected readonly Structure $structure,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Database/Explorer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Explorer
private int $transactionDepth = 0;
private ?Cache $cache = null;
private ?Conventions $conventions = null;
private ?IStructure $structure = null;
private ?Structure $structure = null;


public function __construct(
Expand Down Expand Up @@ -392,7 +392,7 @@ public function getConventions(): Conventions


/** @internal */
public function getStructure(): IStructure
public function getStructure(): Structure
{
return $this->structure ??= new Structure($this->getDatabaseEngine(), $this->getCache());
}
Expand Down
78 changes: 0 additions & 78 deletions src/Database/IStructure.php

This file was deleted.

3 changes: 2 additions & 1 deletion src/Database/Structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

/**
* Cached reflection of database structure.
* @internal
*/
class Structure implements IStructure
class Structure
{
/** @var array{tables: array, columns: array, primary: array, aliases: array, hasMany: array, belongsTo: array} */
protected array $structure;
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Table/SqlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use Nette\Database\Conventions;
use Nette\Database\Drivers\Engine;
use Nette\Database\Explorer;
use Nette\Database\IStructure;
use Nette\Database\SqlLiteral;
use Nette\Database\Structure;


/**
Expand Down Expand Up @@ -47,7 +47,7 @@ class SqlBuilder
protected array $aliases = [];
protected string $currentAlias = '';
private readonly Engine $engine;
private readonly IStructure $structure;
private readonly Structure $structure;
private array $cacheTableList = [];
private array $expandingJoins = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require __DIR__ . '/../../bootstrap.php';


test('basic test', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure = Mockery::mock(Nette\Database\Structure::class);
$structure->shouldReceive('getBelongsToReference')->with('books')->andReturn([
'author_id' => 'authors',
'translator_id' => 'authors',
Expand All @@ -26,7 +26,7 @@ test('basic test', function () {
});

test('basic test', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure = Mockery::mock(Nette\Database\Structure::class);
$structure->shouldReceive('getBelongsToReference')->with('public.books')->andReturn([
'author_id' => 'public.authors',
'translator_id' => 'public.authors',
Expand All @@ -39,7 +39,7 @@ test('basic test', function () {
});

test('tests order of table columns with foreign keys', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure = Mockery::mock(Nette\Database\Structure::class);
$structure->shouldReceive('getBelongsToReference')->with('books')->andReturn([
'translator_id' => 'authors',
'author_id' => 'authors',
Expand All @@ -52,7 +52,7 @@ test('tests order of table columns with foreign keys', function () {


test('tests case insensivity', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure = Mockery::mock(Nette\Database\Structure::class);
$structure->shouldReceive('getBelongsToReference')->with('books')->andReturn([
'author_id' => 'authors',
'translator_id' => 'authors',
Expand All @@ -65,7 +65,7 @@ test('tests case insensivity', function () {


test('tests case insensivity and prefixes', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure = Mockery::mock(Nette\Database\Structure::class);
$structure->shouldReceive('getBelongsToReference')->with('nBooks')->andReturn([
'authorId' => 'nAuthors',
'translatorId' => 'nAuthors',
Expand All @@ -79,7 +79,7 @@ test('tests case insensivity and prefixes', function () {


test('tests rebuilt', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure = Mockery::mock(Nette\Database\Structure::class);
$structure->shouldReceive('isRebuilt')->andReturn(false);
$structure->shouldReceive('rebuild');
$structure->shouldReceive('getBelongsToReference')->andReturn([])->once();
Expand All @@ -96,7 +96,7 @@ test('tests rebuilt', function () {


test('tests already rebuilt structure', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure = Mockery::mock(Nette\Database\Structure::class);
$structure->shouldReceive('isRebuilt')->andReturn(true);
$structure->shouldReceive('getBelongsToReference')->with('books')->andReturn([])->once();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require __DIR__ . '/../../bootstrap.php';


test('basic test singular', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure = Mockery::mock(Nette\Database\Structure::class);
$structure->shouldReceive('getHasManyReference')->with('author')->andReturn([
'book' => ['author_id', 'translator_id'],
'book_topics' => ['author_id'],
Expand Down Expand Up @@ -43,7 +43,7 @@ test('basic test singular', function () {


test('basic test singular with schema', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure = Mockery::mock(Nette\Database\Structure::class);
$structure->shouldReceive('getHasManyReference')->with('public.author')->andReturn([
'public.book' => ['author_id', 'translator_id'],
'public.book_topics' => ['author_id'],
Expand Down Expand Up @@ -88,7 +88,7 @@ test('basic test singular with schema', function () {


test('basic test plural', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure = Mockery::mock(Nette\Database\Structure::class);
$structure->shouldReceive('getHasManyReference')->with('authors')->andReturn([
'books' => ['author_id', 'translator_id'],
])->once();
Expand All @@ -112,7 +112,7 @@ test('basic test plural', function () {


test('tests column match with source table', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure = Mockery::mock(Nette\Database\Structure::class);
$structure->shouldReceive('getHasManyReference')->with('author')->andReturn([
'book' => ['author_id', 'tran_id'],
])->once();
Expand All @@ -139,7 +139,7 @@ test('tests column match with source table', function () {


test('tests case insensivity and prefixes', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure = Mockery::mock(Nette\Database\Structure::class);
$structure->shouldReceive('getHasManyReference')->with('nAuthors')->andReturn([
'nBooks' => ['authorId', 'translatorId'],
])->once();
Expand All @@ -151,7 +151,7 @@ test('tests case insensivity and prefixes', function () {


test('tests rebuilt', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure = Mockery::mock(Nette\Database\Structure::class);
$structure->shouldReceive('isRebuilt')->andReturn(false);
$structure->shouldReceive('rebuild');
$structure->shouldReceive('getHasManyReference')->with('author')->andReturn([])->once();
Expand All @@ -165,7 +165,7 @@ test('tests rebuilt', function () {


test('tests already rebuilt structure', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure = Mockery::mock(Nette\Database\Structure::class);
$structure->shouldReceive('isRebuilt')->andReturn(true);
$structure->shouldReceive('getHasManyReference')->with('author')->andReturn([])->once();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require __DIR__ . '/../../bootstrap.php';


test('', function () {
$structure = Mockery::mock(Nette\Database\IStructure::class);
$structure = Mockery::mock(Nette\Database\Structure::class);
$structure->shouldReceive('getPrimaryKey')->with('books_x_tags')->andReturn(['book_id', 'tag_id']);

$conventions = new DiscoveredConventions($structure);
Expand Down

0 comments on commit 787349a

Please sign in to comment.