Skip to content

Commit

Permalink
Add makefile and test namespaces check script
Browse files Browse the repository at this point in the history
  • Loading branch information
veteran29 committed Jul 24, 2023
1 parent fd8e783 commit 2b0bb8b
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
7 changes: 7 additions & 0 deletions api-platform/.idea/symfony2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions api-platform/api/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Default values
env = dev
colors = --colors=always

# Executables
EXEC_PHP = docker-compose exec -T php

ifeq ($(ci),true)
fixerDryRun = --dry-run
coverage = --coverage-text --coverage-cobertura cobertura-report.xml
force = true
endif
ifeq ($(force),true)
forceDrop = --force
endif

cs:
$(EXEC_PHP) php tests/check-namespaces.php $(force)
$(EXEC_PHP) php vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix $(fixerDryRun)
# $(EXEC_PHP) php vendor/phpstan/phpstan/phpstan analyse --memory-limit=512M

$(EXEC_PHP) php bin/console lint:twig templates/
$(EXEC_PHP) php bin/console lint:yaml --parse-tags config/
$(EXEC_PHP) php bin/console doctrine:schema:validate --env=$(env)
$(EXEC_PHP) php bin/console doctrine:mapping:info --env=$(env)

db:
$(EXEC_PHP) php bin/console doctrine:database:drop --if-exists $(forceDrop) --env=$(env)
$(EXEC_PHP) php bin/console doctrine:database:create --if-not-exists --env=$(env)
$(EXEC_PHP) php bin/console doctrine:migration:migrate --no-interaction --env=$(env)

fixtures:
# $(EXEC_PHP) php bin/console doctrine:fixtures:load --append --group=default --no-interaction --env=$(env)

test:
make db env=test force=true
make test-ci

test-ci:
make fixtures env=test
$(EXEC_PHP) bin/phpunit --testdox $(coverage)
60 changes: 60 additions & 0 deletions api-platform/api/tests/check-namespaces.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

/**
* @author https://github.com/jskowronski39, modified by https://github.com/veteran29
* @license MIT
*/
use Symfony\Component\Finder\Finder;

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

$testDirs = [
'functional'.DIRECTORY_SEPARATOR,
'unit'.DIRECTORY_SEPARATOR,
];

$testFileSuffixes = [
'Test.php',
];

$finder = (new Finder())
->files()
->name(array_map(fn ($x) => "*{$x}", $testFileSuffixes))
->notName(['Abstract*', '*ScenarioTest.php'])
->in(__DIR__)
;

$mismatchedTestNamespaces = 0;

foreach ($finder as $testFile) {
$testFilePath = $testFile->getPathname();
$testSubjectFilePath = $testFilePath;

$testSubjectFilePath = str_replace('tests'.DIRECTORY_SEPARATOR, 'src'.DIRECTORY_SEPARATOR, $testSubjectFilePath);

$testSubjectFilePath = preg_replace('#'.DIRECTORY_SEPARATOR.'\w+?ActionTest\.php$#', '.php', $testSubjectFilePath);

$testSubjectFilePath = str_replace($testDirs, '', $testSubjectFilePath);
$testSubjectFilePath = str_replace($testFileSuffixes, '.php', $testSubjectFilePath);

if (!file_exists($testSubjectFilePath)) {
$testFilePath = str_replace(dirname(__DIR__), '', $testFilePath);
$testSubjectFilePath = str_replace(dirname(__DIR__), '', $testSubjectFilePath);

echo 'Subject of test:'.PHP_EOL;
echo $testFilePath.PHP_EOL.PHP_EOL;
echo 'Is expected to be found in:'.PHP_EOL;
echo $testSubjectFilePath.PHP_EOL;
echo str_repeat('-', 100).PHP_EOL.PHP_EOL;

++$mismatchedTestNamespaces;
}
}

if ($mismatchedTestNamespaces > 0 && ('true' !== ($argv[1] ?? false))) {
exit(1);
}

exit(0);

0 comments on commit 2b0bb8b

Please sign in to comment.