Skip to content

Instantly share code, notes, and snippets.

View dantleech's full-sized avatar
💭
Nothing

dantleech dantleech

💭
Nothing
View GitHub Profile
@dantleech
dantleech / 00_Context.php
Last active May 20, 2024 07:13
POC for using a fixture contianer to lazily load "fixtures"
<?php
class OrganisationContext implements Context
{
/**
* Fixture container is similar to a service container, but for class instances.
*/
public function __construct(private FixtureContainer $fixture)
{
}
<?php
namespace App\Command;
use RuntimeException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@dantleech
dantleech / Color.php
Created March 18, 2021 11:07
PHPBench Color/Gradient V/O / Collections
<?php
namespace PhpBench\Expression\ColorMap\Util;
use RuntimeException;
final class Color
{
/**
* @var int
<?php
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\DrupalKernel;
$autoload = require __DIR__ . '/vendor/autoload.php';
$cwd = getcwd();
chdir('docroot');
$drupalKernel = DrupalKernel::createFromRequest(
@dantleech
dantleech / project-checklist.md
Last active May 28, 2018 07:07
Project checklist

Testing

  • Facility to write and execute E2E tests,
  • Facility to write and execute Integration (e.g. repository) tests.
  • Facility to control DB state effectively (e.g. fixtures for dev setup + tests)
  • Ability to test emails
  • Test reports (e.g. monitor test results over time)
  • Performance / load tests (e.g. Jmeter, Gatling, PHPBench)
  • Smoke tests (e.g. CMS pages) on local / int / live
@dantleech
dantleech / README.md
Last active October 21, 2021 21:22
PHPStan Drupal Integration
$ composer require phpstan/phpstan

Drupal dynamically adds to the class autoloader at runtime, so it is necessary to bootstrap Drupal in order that it is fully populated. Note that this may require that the database be accessible (i.e. may be problematic when working with Docker). This is why we use a custom autoload file below.

$ ./bin/phpstan analyse --level=7 -c phpstan.neon docroot/modules/custom
@dantleech
dantleech / phpactor_autoload.php
Created January 12, 2018 10:22
Drupal 8 autoloader bootstrap for Phpactor
<?php
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Database\Database;
$autoload = require __DIR__ . '/autoload.php';
$kernel = new DrupalKernel('prod', $autoload);
$kernel->setSitePath(__DIR__);
@dantleech
dantleech / bosh
Last active August 10, 2017 08:26
#!/bin/bash
# Run a command in the app container as the www-data user
ARGS="$@"
docker exec --user=www-data --tty=true `docker-compose ps -q app` $ARGS
#!/bin/bash
# locate CharName.pm
egrep -i "^[0-9a-f]{4,} .*$*" /usr/lib/x86_64-linux-gnu/perl5/5.24/Unicode/CharName.pm | while read h d; do /usr/bin/printf "\U$(printf "%08x" 0x$h)\tU+%s\t%s\n" $h "$d"; done
@dantleech
dantleech / sourcebuilderproto.php
Last active July 11, 2017 09:26
API for source code generator / modifier
<?php
$builder = $sourceBuilder->prototypeBuilder();
$builder->namespace('Animals');
$builder->use('Measurements\\Height');
$builder->class('Rabbits')
->properties()
->property('television')
->visiblity('private')
->end()