Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small primary #76

Open
wants to merge 5 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .github/workflows/ci-mssql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ jobs:
mssql: 'server:2017-latest'
- php: '8.0'
extensions: pdo, pdo_sqlsrv
mssql: 'server:2019-latest'
mssql: 'server:2019-CU25-ubuntu-20.04'
- php: '8.1'
extensions: pdo, pdo_sqlsrv
mssql: 'server:2019-latest'
mssql: 'server:2019-CU25-ubuntu-20.04'
- php: '8.2'
extensions: pdo, pdo_sqlsrv
mssql: 'server:2019-latest'
mssql: 'server:2019-CU25-ubuntu-20.04'
- php: '8.3'
extensions: pdo, pdo_sqlsrv
mssql: 'server:2019-latest'
mssql: 'server:2019-CU25-ubuntu-20.04'

services:
mssql:
image: mcr.microsoft.com/mssql/${{ matrix.mssql }}
env:
SA_PASSWORD: SSpaSS__1
ACCEPT_EULA: Y
MSSQL_PID: Developer
ports:
- 11433:1433
options: --name=mssql --health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'SSpaSS__1' -Q 'SELECT 1'" --health-interval=10s --health-timeout=5s --health-retries=3
image: mcr.microsoft.com/mssql/${{ matrix.mssql }}
env:
SA_PASSWORD: SSpaSS__1
ACCEPT_EULA: Y
MSSQL_PID: Developer
ports:
- 11433:1433
options: --name=mssql --health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'SSpaSS__1' -Q 'SELECT 1'" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup DB services
run: |
cd tests
docker-compose up -d
docker compose up -d
cd ..
- name: Setup PHP ${{ matrix.php-versions }}
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function setPrimary(bool $primary): self

public function isPrimary(): bool
{
return $this->primary || in_array($this->type, ['primary', 'bigPrimary']);
return $this->primary || in_array($this->type, ['primary', 'bigPrimary', 'smallPrimary']);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Relation/Traits/FieldTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ protected function ensureField(Entity $target, string $fieldName, Field $outerFi
case 'bigPrimary':
$field->setType('bigint');
break;
case 'smallPrimary':
$field->setType('smallint');
break;
default:
$field->setType($outerField->getType());
}
Expand Down
33 changes: 33 additions & 0 deletions tests/Schema/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,39 @@ public function testRenderWithCustomType(): void
$this->assertSame('ltree', $table->column('name')->getDeclaredType());
}

/**
* @dataProvider dataIsPrimary
*/
public function testIsPrimary(string $type, bool $expected = true): void
{
$field = new Field();
$field->setType($type);
$field->setColumn('id');

$column = Column::parse($field);
$this->assertSame($expected, $column->isPrimary());
}

public function dataIsPrimary(): iterable
{
yield 'primary' => [
'primary',
true,
];
yield 'smallPrimary' => [
'smallPrimary',
true,
];
yield 'bigPrimary' => [
'bigPrimary',
true,
];
yield 'foo' => [
'foo',
false,
];
}

/**
* @return AbstractTable
*/
Expand Down
30 changes: 30 additions & 0 deletions tests/Schema/FieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,34 @@ public function testGetByColumnNameShouldThrowAnExceptionWhenFieldNotFound(): vo

$m->getByColumnName('slug');
}

/**
* @dataProvider dataIsPrimary
*/
public function testIsPrimary(string $type, bool $expected = true): void
{
$field = new Field();
$field->setType($type);
$this->assertSame($expected, $field->isPrimary());
}

public function dataIsPrimary(): iterable
{
yield 'primary' => [
'primary',
true,
];
yield 'smallPrimary' => [
'smallPrimary',
true,
];
yield 'bigPrimary' => [
'bigPrimary',
true,
];
yield 'foo' => [
'foo',
false,
];
}
}
25 changes: 20 additions & 5 deletions tests/Schema/Relation/Traits/FieldTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,27 @@ public function testEnsureFieldIfFieldNotExistsItShouldBeCreated(
}
}

public function outerFieldTypes(): array
public function outerFieldTypes(): iterable
{
return [
['primary', 'int', false],
['bigPrimary', 'bigint', true],
['test', 'test', true],
yield 'primary' => [
'primary',
'int',
false,
];
yield 'bigPrimary' => [
'bigPrimary',
'bigint',
true,
];
yield 'smallPrimary' => [
'smallPrimary',
'smallint',
true,
];
yield 'test' => [
'test',
'test',
true,
];
}

Expand Down
6 changes: 1 addition & 5 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
version: "3"

services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2019-latest
image: mcr.microsoft.com/mssql/server:2019-CU25-ubuntu-20.04
ports:
- "11433:1433"
environment:
Expand All @@ -11,7 +9,6 @@ services:

mysql:
image: mysql:8.0.37
restart: always
command: --default-authentication-plugin=mysql_native_password
ports:
- "13306:3306"
Expand All @@ -22,7 +19,6 @@ services:

postgres:
image: postgres:12
restart: always
ports:
- "15432:5432"
environment:
Expand Down
Loading