Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
benr77 committed Jun 25, 2024
0 parents commit bd288c8
Show file tree
Hide file tree
Showing 14 changed files with 370 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

name: CI Pipeline

on:
push: ~
pull_request: ~

jobs:
build:
runs-on: ${{ matrix.operating-system }}
name: PHP ${{ matrix.php }} and Symfony ${{ matrix.symfony }}
strategy:
matrix:
operating-system: [ 'ubuntu-22.04' ]
php: [ '8.2', '8.3' ]
symfony: ['6.4.*', '7.0.*']

steps:
- uses: actions/checkout@v4

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: flex
coverage: pcov

- name: Download dependencies
env:
SYMFONY_REQUIRE: ${{ matrix.symfony }}
uses: ramsey/composer-install@v3

- name: Run test suite on PHP ${{ matrix.php }} and Symfony ${{ matrix.symfony }}
run: ./vendor/bin/phpunit --coverage-clover clover.xml

- name: Make code coverage badge
uses: timkrase/[email protected]
with:
coverage_badge_path: output/coverage.svg
push_badge: false

- name: Git push to image-data branch
uses: peaceiris/actions-gh-pages@v4
with:
publish_dir: ./output
publish_branch: image-data
github_token: ${{ secrets.GITHUB_TOKEN }}
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'

ecs:
name: Easy Coding Standard
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: ramsey/composer-install@v3
- run: vendor/bin/ecs

phpstan:
name: PHPStan
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: ramsey/composer-install@v3
- run: vendor/bin/phpstan
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
composer.lock
var/
vendor/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright 2024 Headstrong Internet Services Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.PHONY: help
.DEFAULT_GOAL := help

PHP = php
PHPUNIT = ${PHP} vendor/bin/phpunit

cs: ## Run ECS Coding Standards analysis
@${PHP} vendor/bin/ecs check

cs-fix: ## Fix ECS Coding Standards
@${PHP} vendor/bin/ecs check --fix

static: ## Run PHPStan static analysis
@${PHP} vendor/bin/phpstan analyse

test: ## Run PHPUnit tests
@${PHPUNIT}

test-coverage: ## Run PHPUnit tests with code coverage
@${PHPUNIT} --coverage-html=var/coverage

########################################################################################################################
# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
@echo "\nMakefile is used to run various utilities related to this project\n"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
########################################################################################################################
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Acme Tools for Symfony
====

![Build Status](https://github.com/headsnet/acme-tools-bundle/actions/workflows/ci.yml/badge.svg)
![Coverage](https://raw.githubusercontent.com/headsnet/acme-tools-bundle/image-data/coverage.svg)
[![Latest Stable Version](https://poser.pugx.org/headsnet/acme-tools-bundle/v)](//packagist.org/packages/headsnet/acme-tools-bundle)
[![Total Downloads](https://poser.pugx.org/headsnet/acme-tools-bundle/downloads)](//packagist.org/packages/headsnet/acme-tools-bundle)
[![License](https://poser.pugx.org/headsnet/acme-tools-bundle/license)](//packagist.org/packages/headsnet/acme-tools-bundle)
[![PHP Version Require](http://poser.pugx.org/headsnet/acme-tools-bundle/require/php)](//packagist.org/packages/headsnet/acme-tools-bundle)

## Installation

```bash
composer require headsnet/acme-tools-bundle
```
If your Symfony installation does not auto-register bundles, add it manually:

```php
// bundles.php
return [
...
Headsnet\AcmeToolsBundle\HeadsnetAcmeToolsBundle::class => ['all' => true],
];
```
## Contributions

Contributions are welcome via Pull Requests. Please include a single change in each PR.

## License

Released under the [MIT License](LICENSE).
41 changes: 41 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "headsnet/acme-tools-bundle",
"type": "library",
"description": "Tools and helpers for functionality needed in larger Symfony projects",
"keywords": ["symfony", "php"],
"homepage": "https://github.com/headsnet/acme-tools-bundle",
"license": "MIT",
"support": {
"issues": "https://github.com/headsnet/acme-tools-bundle/issues"
},
"require": {
"php": ">=8.2",
"symfony/config": "^6.0 || ^7.0",
"symfony/dependency-injection": "^6.0 || ^7.0",
"symfony/http-kernel": "^6.0 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^10.0",
"nyholm/symfony-bundle-test": "^3.0",
"phpstan/phpstan": "^1.11",
"symplify/easy-coding-standard": "^12.2"
},
"suggest": {

},
"autoload": {
"psr-4": {
"Headsnet\\AcmeToolsBundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Headsnet\\AcmeToolsBundle\\Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
}
}
}
15 changes: 15 additions & 0 deletions config/services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return function (ContainerConfigurator $configurator): void
{
$services = $configurator->services()
->defaults()
->autowire()
->autoconfigure()
;

$services->load('Headsnet\\AcmeToolsBundle\\', '../src/*');
};
35 changes: 35 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);

use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
use PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer;
use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

$ecsConfig->skip([
BlankLineAfterOpeningTagFixer::class,
NotOperatorWithSuccessorSpaceFixer::class,
MethodChainingIndentationFixer::class
]);

$ecsConfig->rules([
NoUnusedImportsFixer::class,
]);

$ecsConfig->sets([
SetList::SPACES,
SetList::ARRAY,
SetList::DOCBLOCK,
SetList::NAMESPACES,
SetList::COMMENTS,
SetList::PSR_12,
]);
};
10 changes: 10 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
parameters:

level: 9

paths:
- src/
- tests/

ignoreErrors:
- '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::children\(\).#'
23 changes: 23 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="tests/bootstrap.php"
cacheDirectory="var/cache/.phpunit.cache"
executionOrder="depends,defects"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="false"
beStrictAboutOutputDuringTests="true"
displayDetailsOnTestsThatTriggerWarnings="true"
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<source restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
38 changes: 38 additions & 0 deletions src/HeadsnetAcmeToolsBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Headsnet\AcmeToolsBundle;

use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;

class HeadsnetAcmeToolsBundle extends AbstractBundle
{
public function configure(DefinitionConfigurator $definition): void
{
$definition->rootNode()
->children()
->scalarNode('root_namespace')->cannotBeEmpty()->end()
;
}

/**
* @param array{
* root_namespace: string,
* } $config
*/
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
{
$container->import('../config/services.php');

$container->parameters()
->set('headsnet_acme_tools.root_namespace', $config['root_namespace'])
;
}

public function build(ContainerBuilder $container): void
{
parent::build($container);
}
}
3 changes: 3 additions & 0 deletions tests/Fixtures/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
headsnet_acme_tools:
root_namespace: App

45 changes: 45 additions & 0 deletions tests/HeadsnetAcmeToolsBundleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);

namespace Headsnet\AcmeToolsBundle\Tests;

use Headsnet\AcmeToolsBundle\HeadsnetAcmeToolsBundle;
use Nyholm\BundleTest\TestKernel;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpKernel\KernelInterface;

#[CoversClass(HeadsnetAcmeToolsBundle::class)]
class HeadsnetAcmeToolsBundleTest extends KernelTestCase
{
protected static function getKernelClass(): string
{
return TestKernel::class;
}

/**
* @param array{debug?: bool, environment?: string} $options
*/
protected static function createKernel(array $options = []): KernelInterface
{
/** @var TestKernel $kernel $kernel */
$kernel = parent::createKernel($options);
$kernel->addTestBundle(HeadsnetAcmeToolsBundle::class);
$kernel->addTestConfig(__DIR__ . '/Fixtures/config.yaml');
$kernel->handleOptions($options);

return $kernel;
}

#[Test]
public function initialise_bundle(): void
{
$kernel = self::bootKernel();
$container = $kernel->getContainer();

$this->assertTrue(
$container->hasParameter('headsnet_acme_tools.root_namespace')
);
}
}
13 changes: 13 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);

use Symfony\Component\Filesystem\Filesystem;

require dirname(__DIR__) . '/vendor/autoload.php';

$filesystem = new Filesystem();

if ($filesystem->exists(__DIR__ . '/../src/_generated')) {
echo "Removing generated test files...\n";
$filesystem->remove(__DIR__ . '/../src/_generated');
}

0 comments on commit bd288c8

Please sign in to comment.