Skip to content

Commit

Permalink
Enhancement: Show and validate Doctrine mapping information
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Mar 13, 2020
1 parent fb65c38 commit 10e4003
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.dependabot/ export-ignore
/.github/ export-ignore
/config/ export-ignore
/test/ export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ jobs:
if: "matrix.dependencies == 'highest'"
run: "composer update --no-interaction --no-progress --no-suggest"

- name: "Show Doctrine mapping information"
run: "vendor/bin/doctrine orm:info"

- name: "Validate Doctrine schema"
run: "vendor/bin/doctrine orm:validate-schema --skip-sync"

- name: "Run auto-review tests with phpunit/phpunit"
run: "vendor/bin/phpunit --configuration=test/AutoReview/phpunit.xml"

Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ MIN_COVERED_MSI:=84
MIN_MSI:=53

.PHONY: it
it: coding-standards dependency-analysis static-code-analysis tests ## Runs the coding-standards, dependency-analysis, static-code-analysis, and tests targets
it: coding-standards dependency-analysis static-code-analysis doctrine tests ## Runs the coding-standards, dependency-analysis, static-code-analysis, doctrine, and tests targets

.PHONY: code-coverage
code-coverage: vendor ## Collects coverage from running unit tests with phpunit/phpunit
Expand All @@ -18,6 +18,11 @@ coding-standards: vendor ## Fixes code style issues with friendsofphp/php-cs-fix
dependency-analysis: vendor ## Runs a dependency analysis with maglnet/composer-require-checker
docker run --interactive --rm --tty --volume ${PWD}:/app webfactory/composer-require-checker:2.1.0 check --config-file=composer-require-checker.json

.PHONY: doctrine
doctrine: vendor ## Shows and validates Docrine mapping information
vendor/bin/doctrine orm:info
vendor/bin/doctrine orm:validate-schema --skip-sync

.PHONY: help
help: ## Displays this list of targets with descriptions
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}'
Expand Down
30 changes: 30 additions & 0 deletions config/cli-config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2020 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/factory-bot
*/

use Doctrine\ORM;

require_once __DIR__ . '/../vendor/autoload.php';

$filename = include __DIR__ . '/entity-manager.php';

$entityManager = $filename;

if (!$entityManager instanceof ORM\EntityManagerInterface) {
throw new \RuntimeException(\sprintf(
'File "%s" should return an instance of "%s" that can be used in tests, but it does not.',
$filename,
ORM\EntityManagerInterface::class
));
}

return ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager);
31 changes: 31 additions & 0 deletions config/entity-manager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2020 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/factory-bot
*/

use Doctrine\ORM;

require_once __DIR__ . '/../vendor/autoload.php';

$configuration = ORM\Tools\Setup::createAnnotationMetadataConfiguration(
[
__DIR__ . '/../test/Fixture/Entity',
],
true
);

return ORM\EntityManager::create(
[
'driver' => 'pdo_sqlite',
'path' => ':memory:',
],
$configuration
);
16 changes: 16 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@
<code>getName</code>
</MissingReturnType>
</file>
<file src="test/Integration/AbstractTestCase.php">
<MixedAssignment occurrences="1">
<code>$entityManager</code>
</MixedAssignment>
<UnresolvableInclude occurrences="1">
<code>include $filename</code>
</UnresolvableInclude>
</file>
<file src="test/Integration/FixtureFactoryTest.php">
<MixedAssignment occurrences="2">
<code>$ss</code>
Expand All @@ -199,6 +207,14 @@
<code>getId</code>
</MixedMethodCall>
</file>
<file src="test/Unit/AbstractTestCase.php">
<MixedAssignment occurrences="1">
<code>$entityManager</code>
</MixedAssignment>
<UnresolvableInclude occurrences="1">
<code>include $filename</code>
</UnresolvableInclude>
</file>
<file src="test/Unit/Definition/DefinitionsTest.php">
<MixedAssignment occurrences="1">
<code>$definitions</code>
Expand Down
25 changes: 11 additions & 14 deletions test/Integration/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,17 @@ abstract class AbstractTestCase extends Framework\TestCase
{
final protected static function createEntityManager(): ORM\EntityManagerInterface
{
$configuration = ORM\Tools\Setup::createAnnotationMetadataConfiguration(
[
__DIR__ . '/../Fixture/Entity',
],
true
);

$entityManager = ORM\EntityManager::create(
[
'driver' => 'pdo_sqlite',
'path' => ':memory:',
],
$configuration
);
$filename = __DIR__ . '/../../config/entity-manager.php';

$entityManager = include $filename;

if (!$entityManager instanceof ORM\EntityManagerInterface) {
throw new \RuntimeException(\sprintf(
'File "%s" should return an instance of "%s" that can be used in tests, but it does not.',
$filename,
ORM\EntityManagerInterface::class
));
}

$schemaTool = new ORM\Tools\SchemaTool($entityManager);

Expand Down
27 changes: 13 additions & 14 deletions test/Unit/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@ abstract class AbstractTestCase extends Framework\TestCase
{
final protected static function createEntityManager(): ORM\EntityManagerInterface
{
$configuration = ORM\Tools\Setup::createAnnotationMetadataConfiguration(
[
__DIR__ . '/../Fixture/Entity',
],
true
);

return ORM\EntityManager::create(
[
'driver' => 'pdo_sqlite',
'path' => ':memory:',
],
$configuration
);
$filename = __DIR__ . '/../../config/entity-manager.php';

$entityManager = include $filename;

if (!$entityManager instanceof ORM\EntityManagerInterface) {
throw new \RuntimeException(\sprintf(
'File "%s" should return an instance of "%s" that can be used in tests, but it does not.',
$filename,
ORM\EntityManagerInterface::class
));
}

return $entityManager;
}
}

0 comments on commit 10e4003

Please sign in to comment.