Skip to content

Commit 9245951

Browse files
authored
Test generator, step 1 (#638)
It's working, but not complete.
1 parent 732d677 commit 9245951

28 files changed

+777
-8
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The following system dependencies are required:
1111

1212
- `composer`, as recommended in the [PHP track installation docs][exercism-track-installation-composer].
1313
- [`bash` shell][gnu-bash]
14+
- PHP V8.2+ CLI
1415

1516
Run the following commands to get started with this project:
1617

@@ -51,6 +52,20 @@ composer lint:fix # Automatically fix codestyle issues
5152
- CI is run on all pull requests, it must pass the required checks for merge.
5253
- CI is running all tests on PHP 8.0 to PHP 8.2
5354

55+
## Generating new practice exercises
56+
57+
Use `bin/configlet create --practice-exercise <slug>` to create the exercism resources required.
58+
This provides you with the directories and files in `exercises/practice/<slug>`.
59+
Look into `tests.toml` for which test cases **not** to implement / generate and mark them with `include = false`.
60+
61+
Test generator MVP used like this:
62+
63+
```shell
64+
composer -d contribution/generator install
65+
contribution/generator/bin/console app:create-tests '<slug>'
66+
composer lint:fix
67+
```
68+
5469
[exercism-configlet]: https://exercism.org/docs/building/configlet
5570
[exercism-docs]: https://exercism.org/docs
5671
[exercism-track-home]: https://exercism.org/docs/tracks/php

contribution/generator/.env

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# In all environments, the following files are loaded if they exist,
2+
# the latter taking precedence over the former:
3+
#
4+
# * .env contains default values for the environment variables needed by the app
5+
# * .env.local uncommitted file with local overrides
6+
# * .env.$APP_ENV committed environment-specific defaults
7+
# * .env.$APP_ENV.local uncommitted environment-specific overrides
8+
#
9+
# Real environment variables win over .env files.
10+
#
11+
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
12+
# https://symfony.com/doc/current/configuration/secrets.html
13+
#
14+
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
15+
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
16+
17+
###> symfony/framework-bundle ###
18+
APP_ENV=dev
19+
APP_SECRET=1be0b2dbd34333efb23cfefcff0ff718
20+
###< symfony/framework-bundle ###

contribution/generator/.env.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# define your env variables for the test env here
2+
KERNEL_CLASS='App\Kernel'
3+
APP_SECRET='$ecretf0rt3st'
4+
SYMFONY_DEPRECATIONS_HELPER=999999
5+
PANTHER_APP_ENV=panther
6+
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots

contribution/generator/.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# IDEs
2+
.idea
3+
4+
###> symfony/framework-bundle ###
5+
/.env.local
6+
/.env.local.php
7+
/.env.*.local
8+
/config/secrets/prod/prod.decrypt.private.php
9+
/public/bundles/
10+
/var/
11+
/vendor/
12+
###< symfony/framework-bundle ###
13+
14+
###> phpunit/phpunit ###
15+
/phpunit.xml
16+
.phpunit.result.cache
17+
###< phpunit/phpunit ###

contribution/generator/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Auto Creating of tests for Exercism PHP Track
2+
3+
This is a small poc on how we could auto generate tests for the PHP track based on the https://github.com/exercism/problem-specifications/.
4+
5+
How to test it:
6+
7+
```
8+
git clone https://github.com/tomasnorre/exercism-tests-generation.git
9+
cd exercism-tests-generation
10+
composer install
11+
bin/console app:create-tests
12+
vendor/bin/phpunit src/Command/NucleotideCountTest.php
13+
```
14+
15+
If you now make a `git status` you will see that the `src/Command/NucleotideCountTest.php` and you can now inspect the auto generated tests.
16+
17+
It's all based on the `nikic/php-parser` and the https://github.com/exercism/problem-specifications/ repository, I have made a local copy of that on file
18+
for now to spare the http-requests.
19+
20+
Let me know what you think.

contribution/generator/bin/console

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use App\Kernel;
5+
use Symfony\Bundle\FrameworkBundle\Console\Application;
6+
7+
if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
8+
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
9+
}
10+
11+
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
12+
13+
return function (array $context) {
14+
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
15+
16+
return new Application($kernel);
17+
};

contribution/generator/composer.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"type": "project",
3+
"license": "proprietary",
4+
"minimum-stability": "stable",
5+
"prefer-stable": true,
6+
"require": {
7+
"php": ">=8.2",
8+
"ext-ctype": "*",
9+
"ext-iconv": "*",
10+
"nikic/php-parser": "^5.0",
11+
"symfony/console": "7.0.*",
12+
"symfony/dotenv": "7.0.*",
13+
"symfony/flex": "^2",
14+
"symfony/framework-bundle": "7.0.*",
15+
"symfony/runtime": "7.0.*",
16+
"symfony/yaml": "7.0.*"
17+
},
18+
"require-dev": {
19+
"phpunit/phpunit": "^11.0",
20+
"symfony/maker-bundle": "^1.54"
21+
},
22+
"config": {
23+
"allow-plugins": {
24+
"php-http/discovery": true,
25+
"symfony/flex": true,
26+
"symfony/runtime": true
27+
},
28+
"sort-packages": true
29+
},
30+
"autoload": {
31+
"psr-4": {
32+
"App\\": "src/"
33+
}
34+
},
35+
"autoload-dev": {
36+
"psr-4": {
37+
"App\\Tests\\": "tests/"
38+
}
39+
},
40+
"replace": {
41+
"symfony/polyfill-ctype": "*",
42+
"symfony/polyfill-iconv": "*",
43+
"symfony/polyfill-php72": "*",
44+
"symfony/polyfill-php73": "*",
45+
"symfony/polyfill-php74": "*",
46+
"symfony/polyfill-php80": "*",
47+
"symfony/polyfill-php81": "*",
48+
"symfony/polyfill-php82": "*"
49+
},
50+
"scripts": {
51+
"auto-scripts": {
52+
"cache:clear": "symfony-cmd",
53+
"assets:install %PUBLIC_DIR%": "symfony-cmd"
54+
},
55+
"post-install-cmd": [
56+
"@auto-scripts"
57+
],
58+
"post-update-cmd": [
59+
"@auto-scripts"
60+
]
61+
},
62+
"conflict": {
63+
"symfony/symfony": "*"
64+
},
65+
"extra": {
66+
"symfony": {
67+
"allow-contrib": false,
68+
"require": "7.0.*"
69+
}
70+
}
71+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
return [
4+
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
5+
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
6+
];
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
framework:
2+
cache:
3+
# Unique name of your app: used to compute stable namespaces for cache keys.
4+
#prefix_seed: your_vendor_name/app_name
5+
6+
# The "app" cache stores to the filesystem by default.
7+
# The data in this cache should persist between deploys.
8+
# Other options include:
9+
10+
# Redis
11+
#app: cache.adapter.redis
12+
#default_redis_provider: redis://localhost
13+
14+
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
15+
#app: cache.adapter.apcu
16+
17+
# Namespaced pools use the above "app" backend by default
18+
#pools:
19+
#my.dedicated.cache: null
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# see https://symfony.com/doc/current/reference/configuration/framework.html
2+
framework:
3+
secret: '%env(APP_SECRET)%'
4+
#csrf_protection: true
5+
6+
# Note that the session will be started ONLY if you read or write from it.
7+
session: true
8+
9+
#esi: true
10+
#fragments: true
11+
12+
when@test:
13+
framework:
14+
test: true
15+
session:
16+
storage_factory_id: session.storage.factory.mock_file

0 commit comments

Comments
 (0)