Skip to content

Commit

Permalink
Merge branch 'develop' into simplify-spec-usage
Browse files Browse the repository at this point in the history
* develop:
  remove remnants of phpunit
  use builtin memory assertion
  use builtin method to disable memory limit
  update changelog
  fix constructor
  use named constructors
  • Loading branch information
Baptouuuu committed Jul 14, 2024
2 parents 1bbbcd9 + 9cab7ad commit 27cad5e
Show file tree
Hide file tree
Showing 50 changed files with 178 additions and 169 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/composer.lock
/vendor
/.phpunit.result.cache
/.phpunit.cache
/.cache
/tmp
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@
- `Formal\AccessLayer\Query\MultipleInsert`
- `Formal\AccessLayer\Table\Column\Type::uuid()`
- `Formal\AccessLayer\Table\Column\Type::bool()`
- `Formal\AccessLayer\Connection\Lazy::of()`
- `Formal\AccessLayer\Row::new()`
- `Formal\AccessLayer\Row\Value::of()`

### Changed

- Requires `innmind/specification:~4.1`
- `Formal\AccessLayer\Query::sql()` now has a `Driver` argument
- `Formal\AccessLayer\Query\Insert::into()` only accepts 1 `Row`, for multiple rows use `MultipleInsert` instead
- `Formal\AccessLayer\Connection\Lazy` constructor is now private, use `::of()` instead
- `Formal\AccessLayer\Row` constructor is now private, use `::new()` instead
- `Formal\AccessLayer\Row\Value` constructor is now private, use `::of()` instead
- `Formal\AccessLayer\Table\Column` constructor is now private, use `::of()` instead
- `Formal\AccessLayer\Table\Column\Name` constructor is now private, use `::of()` instead
- `Formal\AccessLayer\Table\Name` constructor is now private, use `::of()` instead

### Removed

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use Formal\AccessLayer\{
use Innmind\Url\Url;
use Innmind\Immutable\Sequence;

$connection = new Lazy(static fn() => PDO::of(Url::of('mysql://user:[email protected]:3306/database_name')));
$connection = Lazy::of(static fn() => PDO::of(Url::of('mysql://user:[email protected]:3306/database_name')));

$rows = $connection(SQL::of('SELECT * FROM `some_table`'));
$rows; // instanceof Sequence<Row>
Expand Down
3 changes: 1 addition & 2 deletions blackbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

require 'vendor/autoload.php';

\ini_set('memory_limit', '-1');

use Innmind\BlackBox\{
Application,
Runner\Load,
Runner\CodeCoverage,
};

Application::new($argv)
->disableMemoryLimit()
->codeCoverage(
CodeCoverage::of(
__DIR__.'/src/',
Expand Down
2 changes: 1 addition & 1 deletion documentation/connections/lazy.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use Formal\AccessLayer\{
};
use Innmind\Url\Url;

$connection = new Lazy(
$connection = Lazy::of(
static fn() => PDO::of(
Url::of('mysql://user:[email protected]:3306/database_name'),
),
Expand Down
44 changes: 22 additions & 22 deletions documentation/queries/create_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use Formal\AccessLayer\{
};

$create = CreateTable::named(
new Name('users'),
new Column(
new Column\Name('username'),
Name::of('users'),
Column::of(
Column\Name::of('username'),
Column\Type::varchar(),
),
new Column(
new Column\Name('name'),
Column::of(
Column\Name::of('name'),
Column\Type::varchar(),
),
);
Expand All @@ -31,13 +31,13 @@ use Formal\AccessLayer\{
};

$create = CreateTable::ifNotExists(
new Name('users'),
new Column(
new Column\Name('username'),
Name::of('users'),
Column::of(
Column\Name::of('username'),
Column\Type::varchar(),
),
new Column(
new Column\Name('name'),
Column::of(
Column\Name::of('name'),
Column\Type::varchar(),
),
);
Expand All @@ -52,34 +52,34 @@ You can specify the primary key of the table like so:

```php
$create = CreateTable::named(
new Name('users'),
new Column(
new Column\Name('id'),
Name::of('users'),
Column::of(
Column\Name::of('id'),
Column\Type::int(),
),
);
$create = $create->primaryKey(new Column\Name('id'));
$create = $create->primaryKey(Column\Name::of('id'));
$connection($create);
```

### Foreign key

```php
$create = CreateTable::named(
new Name('address'),
new Column(
new Column\Name('user'),
Name::of('address'),
Column::of(
Column\Name::of('user'),
Column\Type::int(),
),
new Column(
new Column\Name('address'),
Column::of(
Column\Name::of('address'),
Column\Type::text(),
),
);
$create = $create->foreignKey(
new Column\Name('user'),
new Name('users'),
new Column\Name('id'),
Column\Name::of('user'),
Name::of('users'),
Column\Name::of('id'),
);
$connection($create);
```
Expand Down
4 changes: 2 additions & 2 deletions documentation/queries/delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use Formal\AccessLayer\{
Table\Name,
};

$delete = Delete::from(new Name('users'));
$delete = Delete::from(Name::of('users'));
$connection($delete);
```

Expand Down Expand Up @@ -38,7 +38,7 @@ final class Username
}
}

$delete = Delete::from(new Name('users'))->where(
$delete = Delete::from(Name::of('users'))->where(
Username::of('some username')->or(Username::of('other username')),
);
$connection($delete);
Expand Down
4 changes: 2 additions & 2 deletions documentation/queries/drop_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use Formal\AccessLayer\{
Table\Name,
};

$drop = DropTable::named(new Name('users'));
$drop = DropTable::named(Name::of('users'));
$connection($drop);
```

Expand All @@ -18,6 +18,6 @@ use Formal\AccessLayer\{
Table\Name,
};

$drop = DropTable::ifExists(new Name('users'));
$drop = DropTable::ifExists(Name::of('users'));
$connection($drop);
```
20 changes: 10 additions & 10 deletions documentation/queries/insert.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use Formal\AccessLayer\{
};

$insert = Insert::into(
new Name('users'),
Name::of('users'),
Row::of([
'username' => 'some username',
'name' => 'some name',
Expand All @@ -31,15 +31,15 @@ use Formal\AccessLayer\{
};

$insert = Insert::into(
new Name('users'),
new Row(
new Row\Value(
new Column\Name('username'),
Name::of('users'),
Row::new(
Row\Value::of(
Column\Name::of('username'),
'some username',
Type::string,
),
new Row\Value(
new Column\Name('name'),
Row\Value::of(
Column\Name::of('name'),
'some name',
Type::string,
),
Expand All @@ -64,9 +64,9 @@ use Formal\AccessLayer\{
use Innmind\Immutable\Sequence;

$insert = MultipleInsert::into(
new Name('users'),
new Column\Name('username'),
new Column\Name('name'),
Name::of('users'),
Column\Name::of('username'),
Column\Name::of('name'),
);
$connection($insert(Sequence::of(
Row::of([
Expand Down
10 changes: 5 additions & 5 deletions documentation/queries/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use Formal\AccesLayer\{
Table\Name,
};

$select = Select::from(new Name('users'));
$select = Select::from(Name::of('users'));
$users = $connection($select);
```

Expand All @@ -24,9 +24,9 @@ use Formal\AccesLayer\{
Table\Column,
};

$select = Select::from(new Name('users'))->columns(
new Column\Name('username'),
new Column\Name('name'),
$select = Select::from(Name::of('users'))->columns(
Column\Name::of('username'),
Column\Name::of('name'),
);
$users = $connection($select);
```
Expand Down Expand Up @@ -58,7 +58,7 @@ final class Username
}
}

$select = Select::from(new Name('users'))->where(
$select = Select::from(Name::of('users'))->where(
Username::of('some username')->or(Username::of('other username')),
);
$users = $connection($select);
Expand Down
4 changes: 2 additions & 2 deletions documentation/queries/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use Formal\AccessLayer\{
};

$update = Update::set(
new Name('users'),
Name::of('users'),
Row::of([
'name' => 'some value',
]),
Expand Down Expand Up @@ -46,7 +46,7 @@ final class Username
}

$update = Update::set(
new Name('users'),
Name::of('users'),
Row::of([
'name' => 'some value',
]),
Expand Down
2 changes: 1 addition & 1 deletion fixtures/Table/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static function any(Set $type = null, int $max = null): Set
{
return Set\Randomize::of( // randomize to prevent same name used twice
Set\Composite::immutable(
static fn($name, $type): Model => new Model($name, $type),
Model::of(...),
Column\Name::any($max),
$type ?? Column\Type::any(),
),
Expand Down
2 changes: 1 addition & 1 deletion fixtures/Table/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class Name
public static function any(): Set
{
return Set\Composite::immutable(
static fn(string $firstChar, string $name): Model => new Model($firstChar.$name),
static fn(string $firstChar, string $name): Model => Model::of($firstChar.$name),
Set\Either::any( // table name can't start with a number
Set\Chars::lowercaseLetter(),
Set\Chars::uppercaseLetter(),
Expand Down
27 changes: 0 additions & 27 deletions phpunit.xml.dist

This file was deleted.

4 changes: 2 additions & 2 deletions proofs/connection/lazy.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

return static function() {
$port = \getenv('DB_PORT') ?: '3306';
$connection = new Lazy(
$connection = Lazy::of(
static fn() => PDO::of(Url::of("mysql://root:[email protected]:$port/example")),
);
Properties::seed($connection);
Expand All @@ -32,7 +32,7 @@
yield test(
'Lazy connection must not be established at instanciation',
static fn($assert) => $assert
->object(new Lazy(static fn() => PDO::of(Url::of('mysql://unknown:[email protected]:3306/unknown'))))
->object(Lazy::of(static fn() => PDO::of(Url::of('mysql://unknown:[email protected]:3306/unknown'))))
->instance(Connection::class),
);

Expand Down
Loading

0 comments on commit 27cad5e

Please sign in to comment.