Skip to content

Don't assume PHPARKITECT_COMPOSER_INSTALL is not defined yet #401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

hgraca
Copy link
Contributor

@hgraca hgraca commented Jul 29, 2023

By default, the classmap is not loaded, so it's not possible to use functions like is_a to infer inheritance of classes under test. To solve this, the autoloader must be included in the config file, but then it will try to define this variable again, which will cause it to throw an error.

By default, the classmap is not loaded, so it's not possible to
use functions like `is_a` to infer inheritance of classes under test.
To solve this, the autoloader must be included in the config file, but then
it will try to define this variable again, which will cause it to throw an error.
@fain182
Copy link
Collaborator

fain182 commented Aug 5, 2023

Can you show a snippet of how you use is_a in the configuration file to better understand your needs?

@codecov-commenter
Copy link

codecov-commenter commented Aug 5, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.33%. Comparing base (976c200) to head (7b82aca).
Report is 130 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main     #401   +/-   ##
=========================================
  Coverage     94.33%   94.33%           
  Complexity      571      571           
=========================================
  Files            67       67           
  Lines          1500     1500           
=========================================
  Hits           1415     1415           
  Misses           85       85           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hgraca
Copy link
Contributor Author

hgraca commented Aug 5, 2023

Like this:

<?php

declare(strict_types=1);

use Arkitect\ClassSet;
use Arkitect\CLI\Config;
use Arkitect\Expression\ForClasses\HaveNameMatching;
use Arkitect\Expression\ForClasses\IsA;
use Arkitect\Rules\Rule;
use Hgraca\SymfonyBoilerplate\Infrastructure\CommandBus\Port\CommandHandlerInterface;

require_once dirname(__DIR__) . '/../vendor/autoload_runtime.php';

return static function (Config $config): void {
    $rootPath = realpath(__DIR__ . '/../..');

    $classSet = ClassSet::fromDir("$rootPath/src", "$rootPath/tests");

    $rules[] = Rule::allClasses()
        ->except(...$this->exceptionList)
        ->that(new IsA(CommandHandlerInterface::class))
        ->should(new HaveNameMatching('*CommandHandler'))
        ->because("our command handlers must be suffixed 'CommandHandler', to differentiate from 'QueryHandler' and 'MutatorHandler'.");

    $config->add($classSet, ...$rules);
};

I need to use the IsA expression there, as opposed to Implements, because Implements only checks for direct implementation, not implementation through the inheritance tree.

@micheleorselli
Copy link
Member

@hgraca release 0.5.4 allows to specify an extra autoloader as an option if you'd like to give it a try

@hgraca
Copy link
Contributor Author

hgraca commented May 4, 2025

@micheleorselli I rebased my fork, removed my hack, tested it in my current project from work and it works like a charm, as far as I can see.

tkx a lot!

I am therefore closing this PR.

@hgraca hgraca closed this May 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants