Add Behat

Add Behat as a dev dependency and add the example `ls` example.

Due to a deprecation error, I needed to downgrade to PHP 8.1 on stream,
though this would error the main `app:generate` command as I'm using
`readonly` classes that were introduced in PHP 8.2.
This commit is contained in:
Oliver Davies 2024-03-01 20:33:01 +00:00
parent 65070dfb2b
commit 0d774daca0
6 changed files with 293 additions and 22 deletions

View file

@ -70,6 +70,7 @@
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8",
"behat/behat": "^3.14",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "^6.4",

203
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "8f7c72036cf473ae396a2e66a30c45a1",
"content-hash": "e7d5bf85313a3f5cb74e96149e0c01ec",
"packages": [
{
"name": "doctrine/annotations",
@ -4504,6 +4504,205 @@
},
"time": "2022-10-31T08:38:03+00:00"
},
{
"name": "behat/behat",
"version": "v3.14.0",
"source": {
"type": "git",
"url": "https://github.com/Behat/Behat.git",
"reference": "2a3832d9cb853a794af3a576f9e524ae460f3340"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Behat/Behat/zipball/2a3832d9cb853a794af3a576f9e524ae460f3340",
"reference": "2a3832d9cb853a794af3a576f9e524ae460f3340",
"shasum": ""
},
"require": {
"behat/gherkin": "^4.9.0",
"behat/transliterator": "^1.2",
"ext-mbstring": "*",
"php": "^7.2 || ^8.0",
"psr/container": "^1.0 || ^2.0",
"symfony/config": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/console": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/event-dispatcher": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/translation": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/yaml": "^4.4 || ^5.0 || ^6.0 || ^7.0"
},
"require-dev": {
"herrera-io/box": "~1.6.1",
"phpspec/prophecy": "^1.15",
"phpunit/phpunit": "^8.5 || ^9.0",
"symfony/process": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"vimeo/psalm": "^4.8"
},
"suggest": {
"ext-dom": "Needed to output test results in JUnit format."
},
"bin": [
"bin/behat"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
}
},
"autoload": {
"psr-4": {
"Behat\\Hook\\": "src/Behat/Hook/",
"Behat\\Step\\": "src/Behat/Step/",
"Behat\\Behat\\": "src/Behat/Behat/",
"Behat\\Testwork\\": "src/Behat/Testwork/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Konstantin Kudryashov",
"email": "ever.zet@gmail.com",
"homepage": "http://everzet.com"
}
],
"description": "Scenario-oriented BDD framework for PHP",
"homepage": "http://behat.org/",
"keywords": [
"Agile",
"BDD",
"ScenarioBDD",
"Scrum",
"StoryBDD",
"User story",
"business",
"development",
"documentation",
"examples",
"symfony",
"testing"
],
"support": {
"issues": "https://github.com/Behat/Behat/issues",
"source": "https://github.com/Behat/Behat/tree/v3.14.0"
},
"time": "2023-12-09T13:55:02+00:00"
},
{
"name": "behat/gherkin",
"version": "v4.9.0",
"source": {
"type": "git",
"url": "https://github.com/Behat/Gherkin.git",
"reference": "0bc8d1e30e96183e4f36db9dc79caead300beff4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Behat/Gherkin/zipball/0bc8d1e30e96183e4f36db9dc79caead300beff4",
"reference": "0bc8d1e30e96183e4f36db9dc79caead300beff4",
"shasum": ""
},
"require": {
"php": "~7.2|~8.0"
},
"require-dev": {
"cucumber/cucumber": "dev-gherkin-22.0.0",
"phpunit/phpunit": "~8|~9",
"symfony/yaml": "~3|~4|~5"
},
"suggest": {
"symfony/yaml": "If you want to parse features, represented in YAML files"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.x-dev"
}
},
"autoload": {
"psr-0": {
"Behat\\Gherkin": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Konstantin Kudryashov",
"email": "ever.zet@gmail.com",
"homepage": "http://everzet.com"
}
],
"description": "Gherkin DSL parser for PHP",
"homepage": "http://behat.org/",
"keywords": [
"BDD",
"Behat",
"Cucumber",
"DSL",
"gherkin",
"parser"
],
"support": {
"issues": "https://github.com/Behat/Gherkin/issues",
"source": "https://github.com/Behat/Gherkin/tree/v4.9.0"
},
"time": "2021-10-12T13:05:09+00:00"
},
{
"name": "behat/transliterator",
"version": "v1.5.0",
"source": {
"type": "git",
"url": "https://github.com/Behat/Transliterator.git",
"reference": "baac5873bac3749887d28ab68e2f74db3a4408af"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Behat/Transliterator/zipball/baac5873bac3749887d28ab68e2f74db3a4408af",
"reference": "baac5873bac3749887d28ab68e2f74db3a4408af",
"shasum": ""
},
"require": {
"php": ">=7.2"
},
"require-dev": {
"chuyskywalker/rolling-curl": "^3.1",
"php-yaoi/php-yaoi": "^1.0",
"phpunit/phpunit": "^8.5.25 || ^9.5.19"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"Behat\\Transliterator\\": "src/Behat/Transliterator"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Artistic-1.0"
],
"description": "String transliterator",
"keywords": [
"i18n",
"slug",
"transliterator"
],
"support": {
"issues": "https://github.com/Behat/Transliterator/issues",
"source": "https://github.com/Behat/Transliterator/tree/v1.5.0"
},
"time": "2022-03-30T09:27:43+00:00"
},
{
"name": "doctrine/instantiator",
"version": "2.0.0",
@ -6814,5 +7013,5 @@
"platform-overrides": {
"php": "8.2"
},
"plugin-api-version": "2.3.0"
"plugin-api-version": "2.6.0"
}

View file

@ -0,0 +1,64 @@
<?php
use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
/**
* Defines application features from the specific context.
*/
class FeatureContext implements Context
{
/**
* Initializes context.
*
* Every scenario gets its own context instance.
* You can also pass arbitrary arguments to the
* context constructor through behat.yml.
*/
public function __construct()
{
}
/**
* @Given I am in a directory :arg1
*/
public function iAmInADirectory($dir)
{
if (!file_exists($dir)) {
mkdir($dir);
}
chdir($dir);
}
/**
* @Given I have a file named :arg1
*/
public function iHaveAFileNamed($file)
{
touch($file);
}
/**
* @When I run :arg1
*/
public function iRun($command)
{
exec($command, $output);
$this->output = trim(implode("\n", $output));
}
/**
* @Then I should get:
*/
public function iShouldGet(PyStringNode $string)
{
if ((string) $string !== $this->output) {
throw new Exception(
"Actual output is:\n" . $this->output
);
}
}
}

15
features/ls.feature Normal file
View file

@ -0,0 +1,15 @@
Feature: ls
In order to see the directory structure
As a UNIX user
I need to be able to list the current directory's contents
Scenario: List 2 files in a directory
Given I am in a directory "test"
And I have a file named "foo"
And I have a file named "bar"
When I run "ls"
Then I should get:
"""
bar
foo
"""

View file

@ -1,4 +1,5 @@
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.
{
inputs = {
devshell.url = "github:numtide/devshell";
@ -11,22 +12,13 @@
systems = [ "x86_64-linux" ];
perSystem = {
config,
self',
inputs',
pkgs,
system,
...
}: {
perSystem = { config, self', inputs', pkgs, system, ... }: {
devshells.default = {
packages = with pkgs; [
"php82"
"php82Packages.composer"
"php81"
"php81Packages.composer"
];
};
formatter = pkgs.alejandra;
};
};
}

View file

@ -4,12 +4,12 @@ declare(strict_types=1);
namespace App\DataTransferObject;
readonly final class TemplateFile
final class TemplateFile
{
public function __construct(
public string $data,
public string $name,
public string|null $path = null,
readonly public string $data,
readonly public string $name,
readonly public string|null $path = null,
) {
}
}