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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ indent_style = tab
indent_size = tab
tab_width = 4

[{*.json, *.yaml, *.yml, *.md}]
[*.{json,yaml,yml,md}]
indent_style = space
indent_size = 2
6 changes: 3 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Not archived
.docs export-ignore
tests export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
phpstan.neon export-ignore
Makefile export-ignore
README.md export-ignore
phpstan.neon export-ignore
ruleset.xml export-ignore
tests export-ignore
10 changes: 0 additions & 10 deletions .github/.kodiak.toml

This file was deleted.

5 changes: 3 additions & 2 deletions .github/workflows/codesniffer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: "Codesniffer"

on:
pull_request:
workflow_dispatch:

push:
branches: ["*"]
Expand All @@ -10,8 +11,8 @@ on:
- cron: "0 8 * * 1"

jobs:
build:
codesniffer:
name: "Codesniffer"
uses: contributte/.github/.github/workflows/codesniffer.yml@v1
uses: contributte/.github/.github/workflows/codesniffer.yml@master
with:
php: "8.2"
18 changes: 18 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Coverage"

on:
pull_request:
workflow_dispatch:

push:
branches: ["*"]

schedule:
- cron: "0 9 * * 1"

jobs:
coverage:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester-coverage-v2.yml@master
with:
php: "8.2"
7 changes: 4 additions & 3 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ name: "Phpstan"

on:
pull_request:
workflow_dispatch:

push:
branches: ["*"]

schedule:
- cron: "0 8 * * 1"
- cron: "0 10 * * 1"

jobs:
build:
phpstan:
name: "Phpstan"
uses: contributte/.github/.github/workflows/phpstan.yml@v1
uses: contributte/.github/.github/workflows/phpstan.yml@master
with:
php: "8.2"
28 changes: 18 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,36 @@ name: "Nette Tester"

on:
pull_request:
workflow_dispatch:

push:
branches: ["*"]

schedule:
- cron: "0 8 * * 1"
- cron: "0 10 * * 1"

jobs:
build84:
test85:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester-mysql.yml@v1
uses: contributte/.github/.github/workflows/nette-tester-mysql.yml@master
with:
php: "8.4"
php: "8.5"

build83:
test84:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester-mysql.yml@v1
uses: contributte/.github/.github/workflows/nette-tester-mysql.yml@master
with:
php: "8.3"
php: "8.4"

build82:
test83:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester-mysql.yml@v1
uses: contributte/.github/.github/workflows/nette-tester-mysql.yml@master
with:
php: "8.2"
php: "8.3"

test82:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester-mysql.yml@master
with:
php: "8.2"
composer: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable --prefer-lowest"
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
/composer.lock

# Tests
/temp
/coverage.xml
/tests/tmp
/coverage.*
/tests/**/*.log
/tests/**/*.html
/tests/**/*.expected
/tests/**/*.actual
26 changes: 12 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
"nextras/dbal": "^5.0.0"
},
"require-dev": {
"contributte/qa": "^0.4.0",
"contributte/tester": "^0.3.0",
"nette/di": "^3.0.1",
"nextras/orm": "^5.0.0",
"mockery/mockery": "^1.3.0",
"phpstan/phpstan": "^1.0.0",
"phpstan/phpstan-strict-rules": "^1.0.0",
"phpstan/phpstan-deprecation-rules": "^1.0.0",
"phpstan/phpstan-nette": "^1.0.0"
"contributte/phpstan": "~0.2.0",
"contributte/qa": "~0.4.0",
"contributte/tester": "~0.3.0",
"mockery/mockery": "^1.6.0",
"nette/di": "^3.2.0",
"nextras/orm": "^5.0.0"
},
"autoload": {
"psr-4": {
Expand All @@ -37,14 +34,15 @@
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "0.7.x-dev"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"extra": {
"branch-alias": {
"dev-master": "0.7.x-dev"
}
}
}
14 changes: 10 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
includes:
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/phpstan/phpstan-nette/extension.neon
- vendor/phpstan/phpstan-nette/rules.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/contributte/phpstan/phpstan.neon

parameters:
level: 9
phpVersion: 80200

scanDirectories:
- src

fileExtensions:
- php

paths:
- src

ignoreErrors:
- identifier: trait.unused
12 changes: 8 additions & 4 deletions ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@
<element key="src" value="Contributte\Nextras\Orm\QueryObject"/>
<element key="tests" value="Tests"/>
</property>
<property name="extensions" type="array">
<element value="php"/>
<element value="phpt"/>
</property>
</properties>
</rule>

<!-- Exclude rules not applicable to .phpt test cases (inline classes without namespaces) -->
<!-- Exclude class naming rules for test files with inline helper classes -->
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName.NoMatchBetweenTypeNameAndFileName">
<exclude-pattern>/tests/Cases</exclude-pattern>
</rule>
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
<exclude-pattern>/tests/Cases</exclude-pattern>
</rule>
Expand All @@ -23,9 +30,6 @@
<rule ref="Squiz.Classes.ClassFileName.NoMatch">
<exclude-pattern>/tests/Cases</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName.NoMatchBetweenTypeNameAndFileName">
<exclude-pattern>/tests/Cases</exclude-pattern>
</rule>

<!-- Excludes -->
<exclude-pattern>/tests/tmp</exclude-pattern>
Expand Down
4 changes: 0 additions & 4 deletions tests/.coveralls.yml

This file was deleted.

10 changes: 0 additions & 10 deletions tests/.gitignore

This file was deleted.

22 changes: 20 additions & 2 deletions tests/Cases/E2E/BooksTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,37 @@ use Contributte\Nextras\Orm\QueryObject\Queryable;
use Contributte\Nextras\Orm\QueryObject\QueryObjectContextAwareManager;
use Contributte\Nextras\Orm\QueryObject\QueryObjectManager;
use Nette\DI\Container;
use Nextras\Dbal\Drivers\Exception\ConnectionException;
use Nextras\Dbal\IConnection;
use Nextras\Dbal\Result\Result;
use Nextras\Orm\Collection\ICollection;
use Tester\Assert;
use Tester\Environment;
use Tester\TestCase;
use Tests\Mocks\Model\Book\AllBooksExecutableQueryObject;
use Tests\Mocks\Model\Book\AllBooksQueryObject;
use Tests\Mocks\Model\Book\Book;
use Tests\Mocks\Model\Book\BookRepository;
use Tests\Mocks\Model\User\User;

require_once __DIR__ . '/../../bootstrap.php';

// nextras/orm 5.0.x is not yet compatible with PHP 8.5 (null array offset in AbstractEntity)
if (PHP_VERSION_ID >= 80500) {
Environment::skip('nextras/orm is not yet compatible with PHP 8.5');
}

$container = require_once __DIR__ . '/../../bootstrap.container.php';

/** @var IConnection $connection */
$connection = $container->getByType(IConnection::class);

try {
$connection->connect();
} catch (ConnectionException $e) {
Environment::skip('MySQL connection not available: ' . $e->getMessage());
}

final class BooksTest extends TestCase
{

Expand Down Expand Up @@ -124,8 +142,8 @@ final class BooksTest extends TestCase
$sql = file_get_contents(__DIR__ . '/../../Fixtures/mysql.sql');
assert($sql !== false);

foreach (array_filter(array_map('trim', explode(';', $sql))) as $query) {
$connection->query('%raw', $query);
foreach (array_filter(array_map('trim', explode(';', $sql))) as $statement) {
$connection->query('%raw', $statement);
}
}

Expand Down
17 changes: 11 additions & 6 deletions tests/Cases/Exceptions.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,37 @@

use Contributte\Nextras\Orm\QueryObject\Exception\InvalidHydrationModeException;
use Contributte\Nextras\Orm\QueryObject\Exception\InvalidObjectCreationException;
use Contributte\Tester\Toolkit;
use Tester\Assert;

require_once __DIR__ . '/../bootstrap.php';

test('InvalidHydrationModeException extends LogicException', function (): void {
// Test: InvalidHydrationModeException extends LogicException
Toolkit::test(static function (): void {
$exception = new InvalidHydrationModeException('Test message');

Assert::type(LogicException::class, $exception);
Assert::same('Test message', $exception->getMessage());
});

test('InvalidObjectCreationException extends LogicException', function (): void {
// Test: InvalidObjectCreationException extends LogicException
Toolkit::test(static function (): void {
$exception = new InvalidObjectCreationException('Creation failed');

Assert::type(LogicException::class, $exception);
Assert::same('Creation failed', $exception->getMessage());
});

test('InvalidHydrationModeException can be thrown and caught', function (): void {
Assert::exception(function (): void {
// Test: InvalidHydrationModeException can be thrown and caught
Toolkit::test(static function (): void {
Assert::exception(static function (): void {
throw new InvalidHydrationModeException('Invalid hydration mode "99"');
}, InvalidHydrationModeException::class, 'Invalid hydration mode "99"');
});

test('InvalidObjectCreationException can be thrown and caught', function (): void {
Assert::exception(function (): void {
// Test: InvalidObjectCreationException can be thrown and caught
Toolkit::test(static function (): void {
Assert::exception(static function (): void {
throw new InvalidObjectCreationException('Created object must be typed of QueryObject');
}, InvalidObjectCreationException::class, 'Created object must be typed of QueryObject');
});
7 changes: 5 additions & 2 deletions tests/Cases/ExecutableQueryObject.phpt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php declare(strict_types = 1);

use Contributte\Nextras\Orm\QueryObject\ExecutableQueryObject;
use Contributte\Tester\Toolkit;
use Nextras\Dbal\Connection;
use Nextras\Dbal\QueryBuilder\QueryBuilder;
use Nextras\Dbal\Result\Result;
Expand Down Expand Up @@ -48,7 +49,8 @@ class TestExecutableQueryObjectWithPostResult extends ExecutableQueryObject

}

test('ExecutableQueryObject builds query via fetch method', function (): void {
// Test: ExecutableQueryObject builds query via fetch method
Toolkit::test(static function (): void {
$connection = Mockery::mock(Connection::class);
$queryBuilder = Mockery::mock(QueryBuilder::class);

Expand All @@ -70,7 +72,8 @@ test('ExecutableQueryObject builds query via fetch method', function (): void {
Mockery::close();
});

test('ExecutableQueryObject execute method uses connection', function (): void {
// Test: ExecutableQueryObject execute method uses connection
Toolkit::test(static function (): void {
$connection = Mockery::mock(Connection::class);
$queryBuilder = Mockery::mock(QueryBuilder::class);
$result = Mockery::mock(Result::class);
Expand Down
3 changes: 2 additions & 1 deletion tests/Cases/QueryObject.phpt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php declare(strict_types = 1);

use Contributte\Tester\Toolkit;
use Nextras\Dbal\Platforms\IPlatform;
use Nextras\Dbal\QueryBuilder\QueryBuilder;
use Tester\Assert;
use Tests\Mocks\SimpleQueryObject;

require_once __DIR__ . '/../bootstrap.php';

test('QueryObject builds query via fetch method', function (): void {
Toolkit::test(static function (): void {
$platform = Mockery::mock(IPlatform::class);
$qo = new SimpleQueryObject();
$qb = $qo->fetch(new QueryBuilder($platform));
Expand Down
Loading