-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load classes from autoloader classmap if authoritative (#383)
* load classes from autoloader classmap if authoritative * add authoritative classmap example * run in ci * better test logic * remove dead code * another test that loads and run "Tests" folder classes * add README.md
- Loading branch information
Showing
11 changed files
with
187 additions
and
15 deletions.
There are no files selected for viewing
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
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
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,8 @@ | ||
# Authoritative classmap example | ||
|
||
This example demonstrates how an authoritative classmap from composer | ||
can be used to limit parsed files: | ||
|
||
- `run_example_authoritative.php` will discard `Tests` folder | ||
- `run_example_non_authoritative.php` will try to parse `Tests` folder but throws an exception because of missing PHPUnit (--no-dev) | ||
- `run_example_non_authoritative_with_dev.php` will parse and run `Tests` folder |
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,47 @@ | ||
{ | ||
"name": "ecotone/quickstart", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Dariusz Gafka", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"App\\": "src" | ||
}, | ||
"exclude-from-classmap": [ | ||
"**/Tests/" | ||
] | ||
}, | ||
"require": { | ||
"ecotone/lite-amqp-starter": "^1.0.1" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.6", | ||
"wikimedia/composer-merge-plugin": "^2.1" | ||
}, | ||
"scripts": { | ||
"tests:ci": [ | ||
"php run_example_authoritative.php", | ||
"php run_example_non_authoritative.php", | ||
"php run_example_non_authoritative_with_dev.php" | ||
] | ||
}, | ||
"config": { | ||
"sort-packages": true, | ||
"allow-plugins": { | ||
"wikimedia/composer-merge-plugin": true | ||
} | ||
}, | ||
"extra": { | ||
"merge-plugin": { | ||
"include": [ | ||
"../../packages/local_packages.json" | ||
] | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
20 changes: 20 additions & 0 deletions
20
quickstart-examples/AuthoritativeClassmap/run_example_authoritative.php
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,20 @@ | ||
<?php | ||
|
||
use App\Domain\Event\CustomerRegistered; | ||
use Ecotone\Lite\EcotoneLiteApplication; | ||
use Ecotone\Messaging\Config\ServiceConfiguration; | ||
|
||
echo "Running example with authoritative classmap (--no-dev)\n"; | ||
exec("composer update --ignore-platform-reqs --classmap-authoritative --no-dev"); | ||
|
||
require __DIR__ . "/vendor/autoload.php"; | ||
$messagingSystem = EcotoneLiteApplication::bootstrap( | ||
pathToRootCatalog: __DIR__, | ||
serviceConfiguration: ServiceConfiguration::createWithDefaults() | ||
->doNotLoadCatalog() | ||
->withNamespaces(["App"]), | ||
); | ||
|
||
$messagingSystem->getEventBus()->publish(new CustomerRegistered(1)); | ||
|
||
echo "Customer registered\n"; |
27 changes: 27 additions & 0 deletions
27
quickstart-examples/AuthoritativeClassmap/run_example_non_authoritative.php
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,27 @@ | ||
<?php | ||
|
||
use App\Domain\Event\CustomerRegistered; | ||
use Ecotone\Lite\EcotoneLiteApplication; | ||
use Ecotone\Messaging\Config\ServiceConfiguration; | ||
|
||
echo "Running example with non authoritative classmap (--no-dev)\n"; | ||
exec("composer update --ignore-platform-reqs --no-dev"); | ||
|
||
require __DIR__ . "/vendor/autoload.php"; | ||
try { | ||
$messagingSystem = EcotoneLiteApplication::bootstrap( | ||
pathToRootCatalog: __DIR__, | ||
serviceConfiguration: ServiceConfiguration::createWithDefaults() | ||
->doNotLoadCatalog() | ||
->withNamespaces(["App"]), | ||
); | ||
|
||
throw new Exception("ERROR: Expected an error to be thrown !"); | ||
} catch (Error $e) { | ||
$isExpectedError = 'Class "PHPUnit\Framework\TestCase" not found' === $e->getMessage(); | ||
if ($isExpectedError) { | ||
echo "Correctly received an error: {$e->getMessage()}\n"; | ||
} else { | ||
throw new Exception("Unexpected error", previous: $e); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
quickstart-examples/AuthoritativeClassmap/run_example_non_authoritative_with_dev.php
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,20 @@ | ||
<?php | ||
|
||
use App\Domain\Event\CustomerRegistered; | ||
use Ecotone\Lite\EcotoneLiteApplication; | ||
use Ecotone\Messaging\Config\ServiceConfiguration; | ||
|
||
echo "Running example with non authoritative classmap and dev dependencies\n"; | ||
exec("composer update --ignore-platform-reqs"); | ||
|
||
require __DIR__ . "/vendor/autoload.php"; | ||
$messagingSystem = EcotoneLiteApplication::bootstrap( | ||
pathToRootCatalog: __DIR__, | ||
serviceConfiguration: ServiceConfiguration::createWithDefaults() | ||
->doNotLoadCatalog() | ||
->withNamespaces(["App"]), | ||
); | ||
|
||
$messagingSystem->getEventBus()->publish(new CustomerRegistered(1)); | ||
|
||
echo "Customer registered\n"; |
15 changes: 15 additions & 0 deletions
15
quickstart-examples/AuthoritativeClassmap/src/Domain/Event/CustomerRegistered.php
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,15 @@ | ||
<?php | ||
|
||
namespace App\Domain\Event; | ||
|
||
/* | ||
* licence Apache-2.0 | ||
*/ | ||
class CustomerRegistered | ||
{ | ||
public function __construct( | ||
public int $customerId, | ||
) | ||
{ | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...start-examples/AuthoritativeClassmap/src/Tests/ClassExcludedFromClassmapWithAttribute.php
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,16 @@ | ||
<?php | ||
|
||
namespace App\Tests; | ||
|
||
use App\Domain\Event\CustomerRegistered; | ||
use Ecotone\Modelling\Attribute\EventHandler; | ||
|
||
class ClassExcludedFromClassmapWithAttribute | ||
{ | ||
#[EventHandler(endpointId: "test")] | ||
public function event_handler_for_tests(CustomerRegistered $event) : void | ||
{ | ||
echo "Event handler for tests\n"; | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
quickstart-examples/AuthoritativeClassmap/src/Tests/TestInsideSrcFolderTest.php
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,10 @@ | ||
<?php | ||
|
||
namespace App\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class TestInsideSrcFolderTest extends TestCase | ||
{ | ||
|
||
} |
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