Skip to content
Merged
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
74 changes: 74 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Tests

on:
push:
pull_request:

jobs:
phpunit:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.2', '8.3', '8.4', '8.5']
db:
- name: mysql
image: mysql:8.0
port: 3306
container_port: 3306
driver: mysql
collation: utf8_unicode_ci
health_cmd: "mysqladmin ping -h 127.0.0.1 -uuser -puserpass"
- name: postgres
image: postgres:16
port: 5432
container_port: 5432
driver: pgsql
collation: ""
health_cmd: "pg_isready -h 127.0.0.1 -U user -d closuretabletest"

name: PHP ${{ matrix.php }} / ${{ matrix.db.name }}
services:
db:
image: ${{ matrix.db.image }}
ports:
- ${{ matrix.db.port }}:${{ matrix.db.container_port }}
env:
MYSQL_DATABASE: ${{ matrix.db.name }}
MYSQL_USER: user
MYSQL_PASSWORD: userpass
MYSQL_ROOT_PASSWORD: rootpass
POSTGRES_DB: ${{ matrix.db.name }}
POSTGRES_USER: user
POSTGRES_PASSWORD: userpass
options: >-
--health-cmd "${{ matrix.db.health_cmd }}"
--health-interval 10s
--health-timeout 5s
--health-retries 5

env:
DB_DRIVER: ${{ matrix.db.driver }}
DB_HOST: 127.0.0.1
DB_PORT: ${{ matrix.db.port }}
DB_USERNAME: user
DB_PASSWORD: userpass
DB_NAME: ${{ matrix.db.name }}
DB_COLLATION: ${{ matrix.db.collation }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: pdo_mysql, pdo_pgsql
coverage: none

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run tests
run: vendor/bin/phpunit
20 changes: 10 additions & 10 deletions tests/Entity/AncestorTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,36 @@ public function testAncestorsScope(): void
{
$entity = Entity::find(12);

$ancestors = $entity->ancestors()->get();
$ancestors = $entity->ancestors()->orderBy('id')->get();

static::assertCount(3, $ancestors);
static::assertEquals([11, 10, 9], $ancestors->modelKeys());
static::assertEquals([9, 10, 11], $ancestors->modelKeys());
}

public function testAncestorsOfScope(): void
{
$ancestors = Entity::ancestorsOf(12)->get();
$ancestors = Entity::ancestorsOf(12)->orderBy('id')->get();

static::assertCount(3, $ancestors);
static::assertEquals([11, 10, 9], $ancestors->modelKeys());
static::assertEquals([9, 10, 11], $ancestors->modelKeys());
}

public function testAncestorsWithSelfScope(): void
{
$entity = Entity::find(12);

$ancestors = $entity->ancestorsWithSelf()->get();
$ancestors = $entity->ancestorsWithSelf()->orderBy('id')->get();

static::assertCount(4, $ancestors);
static::assertEquals([12, 11, 10, 9], $ancestors->modelKeys());
static::assertEquals([9, 10, 11, 12], $ancestors->modelKeys());
}

public function testAncestorsWithSelfOfScope(): void
{
$ancestors = Entity::ancestorsWithSelfOf(12)->get();
$ancestors = Entity::ancestorsWithSelfOf(12)->orderBy('id')->get();

static::assertCount(4, $ancestors);
static::assertEquals([12, 11, 10, 9], $ancestors->modelKeys());
static::assertEquals([9, 10, 11, 12], $ancestors->modelKeys());
}

public function testGetAncestorsShouldNotBeEmpty(): void
Expand All @@ -67,12 +67,12 @@ public function testAncestorsWhere(): void
{
$entity = Entity::find(12);

$ancestors = $entity->ancestors()->where('position', '<', 2)->get();
$ancestors = $entity->ancestors()->where('position', '<', 2)->orderBy('id')->get();

static::assertInstanceOf(EntityCollection::class, $ancestors);
static::assertCount(2, $ancestors);
static::assertContainsOnlyInstancesOf(Entity::class, $ancestors);
static::assertEquals([11, 10], $ancestors->modelKeys());
static::assertEquals([10, 11], $ancestors->modelKeys());
}

public function testCountAncestors(): void
Expand Down
10 changes: 5 additions & 5 deletions tests/Entity/DescendantTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public function testDescendantsScope(): void
{
$entity = Entity::find(9);

$descendants = $entity->descendants()->get();
$descendants = $entity->descendants()->orderBy('id')->get();

static::assertCount(6, $descendants);
static::assertEquals([10, 11, 12, 13, 14, 15], $descendants->modelKeys());
}

public function testDescendantsOfScope(): void
{
$descendants = Entity::descendantsOf(9)->get();
$descendants = Entity::descendantsOf(9)->orderBy('id')->get();

static::assertCount(6, $descendants);
static::assertEquals([10, 11, 12, 13, 14, 15], $descendants->modelKeys());
Expand All @@ -37,15 +37,15 @@ public function testDescendantsWithSelfScope(): void
{
$entity = Entity::find(9);

$descendants = $entity->descendantsWithSelf()->get();
$descendants = $entity->descendantsWithSelf()->orderBy('id')->get();

static::assertCount(7, $descendants);
static::assertEquals([9, 10, 11, 12, 13, 14, 15], $descendants->modelKeys());
}

public function testDescendantsWithSelfOfScope(): void
{
$descendants = Entity::descendantsWithSelfOf(9)->get();
$descendants = Entity::descendantsWithSelfOf(9)->orderBy('id')->get();

static::assertCount(7, $descendants);
static::assertEquals([9, 10, 11, 12, 13, 14, 15], $descendants->modelKeys());
Expand All @@ -63,7 +63,7 @@ public function testGetDescendants(): void

public function testGetDescendantsWhere(): void
{
$descendants = Entity::find(9)->descendants()->where('position', '=', 1)->get();
$descendants = Entity::find(9)->descendants()->where('position', '=', 1)->orderBy('id')->get();

static::assertCount(1, $descendants);
static::assertEquals([13], $descendants->modelKeys());
Expand Down
Loading