Skip to content

Instantly share code, notes, and snippets.

View adri's full-sized avatar

Adrian Philipp adri

View GitHub Profile
@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 / Factory.php
Created September 26, 2018 13:40
Factory that resolves dependent objects using contexts.
<?php
class Factory
{
/**
* @var array
*/
private $contexts = [];
/**
@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 / PayoutContext.php
Last active September 26, 2018 14:26
Example PayoutContext for using a Factory
<?php
class PayoutContext
{
/**
* @var PayoutId
*/
public $payoutId;
/**
@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 / 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 / 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 / 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) {