Skip to content

Instantly share code, notes, and snippets.

View adri's full-sized avatar

Adrian Philipp adri

View GitHub Profile
@adri
adri / FixtureTestCaseUsage.php
Created September 26, 2018 14:36
Example fixture test case that persists objects to the database.
<?php
class ExampleTest extends FixtureTestCase
{
/**
* @test
*/
public function testSomething() : void
{
$payout = $this->fixture()->payout(function (PayoutContext $payout) {
@adri
adri / ExampleUsage.php
Created September 26, 2018 14:34
Example usage of specifying an objects property.
<?php
$payout = Factory::create()->payout(function (PayoutContext $payout) {
$payout->payoutId = PayoutId::fromString('03f74472-0e31-4d5c-8f61-bf34bda2dcb2');
});
@adri
adri / ExampleUsageWith.php
Created September 26, 2018 14:32
Example usage of setting dependent objects properties without creating a new object.
<?php
$payout = Factory::create()
->withPayment(function (PaymentContext $payment) {
$payment->amount = new Money(1337, new Currency('USD'));
})
->payout(function (PayoutContext $payout) {
$payout->payoutId = PayoutId::fromString('03f74472-0e31-4d5c-8f61-bf34bda2dcb2');
});
@adri
adri / PaymentContext.php
Created September 26, 2018 14:28
Example PaymentContext for creating a payment object.
<?php
class PaymentContext
{
/**
* @var PaymentId
*/
public $paymentId;
/**
@adri
adri / PayoutContext.php
Last active September 26, 2018 14:26
Example PayoutContext for using a Factory
<?php
class PayoutContext
{
/**
* @var PayoutId
*/
public $payoutId;
/**
@adri
adri / FixtureTestCase.php
Last active November 8, 2018 14:36
Symfony TestCase using fixtures and database transactions
<?php
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\DBAL\Connection;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class FixtureTestCase extends KernelTestCase
{
/**
@adri
adri / Factory.php
Created September 26, 2018 13:40
Factory that resolves dependent objects using contexts.
<?php
class Factory
{
/**
* @var array
*/
private $contexts = [];
/**
@adri
adri / graphql.php
Created February 8, 2018 07:50
Concurrent GraphQL resolvers in PHP POC
<?php
// Test this using following command
// php reactphp.php
// curl http://localhost:8080 -d '{"query": "query { echo(message: \"Hello World\") }" }'
// curl http://localhost:8080 -d '{"query": "mutation { sum(x: 2, y: 2) }" }'
require_once __DIR__ . '/../vendor/autoload.php';
use GraphQL\Executor\Promise\Adapter\ReactPromiseAdapter;
use GraphQL\GraphQL;
use GraphQL\Type\Definition\ObjectType;
@adri
adri / config.yml
Last active February 15, 2017 14:32
Cache Doctrine metadata via opcache using DoctrineCacheBridge
framework:
cache:
pools:
app.cache.doctrine_metadata:
adapter: cache.adapter.php_files
doctrine:
orm:
entity_managers:
default:
require("babel/register");
const dependencies = require('./src/dependencies');
var WebpackIsomorphicTools = require('webpack-isomorphic-tools');
var chokidar = require('chokidar');
var webpack = require('webpack');
var config = require('./config/webpack.config.dev');
var compiler = webpack(config);
var app = dependencies.expressApp;
var Mocha = require('mocha');