-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add makefile and test namespaces check script
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |