Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into native-models
Browse files Browse the repository at this point in the history
  • Loading branch information
JasperTey committed Sep 4, 2024
2 parents 0ade9ef + c213e3e commit e59a534
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2.0.0
uses: dependabot/fetch-metadata@v2.2.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [main]
pull_request:
branches: [main, next]
branches: [main, next, develop]

jobs:
test:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to `laravel-ddd` will be documented in this file.

## [1.1.2] - 2024-09-02
### Fixed
- During domain factory autoloading, ensure that `guessFactoryNamesUsing` returns a string when a domain factory is resolved.
- Resolve issues with failing tests caused by mutations to `composer.json` that weren't rolled back.

## [1.1.1] - 2024-04-17
### Added
- Ability to ignore folders during autoloading via `config('ddd.autoload_ignore')`, or register a custom filter callback via `DDD::filterAutoloadPathsUsing(callable $filter)`.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
"scripts": {
"post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi",
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
"test": "@composer dump-autoload && vendor/bin/pest",
"test-coverage": "@composer dump-autoload && vendor/bin/pest --coverage",
"format": "vendor/bin/pint",
"lint": "vendor/bin/pint"
},
Expand Down
4 changes: 2 additions & 2 deletions src/LaravelDDDServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class LaravelDDDServiceProvider extends PackageServiceProvider
public function configurePackage(Package $package): void
{
$this->app->scoped(DomainManager::class, function () {
return new DomainManager();
return new DomainManager;
});

$this->app->bind('ddd', DomainManager::class);
Expand Down Expand Up @@ -75,6 +75,6 @@ public function packageBooted()

public function packageRegistered()
{
(new DomainAutoloader())->autoload();
(new DomainAutoloader)->autoload();
}
}
4 changes: 1 addition & 3 deletions src/Listeners/CacheClearSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

class CacheClearSubscriber
{
public function __construct()
{
}
public function __construct() {}

public function handle(): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/Support/DomainAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ protected function handlePolicies(): void
protected function handleFactories(): void
{
Factory::guessFactoryNamesUsing(function (string $modelName) {
if (DomainResolver::isDomainClass($modelName)) {
return DomainFactory::factoryForModel($modelName);
if ($factoryName = DomainFactory::resolveFactoryName($modelName)) {
return $factoryName;
}

$appNamespace = static::appNamespace();
Expand Down
3 changes: 1 addition & 2 deletions src/ValueObjects/DomainNamespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public function __construct(
public readonly string $notifications,
public readonly string $resources,
public readonly string $rules,
) {
}
) {}

public static function from(string $domain, ?string $subdomain = null): self
{
Expand Down
3 changes: 1 addition & 2 deletions src/ValueObjects/DomainObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public function __construct(
public readonly string $fullyQualifiedName,
public readonly string $path,
public readonly ?string $type = null,
) {
}
) {}

public static function fromClass(string $fullyQualifiedClass, ?string $objectType = null): ?self
{
Expand Down
3 changes: 1 addition & 2 deletions src/ValueObjects/DomainObjectNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class DomainObjectNamespace
public function __construct(
public readonly string $type,
public readonly string $namespace,
) {
}
) {}

public static function make(string $key, string $domain, ?string $subdomain = null): self
{
Expand Down
3 changes: 3 additions & 0 deletions tests/.skeleton/bootstrap/providers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

return [];
8 changes: 4 additions & 4 deletions tests/Autoload/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
$this->setupTestApplication();

$this->afterApplicationCreated(function () {
(new DomainAutoloader())->autoload();
(new DomainAutoloader)->autoload();
});
});

Expand All @@ -35,7 +35,7 @@
$this->setupTestApplication();

$this->afterApplicationCreated(function () {
(new DomainAutoloader())->autoload();
(new DomainAutoloader)->autoload();
});
});

Expand Down Expand Up @@ -82,7 +82,7 @@
DomainCache::set('domain-commands', []);

$this->afterApplicationCreated(function () {
(new DomainAutoloader())->autoload();
(new DomainAutoloader)->autoload();
});

// command should not be recognized due to cached empty-state
Expand All @@ -94,7 +94,7 @@
DomainCache::clear();

$this->afterApplicationCreated(function () {
(new DomainAutoloader())->autoload();
(new DomainAutoloader)->autoload();
});

$this->artisan('invoice:deliver')->assertSuccessful();
Expand Down
4 changes: 2 additions & 2 deletions tests/Autoload/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Config::set('ddd.autoload.factories', true);

$this->afterApplicationCreated(function () {
(new DomainAutoloader())->autoload();
(new DomainAutoloader)->autoload();
});
});

Expand Down Expand Up @@ -52,7 +52,7 @@
Config::set('ddd.autoload.factories', false);

$this->afterApplicationCreated(function () {
(new DomainAutoloader())->autoload();
(new DomainAutoloader)->autoload();
});
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Autoload/PolicyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Config::set('ddd.autoload.factories', true);

$this->afterApplicationCreated(function () {
(new DomainAutoloader())->autoload();
(new DomainAutoloader)->autoload();
});
});

Expand Down
8 changes: 4 additions & 4 deletions tests/Autoload/ProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
]);

$this->afterApplicationCreated(function () {
(new DomainAutoloader())->autoload();
(new DomainAutoloader)->autoload();
});
});

Expand All @@ -34,7 +34,7 @@
]);

$this->afterApplicationCreated(function () {
(new DomainAutoloader())->autoload();
(new DomainAutoloader)->autoload();
});
});

Expand All @@ -57,7 +57,7 @@
DomainCache::set('domain-providers', []);

$this->afterApplicationCreated(function () {
(new DomainAutoloader())->autoload();
(new DomainAutoloader)->autoload();
});

expect(fn () => app('invoicing'))->toThrow(Exception::class);
Expand All @@ -68,7 +68,7 @@
DomainCache::clear();

$this->afterApplicationCreated(function () {
(new DomainAutoloader())->autoload();
(new DomainAutoloader)->autoload();
});

expect(app('invoicing'))->toEqual('invoicing-singleton');
Expand Down
7 changes: 7 additions & 0 deletions tests/Command/InstallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

use Illuminate\Support\Facades\Config;

beforeEach(function () {
$this->setupTestApplication();
});

it('publishes config', function () {
$path = config_path('ddd.php');

Expand Down Expand Up @@ -47,6 +51,9 @@
expect($after)->toEqual(config('ddd.domain_path'));

unlink(config_path('ddd.php'));

// Reset composer back to the factory state
$this->setDomainPathInComposer('Domain', 'src/Domain', reload: true);
})->with([
['src/Domain', 'Domain'],
['src/Domains', 'Domains'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Support/AutoloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
});

it('can run', function () {
$autoloader = new DomainAutoloader();
$autoloader = new DomainAutoloader;

$autoloader->autoload();
})->throwsNoExceptions();
13 changes: 8 additions & 5 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\File;
use Lunarstorm\LaravelDDD\LaravelDDDServiceProvider;
use Lunarstorm\LaravelDDD\Support\DomainCache;
use Orchestra\Testbench\TestCase as Orchestra;
use Symfony\Component\Process\Process;

Expand Down Expand Up @@ -136,8 +135,7 @@ protected function composerReload()

(new Process($command, base_path(), ['COMPOSER_MEMORY_LIMIT' => '-1']))
->setTimeout(null)
->run(function ($type, $output) {
});
->run(function ($type, $output) {});
}

protected function cleanSlate()
Expand All @@ -155,27 +153,32 @@ protected function cleanSlate()
File::deleteDirectory(base_path('src/Domains'));
File::deleteDirectory(app_path('Models'));

DomainCache::clear();
File::deleteDirectory(base_path('bootstrap/cache/ddd'));
}

protected function setupTestApplication()
{
File::copyDirectory(__DIR__.'/.skeleton/app', app_path());
File::copyDirectory(__DIR__.'/.skeleton/database', base_path('database'));
File::copyDirectory(__DIR__.'/.skeleton/src/Domain', base_path('src/Domain'));
File::copy(__DIR__.'/.skeleton/bootstrap/providers.php', base_path('bootstrap/providers.php'));
File::ensureDirectoryExists(app_path('Models'));

$this->setDomainPathInComposer('Domain', 'src/Domain');
}

protected function setDomainPathInComposer($domainNamespace, $domainPath)
protected function setDomainPathInComposer($domainNamespace, $domainPath, bool $reload = true)
{
$this->updateComposer(
set: [
[['autoload', 'psr-4', $domainNamespace.'\\'], $domainPath],
],
);

if ($reload) {
$this->composerReload();
}

return $this;
}
}

0 comments on commit e59a534

Please sign in to comment.