Skip to content

Commit

Permalink
Add way to run all examples
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd committed Oct 11, 2023
1 parent 69869b8 commit a6a7796
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 6 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"ramsey/uuid": "^4.5",
"symfony/cache": "^6.2",
"symfony/dotenv": "^6.2",
"symfony/finder": "^6.3",
"symfony/uid": "^6.3"
},
"autoload": {
Expand Down
66 changes: 65 additions & 1 deletion composer.lock

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

12 changes: 7 additions & 5 deletions examples/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

\ini_set('memory_limit', -1);

const __FLOW_DATA__ = __DIR__ . '/data';
const __FLOW_OUTPUT__ = __DIR__ . '/output';
const __FLOW_VAR__ = __DIR__ . '/var';
const __FLOW_VAR_RUN__ = __DIR__ . '/var/run';
const __FLOW_SRC__ = __DIR__ . '/../src';
if (!\defined('__FLOW_DATA__')) {
\define('__FLOW_DATA__', __DIR__ . '/data');
\define('__FLOW_OUTPUT__', __DIR__ . '/output');
\define('__FLOW_VAR__', __DIR__ . '/var');
\define('__FLOW_VAR_RUN__', __DIR__ . '/var/run');
\define('__FLOW_SRC__', __DIR__ . '/../src');
}

if (!\is_dir(__FLOW_VAR__)) {
\mkdir(__FLOW_VAR__);
Expand Down
39 changes: 39 additions & 0 deletions examples/run_examples.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env php
<?php declare(strict_types=1);

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

use Symfony\Component\Finder\Finder;

if ($_ENV['FLOW_PHAR_APP'] ?? false) {
print PHP_EOL . 'This script cannot be run in PHAR, please use CLI approach.' . PHP_EOL;

exit(1);
}

if (false === \in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
print PHP_EOL . 'This script may only be invoked from a command line, got "' . PHP_SAPI . '"' . PHP_EOL;

exit(1);
}

\ini_set('memory_limit', -1);

print "Running all available examples.\n";

$finder = new Finder();
$finder->in(__DIR__ . '/topics')
// async & database examples require additional manual setup to be run properly
->exclude([__DIR__ . '/topics/async', __DIR__ . '/topics/db'])
->files()
->name('*.php');

foreach ($finder as $file) {
print "\nExample: {$file->getRelativePathname()}\n";

try {
include $file->getRealPath();
} catch (\Exception $e) {
print "Example failed: {$e->getMessage()}\n";
}
}

0 comments on commit a6a7796

Please sign in to comment.